forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex17_03_text_query.h
39 lines (33 loc) · 884 Bytes
/
ex17_03_text_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
#pragma once
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using std::string;
using std::vector;
using std::tuple;
using std::shared_ptr;
using std::set;
using std::map;
using std::ifstream;
using std::ostream;
namespace EX03 {
using line_no = vector<string>::size_type;
using query_result =
tuple<string, shared_ptr<set<line_no>>, shared_ptr<vector<string>>>;
class TextQuery {
public:
// read the input file and build the map of lines to line numbers.
TextQuery(ifstream&);
query_result query(const string&) const;
private:
shared_ptr<vector<string>> file; // input file
// map of each word to the set of the lines in which that word appears.
map<string, shared_ptr<set<line_no>>> wm;
};
ostream& print(ostream&, const query_result&);
} // namespace EX03