forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex13_42_TextQuery.h
43 lines (34 loc) · 881 Bytes
/
ex13_42_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
#ifndef CP5_TEXTQUERY_H_
#define CP5_TEXTQUERY_H_
#include <string>
#include <memory>
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include "ex13_42_StrVec.h"
class QueryResult;
class TextQuery {
public:
TextQuery(std::ifstream&);
QueryResult query(const std::string&) const;
private:
std::shared_ptr<StrVec> input;
std::map<std::string, std::shared_ptr<std::set<size_t>>> result;
};
class QueryResult {
public:
friend std::ostream& print(std::ostream&, const QueryResult&);
public:
QueryResult(const std::string& s, std::shared_ptr<std::set<size_t>> set,
std::shared_ptr<StrVec> v)
: word(s), nos(set), input(v)
{
}
private:
std::string word;
std::shared_ptr<std::set<size_t>> nos;
std::shared_ptr<StrVec> input;
};
std::ostream& print(std::ostream&, const QueryResult&);
#endif