forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex12_27_30.h
51 lines (42 loc) · 1.15 KB
/
ex12_27_30.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
//
// ex12_27.h
// Exercise 12.27
//
// Created by pezy on 12/31/14.
//
// The TextQuery and QueryResult classes use only capabilities that we have already covered.
// Without looking ahead, write your own versions of these classes.
#ifndef CP5_ex12_27_h
#define CP5_ex12_27_h
#include <string>
using std::string;
#include <vector>
using std::vector;
#include <memory>
using std::shared_ptr;
#include <iostream>
#include <fstream>
#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