-
Notifications
You must be signed in to change notification settings - Fork 796
/
query.h
57 lines (49 loc) · 1.18 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
#ifndef QUERY_H
#define QUERY_H
#include <iostream>
#include <string>
#include <memory>
#include "query_base.h"
#include "queryresult.h"
#include "textquery.h"
#include "wordquery.h"
/**
* @brief interface class to manage the Query_base inheritance hierachy
*/
class Query
{
friend Query operator~(const Query&);
friend Query operator|(const Query&, const Query&);
friend Query operator&(const Query&, const Query&);
public:
// build a new WordQuery
Query(const std::string& s) : q(new WordQuery(s))
{
std::cout << "Query::Query(const std::string& s) where s=" + s + "\n";
}
// interface functions: call the corresponding Query_base operatopns
QueryResult eval(const TextQuery& t) const
{
return q->eval(t);
}
std::string rep() const
{
std::cout << "Query::rep() \n";
return q->rep();
}
private:
// constructor only for friends
Query(std::shared_ptr<Query_base> query) :
q(query)
{
std::cout << "Query::Query(std::shared_ptr<Query_base> query)\n";
}
std::shared_ptr<Query_base> q;
};
inline std::ostream&
operator << (std::ostream& os, const Query& query)
{
// make a virtual call through its Query_base pointer to rep();
return os << query.rep();
}
#endif // QUERY_H