forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotQuery.h
54 lines (45 loc) · 1.36 KB
/
NotQuery.h
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef NOTQUERY_H
#define NOTQUERY_H
class TextQuery;
class QueryResult;
class Query; // Add
#if DEBUG_LEVEL >= 1
#include <iostream>
#endif
#include <string>
#include <memory>
//#include "Query.h"
#include "Query_base.h"
class NotQuery : public Query_base {
friend Query operator~(const Query &);
// NotQuery(const Query &query) : q(query) {
//#if DEBUG_LEVEL >= 1
// std::cout << "NotQuery::NotQuery(const Query &)" << std::endl;
//#endif
// }
NotQuery(std::shared_ptr<Query_base> query) : pq(query) {
#if DEBUG_LEVEL >= 1
std::cout << "NotQuery::NotQuery(std::shared_ptr<Query_base>)" << std::endl;
#endif
}
QueryResult eval(const TextQuery &) const override;
std::string rep() const override {
#if DEBUG_LEVEL >= 1
std::cout << "NotQuery::rep" << std::endl;
#endif
//return "~(" + q.rep() + ")";
return "~(" + pq->rep() + ")";
}
//Query q;
std::shared_ptr<Query_base> pq;
};
// NOTE The `operator~` should not be `inline` here and should be put into
// seperate implementation file. Otherwise, we must include this header in all
// files where we want to use this operator. And since this header is not part
// of the interface, its a bad idea to have the user include this header in
// user code.
//inline Query operator~(const Query &q) {
// return std::shared_ptr<Query_base>(new NotQuery(q));
//}
Query operator~(const Query &);
#endif