-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuery.h
64 lines (56 loc) · 1.19 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
57
58
59
60
61
62
63
64
#ifndef QUERY_H
#define QUERY_H
#include "TextQuery.h"
#include "QueryResult.h"
#include <string>
#include <memory>
#include <iostream>
#include "Query_base.h"
#include "WordQuery.h"
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 &s) : q(new WordQuery(s)) {}
std::string rep() const {
return q->rep();
}
QueryResult eval(const TextQuery &t) const {
return q->eval(t);
}
// Copy constructor
Query(const Query &query) : q(query.clone()) {}
// Move constructor
Query(Query &&query) : q(query.q) {
query.q = nullptr;
}
// Copy-assignment operator
Query &operator=(const Query &rhs) {
Query_base *temp = rhs.clone();
delete q;
q = temp;
return *this;
}
// Move-assignment operator
Query &operator=(Query &&rhs) {
if (this != &rhs) {
delete q;
q = rhs.q;
rhs.q = nullptr;
}
return *this;
}
// Destructor
~Query() {
delete q;
}
private:
Query(Query_base *query) : q(query) {}
Query_base *clone() const {
return q->clone();
}
Query_base *q = nullptr;
};
std::ostream &operator<<(std::ostream &, const Query &);
#endif