-
Notifications
You must be signed in to change notification settings - Fork 3k
/
ex12_32.h
44 lines (37 loc) · 977 Bytes
/
ex12_32.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
//
// ex12_32.h
// Exercise 12.32
//
// Created by pezy on 1/1/15.
//
// Rewrite the TextQuery and QueryResult classes to use a StrBlob
// instead of a vector<string> to hold the input file.
#ifndef CP5_ex12_32_h
#define CP5_ex12_32_h
#include "ex12_22.h"
using std::shared_ptr;
#include <iostream>
#include <fstream>
#include <map>
#include <set>
class QueryResult;
class TextQuery {
public:
TextQuery(std::ifstream &);
QueryResult query(const string&) const;
private:
StrBlob file;
std::map<string, shared_ptr<std::set<StrBlob::size_type>>> result;
};
class QueryResult {
public:
friend std::ostream& print(std::ostream &, const QueryResult&);
public:
QueryResult(const string &s, shared_ptr<std::set<StrBlob::size_type>> set, const StrBlob& f) : word(s), nos(set), file(f) { }
private:
string word;
shared_ptr<std::set<StrBlob::size_type>> nos;
StrBlob file;
};
std::ostream& print(std::ostream &, const QueryResult&);
#endif