Add iterator to ArticleCollection
[dueringa_WikiWalker.git] / src / ArticleCollection.cpp
bloba14e4028053775482ef6276db28f243c01865942
1 #include "ArticleCollection.h"
3 ArticleCollection::~ArticleCollection()
5 /* this is still kinda ugly, since other pointers may exist...
6 * also, deleting stack-created articles is going to get ugly
7 * (although you shouldn't have pointers to stack variables
8 * anyway... */
9 for(auto it = articleSet.rbegin(); it != articleSet.rend(); it++) {
10 /* reverse iteration, forward one could cause us trouble if we
11 * delete and erase */
12 delete it->second;
14 articleSet.clear();
17 Article* ArticleCollection::get(std::string title)
19 auto it = articleSet.find(title);
21 if(articleSet.end() == it) {
22 return nullptr;
25 return it->second;
27 bool ArticleCollection::add(Article* article)
29 auto ret = articleSet.insert(std::make_pair(article->getTitle(), article));
30 return ret.second;
33 ArticleCollection::iterator ArticleCollection::begin()
35 return articleSet.begin();
38 ArticleCollection::iterator ArticleCollection::end()
40 return articleSet.end();
43 ArticleCollection::const_iterator ArticleCollection::begin() const
45 return articleSet.begin();
48 ArticleCollection::const_iterator ArticleCollection::end() const
50 return articleSet.end();