TupleList SimpleQueryLinker::make_tuples( const std::vector<std::string>& variables) { TupleList result; std::string first_qvar = *variables.begin(); if(!is_initialized(first_qvar)) { throw QueryLinkerError(); } for(ConditionSet::iterator cit = _qvar_table[first_qvar].begin(); cit != _qvar_table[first_qvar].end(); ++cit) { TupleList tuples = make_tuples(first_qvar, *cit, ++variables.begin(), variables.end()); for(TupleList::iterator tit = tuples.begin(); tit != tuples.end(); ++tit) { result.insert(*tit); } } return result; }
void SimpleQueryLinker::merge_tuples(const ConditionPtr& target_condition, const TupleList& tuples, TupleList& result) { for(TupleList::const_iterator tit = tuples.begin(); tit != tuples.end(); ++tit) { result.insert(ConditionTuplePtr( new SimpleConditionTuple(target_condition, *tit))); } }
TupleList SimpleQueryLinker::make_tuples( const std::string& current_qvar, const ConditionPtr& current_condition, std::vector<std::string>::const_iterator next_qit, std::vector<std::string>::const_iterator end) { if(!is_initialized(current_qvar)) { throw QueryLinkerError(); } TupleList result; if(next_qit == end) { result.insert(ConditionTuplePtr( new SimpleConditionTuple(current_condition))); } else { std::string next_qvar = *next_qit++; if(has_link(current_qvar, next_qvar)) { ConditionSet linked_conditions = get_linked_conditions( current_qvar, next_qvar, current_condition); for(ConditionSet::iterator cit = linked_conditions.begin(); cit != linked_conditions.end(); ++cit) { merge_tuples(current_condition, make_tuples(next_qvar, *cit, next_qit, end), result); } } else if(has_indirect_links(current_qvar, next_qvar)) { ConditionSet linked_conditions = get_indirect_links( current_qvar, next_qvar, current_condition); for(ConditionSet::iterator cit = linked_conditions.begin(); cit != linked_conditions.end(); ++cit) { merge_tuples(current_condition, make_tuples(next_qvar, *cit, next_qit, end), result); } } else { for(ConditionSet::iterator cit = _qvar_table[next_qvar].begin(); cit != _qvar_table[next_qvar].end(); ++cit) { merge_tuples(current_condition, make_tuples(next_qvar, *cit, next_qit, end), result); } } } return result; }