本文整理汇总了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;
}