-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ex16_22_textquery.h
49 lines (38 loc) · 1019 Bytes
/
ex16_22_textquery.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
#ifndef CP5_EX16_22_TEXTQUERY_H_
#define CP5_EX16_22_TEXTQUERY_H_
#include <string>
using std::string;
#include <vector>
using std::vector;
#include <memory>
using std::shared_ptr;
#include <fstream>
#include <iostream>
#include <map>
#include <set>
class QueryResult;
class TextQuery {
public:
using LineNo = vector<string>::size_type;
TextQuery(std::ifstream&);
QueryResult query(const string&) const;
private:
shared_ptr<vector<string>> input;
std::map<string, shared_ptr<std::set<LineNo>>> result;
};
class QueryResult {
public:
friend std::ostream& print(std::ostream&, const QueryResult&);
public:
QueryResult(const string& s, shared_ptr<std::set<TextQuery::LineNo>> set,
shared_ptr<vector<string>> v)
: word(s), nos(set), input(v)
{
}
private:
string word;
shared_ptr<std::set<TextQuery::LineNo>> nos;
shared_ptr<vector<string>> input;
};
std::ostream& print(std::ostream&, const QueryResult&);
#endif // CP5_EX16_22_TEXTQUERY_H_