-
Notifications
You must be signed in to change notification settings - Fork 0
/
news-aggregator.h
64 lines (52 loc) · 1.88 KB
/
news-aggregator.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
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* File: news-aggregator.h
* -----------------------
* Defines the NewsAggregator class, which understands how to
* build an index of all HTML articles reachable from a
* command-line-provided RSS feed list URI and interact
* with a user interested in searching that index.
*
* Note that NewsAggregator is an abstract base class, and it
* exists to be subclassed and unify state and logic common to
* all subclasses into one location.
*/
#pragma once
#include <string>
#include <algorithm>
#include <cassert>
#include <thread>
#include <mutex>
#include <set>
#include "log.h"
#include "rss-index.h"
#include "html-document.h"
#include "rss-feed.h"
#include "rss-feed-list.h"
#include "utils.h"
class NewsAggregator {
public: // define those entries that everyone can see and touch
static NewsAggregator *createNewsAggregator(int argc, char *argv[]);
virtual ~NewsAggregator() {}
void buildIndex();
void queryIndex() const;
protected: // defines those entries that only subclasses can see and touch
std::string rssFeedListURI;
NewsAggregatorLog log;
RSSIndex index;
bool built;
void updateIndex(Article article, std::vector<std::string> tokens);
bool containsUrl(const std::string& Url);
std::map<std::string, std::string> getFeedMap();
std::vector<std::string> getTokenVector(const std::string& Url);
bool processFeed(RSSFeed* feed);
std::map<std::string, std::pair<Article, std::vector<std::string> > > titleMap;
std::set<std::string> articleUrls;
std::mutex urls;
std::mutex titleMapLock;
std::mutex indexLock;
NewsAggregator(const std::string& rssFeedListURI, bool verbose);
virtual void processAllFeeds() = 0;
private: // defines those entries that only NewsAggregator methods (not even subclasses) can see and touch
NewsAggregator(const NewsAggregator& original) = delete;
NewsAggregator& operator=(const NewsAggregator& rhs) = delete;
};