Introduce version 0.1
[dueringa_WikiWalker.git] / src / ArticleCollection.h
blob49f1388bb66b480a12564f73e9e05088965186c5
1 //! \file ArticleCollection.h
3 #ifndef _ARTICLE_COLLECTION_H
4 #define _ARTICLE_COLLECTION_H
6 #include <map>
8 // forward-declare, since we only store pointer
9 class Article;
11 /*! Collection of available articles.
12 * This should be used as "cache".
14 class ArticleCollection
16 public:
17 //! The way that articles are stored inside
18 typedef std::map<std::string, Article*> storage_type;
20 //! iterator type
21 typedef storage_type::iterator iterator;
23 //! constant iterator type
24 typedef storage_type::const_iterator const_iterator;
26 /*! add article to collection.
27 * \param article article to add
28 * \return true if insertion took place
29 * false if it failed (e.g. another article with the same title already exists
31 bool add(Article* article);
33 //! get number of articles in collection
34 size_t getNumArticles() const
36 return articleSet.size();
39 /*! get pointer to article.
40 * \param title title of the article to request
41 * \return pointer to article, or nullptr, if not found
43 Article* get(std::string title);
45 ArticleCollection() {}
47 /*! Returns an iterator to the first article in the collection.
48 * \returns iterator to the first article
50 iterator begin();
52 /*! Returns an iterator to the article following the last article in the collection
53 * \returns iterator to element after last article
55 iterator end();
57 /*! Returns a const_iterator to the first article in the collection
58 * \returns constant iterator to the first article
60 const_iterator begin() const;
62 /*! Returns a const_iterator to the article following the last article in the collection
63 * \returns constant iterator to element after last article
65 const_iterator end() const;
67 ~ArticleCollection();
69 //! deleted copy constructor. Because it stores raw pointers.
70 ArticleCollection(const ArticleCollection&) = delete;
71 //! deleted copy assignment. Because it stores raw pointers.
72 ArticleCollection& operator=(const ArticleCollection&) = delete;
74 private:
75 // we need to avoid duplicate article instances.
76 // we do this by associating an article title with its instance
77 storage_type articleSet;
80 #endif // _ARTICLE_COLLECTION_H