-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextQuery.h
29 lines (26 loc) · 932 Bytes
/
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
// This file contains code from "C++ Primer, Fifth Edition",
// by Stanley B.Lippman, Josee Lajoie, and Barbara E. Moo
#ifndef TEXTQUERY_H
#define TEXTQUERY_H
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <fstream>
#include "QueryResult.h"
class QueryResult; // declaration needed for return type in the query function
class TextQuery {
public:
using line_no = std::vector<std::string>::size_type;
TextQuery(std::ifstream&);
QueryResult query(const std::string&) const;
void display_map(); // debugging aid
private:
// pointer to a vector of lines of the input file
std::shared_ptr<std::vector<std::string>> file;
// maps each word to a pointer to the set of lines in which that word appears
std::map<std::string, std::shared_ptr<std::set<line_no>>> wm;
};
std::ostream &print(std::ostream &os, const QueryResult &qr);
#endif