forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.h
39 lines (29 loc) · 808 Bytes
/
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
#ifndef _QUERY_H
#define _QUERY_H
#include <ostream>
using std::ostream;
#include <memory>
using std::shared_ptr;
#include <string>
using std::string;
#include "query_base.h"
#include "queryresult.h"
#include "wordquery.h"
class TextQuery;
class Query
{
friend Query operator~(const Query&);
friend Query operator|(const Query&, const Query&);
friend Query operator&(const Query&, const Query&);
public:
Query(const string&);
//call QueryResult's default copy constructor.
QueryResult eval(const TextQuery &t) const { return q->eval(t); }
string rep() const { return q->rep(); }
private:
Query(shared_ptr<Query_base> query) :q(query){ }
shared_ptr<Query_base> q;
};
ostream & operator<<(ostream &os, const Query &query);
inline Query::Query(const string &s) :q(new WordQuery(s)){ }
#endif