forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotQuery.cpp
33 lines (30 loc) · 902 Bytes
/
NotQuery.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
28
29
30
31
32
33
#include "NotQuery.h"
#include <memory> // make_shared
#include "TextQuery.h"
#include "QueryResult.h"
#if DEBUG_LEVEL >= 1
#include <iostream>
#endif
QueryResult NotQuery::eval(const TextQuery &t) const {
#if DEBUG_LEVEL >= 1
std::cout << "NotQuery::eval" << std::endl;
#endif
auto result = q.eval(t);
auto ret_lines = std::make_shared<std::set<line_no_type>>();
auto bg = result.cbegin(), ed = result.cend();
auto sz = result.get_file()->size();
for (std::size_t n = 0; n != sz; ++n) {
if (bg == ed || *bg != n)
ret_lines->insert(n);
else if (bg != ed)
++bg;
}
return QueryResult(rep(), ret_lines->size(), ret_lines, result.get_file());
}
Query operator~(const Query &query) {
#if DEBUG_LEVEL >= 1
std::cout << "Query operator~(const Query &)" << std::endl;
#endif
//return std::shared_ptr<Query_base>(new NotQuery(query));
return new NotQuery(query);
}