forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OrQuery.cpp
27 lines (24 loc) · 809 Bytes
/
OrQuery.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "OrQuery.h"
#include <memory> // make_shared
#include "TextQuery.h"
#include "QueryResult.h"
#if DEBUG_LEVEL >= 1
#include <iostream>
#endif
QueryResult OrQuery::eval(const TextQuery &t) const {
#if DEBUG_LEVEL >= 1
std::cout << "OrQuery::eval" << std::endl;
#endif
auto left = lhs.eval(t), right = rhs.eval(t);
auto ret_lines =
std::make_shared<std::set<line_no_type>>(left.cbegin(), left.cend());
ret_lines->insert(right.cbegin(), right.cend());
return QueryResult(rep(), ret_lines->size(), ret_lines, left.get_file());
}
Query operator|(const Query &lhs, const Query &rhs) {
#if DEBUG_LEVEL >= 1
std::cout << "Query operator|(const Query &, const Query &)" << std::endl;
#endif
//return std::shared_ptr<Query_base>(new OrQuery(lhs, rhs));
return new OrQuery(lhs, rhs);
}