Add implementation to cache reader
[dueringa_WikiWalker.git] / src / ArticleCollection.cpp
blob26755e117488af18cdd80a40d811d7b1b86ffbe8
1 //! \file ArticleCollection.cpp
3 #include "ArticleCollection.h"
5 #include "Article.h"
7 ArticleCollection::~ArticleCollection()
9 /* this is still kinda ugly, since other pointers may exist...
10 * also, deleting stack-created articles is going to get ugly
11 * (although you shouldn't have pointers to stack variables
12 * anyway... */
13 for(auto it = articleSet.rbegin(); it != articleSet.rend(); it++) {
14 /* reverse iteration, forward one could cause us trouble if we
15 * delete and erase */
16 delete it->second;
18 articleSet.clear();
21 Article* ArticleCollection::get(std::string title)
23 auto it = articleSet.find(title);
25 if(articleSet.end() == it) {
26 return nullptr;
29 return it->second;
31 bool ArticleCollection::add(Article* article)
33 auto ret = articleSet.insert(std::make_pair(article->getTitle(), article));
34 return ret.second;
37 ArticleCollection::iterator ArticleCollection::begin()
39 return articleSet.begin();
42 ArticleCollection::iterator ArticleCollection::end()
44 return articleSet.end();
47 ArticleCollection::const_iterator ArticleCollection::begin() const
49 return articleSet.begin();
52 ArticleCollection::const_iterator ArticleCollection::end() const
54 return articleSet.end();