forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Query.h
56 lines (45 loc) · 1.33 KB
/
Query.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
55
56
#ifndef QUERY_H
#define QUERY_H
class TextQuery;
class QueryResult;
class Query_base;
#include <memory>
#include <string>
#include <iostream>
class Query {
friend Query operator~(const Query &);
friend Query operator&(const Query &, const Query &);
friend Query operator|(const Query &, const Query &);
public:
Query(const std::string &);
~Query();
Query(const Query &);
Query &operator=(const Query &);
//Query(Query &&);
//Query &operator=(Query &&);
QueryResult eval(const TextQuery &t) const;
std::string rep() const;
private:
// Query(std::shared_ptr<Query_base> query) : pq(query) {
//#if DEBUG_LEVEL >= 1
// std::cout << "Query::Query(std::shared_ptr<Query_base>)" << std::endl;
//#endif
// }
// NOTE the pointer used in the following constructor must transfer the
// ownership of the underlying object to this newly constructed object. Thus
// an rvalue reference is used. Otherwise, that pointer (argument) may
// become dangling pointer.
Query(Query_base *&&query) : pq(query), ref_count(new std::size_t(1)) {
#if DEBUG_LEVEL >= 1
std::cout << "Query::Query(Query_base *&&)" << std::endl;
#endif
query = nullptr;
}
//std::shared_ptr<Query_base> pq;
Query_base *pq;
std::size_t *ref_count;
};
inline std::ostream &operator<<(std::ostream &os, const Query &q) {
return os << q.rep();
}
#endif