C++ - 多层继承(inheritance) 的 使用 及 示例(三)
), right.begin(), right.end(),
std::inserter(*ret_lines, ret_lines->begin()));
return QueryResult(rep(), ret_lines, left.get_file());
}
QueryResult NotQuery::eva l(const TextQuery& text) const
{
auto result = query.eva l(text); //调用WordQuery.eva l;
auto ret_lines = std::make_shared>();
auto beg = result.begin(), end = result.end();
auto sz = result.get_file()->size();
for (size_t n=0; n!=sz; ++n) {
if (beg==end || *beg != n )
ret_lines->insert(n);
else if (beg!=end)
++beg;
}
return QueryResult(rep(), ret_lines, result.get_file());
}
bool get_word(std::string& str) {
std::cout << "enter word to look for, or q to quit: " << std::endl;
if ( !(std::cin >> str) || str == "q" ){
std::cout << str;
return false;
}
else{
std::cout << str;
return true;
}
}
int main (void) {
std::ifstream infile;
infile.open("storyDataFile.txt");
TextQuery file = infile;
//Query q = ~Query("Alice");
//Query q = Query("hair") | Query("Alice");
//Query q = Query("hair") & Query("Alice");
Query q = Query("fiery") & Query("bird") | Query("wind");
const auto results = q.eva l(file);
cout << "\nExecuting Query for: " << q << endl;
print(cout, results) << endl;
infile.close();
return 0;
}
输出:
[plain]
Executing Query for: ((fiery & bird) | wind)
((fiery & bird) | wind) occurs 3 times
(line 2) Her Daddy says when the wind blows
(line 4) like a fiery bird in flight
(line 5) A beautiful fiery bird he tells her