forked from chihyang/CPP_Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExer19_06_07_08_TextQuery.h
More file actions
39 lines (39 loc) · 1.36 KB
/
Copy pathExer19_06_07_08_TextQuery.h
File metadata and controls
39 lines (39 loc) · 1.36 KB
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
// TextQuery class from exercise 15.41 and 15.42.
#ifndef TEXT_QUERY_H
#define TEXT_QUERY_H
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <memory>
std::string make_plural(size_t, const std::string&, const std::string&);
class QueryResult;
class TextQuery{
public:
using line_no = std::vector<std::string>::size_type;
TextQuery(std::ifstream&);
QueryResult query(const std::string&) const;
private:
std::shared_ptr<std::vector<std::string>> file;
std::map<std::string, std::shared_ptr<std::set<line_no>>> wm;
};
class QueryResult{
friend std::ostream& print(std::ostream&, const QueryResult&, TextQuery::line_no, TextQuery::line_no);
public:
QueryResult(std::string s,
std::shared_ptr<std::set<TextQuery::line_no>> p,
std::shared_ptr<std::vector<std::string>> f) :
sought(s), lines(p), file(f) { }
// members required by exercise 12.33
std::set<TextQuery::line_no>::iterator begin() const { return lines->begin();}
std::set<TextQuery::line_no>::iterator end() const { return lines->end();}
std::shared_ptr<std::vector<std::string>> get_file() const { return file; }
private:
std::string sought;
std::shared_ptr<std::set<TextQuery::line_no>> lines;
std::shared_ptr<std::vector<std::string>> file;
};
#endif