1 //! \file ArticleCollection.h
3 #ifndef _ARTICLE_COLLECTION_H
4 #define _ARTICLE_COLLECTION_H
8 // forward-declare, since we only store pointer
11 /*! Collection of available articles.
12 * This should be used as "cache".
14 class ArticleCollection
17 //! The way that articles are stored inside
18 typedef std::map
<std::string
, Article
*> storage_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
52 /*! Returns an iterator to the article following the last article in the collection
53 * \returns iterator to element after last article
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;
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;
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