当前位置: 首页>>代码示例>>C++>>正文


C++ Query::get_expr方法代码示例

本文整理汇总了C++中Query::get_expr方法的典型用法代码示例。如果您正苦于以下问题:C++ Query::get_expr方法的具体用法?C++ Query::get_expr怎么用?C++ Query::get_expr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Query的用法示例。


在下文中一共展示了Query::get_expr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: compile

  std::string QueryCompiler::compile(Query& query_to_compile, std::string result_var_name)
  {
    ConnectiveExpr* expression_to_compile = query_to_compile.get_expr();

    // The final script.
    std::string script;

    // Keeps first lines of the function (mainly, result variables initialization).
    std::ostringstream function_header_stream;

    // Keeps condition of tags.
    std::ostringstream tags_stream;

    // Keeps condition of other fields.
    std::ostringstream fields_stream;

    // Keeps sequence of `$r'.
    std::ostringstream result;

    compile_states::States current_state = compile_states::GROUP_AFTER_GROUP;

    // Compiling expressions to CompiledExprs.
    std::list<CompiledExpr> compiled_list = expression_to_compile->compile();

    // Iterating over CompiledExprs to create a Jx9 script.
    std::list<CompiledExpr>::iterator iterator = compiled_list.begin();
    CompiledExpr* first_element = &*iterator;
    ++iterator;
    CompiledExpr* second_element = &*iterator;
    // Initializing data.
    CompileStateData data(first_element, second_element,
                          &function_header_stream,
                          &tags_stream, &fields_stream, &result);
    ++iterator;

    for (;iterator != compiled_list.end(); ++iterator)
    {
      current_state = state_table[current_state](data);

      data.current_expr = &*data.next_expr;
      data.next_expr = &*iterator;
    }

    // Last two elements in the list.
    current_state = state_table[current_state](data);
    // The last element.
    data.current_expr = &*data.next_expr;
    CompiledExpr nope_element = CompiledExpr(compiled_expr::NOPE, "");
    data.next_expr = &nope_element;
    current_state = state_table[current_state](data);

    // Creating filter function.
    script += "$filter_func = function($record) { ";

    // Header of the function.
    if (function_header_stream.tellp() != 0)
    {
      script += function_header_stream.str();
    }

    // Appending tags conditions, if there's any.
    if (tags_stream.tellp() != 0)
    {
      script += " " + tags_stream.str() +" }";
    }

    script += " " + fields_stream.str();
    script += " return " + result.str() + ";";
    script += " }; ";

    // Applying filter on database's records, and putting the result in the
    // result variable.
    script += "$" + result_var_name + " = db_fetch_all('files', $filter_func);";

    return script;
  }
开发者ID:PandaOmnomnom,项目名称:tocc,代码行数:76,代码来源:compiler.cpp


注:本文中的Query::get_expr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。