forked from jzplp/Cpp-Primer-Answer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextQuery.h
41 lines (29 loc) · 818 Bytes
/
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
#ifndef TESTQUERY_H
#define TESTQUERY_H
#include<memory>
#include<fstream>
#include<vector>
#include<map>
#include<set>
class QueryResult;
class TextQuery
{
public:
TextQuery(std::ifstream & infile);
QueryResult query(std::string s);
private:
std::shared_ptr<std::vector<std::string>> lines = std::make_shared<std::vector<std::string>>();
std::map<std::string, std::set<size_t>> dict;
};
class QueryResult
{
friend std::ostream & print(std::ostream & os, const QueryResult & q);
public:
QueryResult(std::string s, std::shared_ptr<std::vector<std::string>> l, std::set<size_t> n) : word(s), lines(l), lineNum(n) { }
private:
std::shared_ptr<std::vector<std::string>> lines;
std::string word;
std::set<size_t> lineNum;
};
std::ostream & print(std::ostream & os, const QueryResult & q);
#endif