Introduce version 0.1
[dueringa_WikiWalker.git] / src / ArticleCollection.cpp
blobd0073a694e9c38bf97e885611cdec650c6dc6ae9
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;
19 articleSet.clear();
22 Article* ArticleCollection::get(std::string title)
24 auto it = articleSet.find(title);
26 if(articleSet.end() == it) {
27 return nullptr;
30 return it->second;
32 bool ArticleCollection::add(Article* article)
34 auto ret = articleSet.insert(std::make_pair(article->getTitle(), article));
35 return ret.second;
38 ArticleCollection::iterator ArticleCollection::begin()
40 return articleSet.begin();
43 ArticleCollection::iterator ArticleCollection::end()
45 return articleSet.end();
48 ArticleCollection::const_iterator ArticleCollection::begin() const
50 return articleSet.begin();
53 ArticleCollection::const_iterator ArticleCollection::end() const
55 return articleSet.end();