1 //! \file ArticleCollection.h
3 #ifndef WIKIWALKER_ARTICLE_COLLECTION_H
4 #define WIKIWALKER_ARTICLE_COLLECTION_H
10 // forward-declare, since we only store pointer
14 } // namespace WikiWalker
18 namespace CollectionUtils
20 /*! Collection of available articles.
21 * This should be used as "cache".
23 using ArticleCollection
= std::map
<std::string
, std::shared_ptr
<Article
>>;
25 //! strategy for merging ArticleCollections
26 enum class MergeStrategy
{
27 //! ignore duplicates, always keep current entry
29 //! always overwrite with articles from other collection
31 //! use the article with more links
32 UseArticleWithMoreLinks
35 /*! get number of anlyzed articles in collection
36 * \returns number of analyzed articles in collection
38 size_t countAnalyzedArticles(const ArticleCollection
& collection
);
40 /*! add article to collection.
41 * \param collection collection to add to
42 * \param article article to add
43 * \return true if insertion took place
44 * false if it failed (e.g. another article with the same title
47 bool add(ArticleCollection
& collection
, std::shared_ptr
<Article
> article
);
49 /*! merge another ArticleCollection into the first one
50 * \param[in] collection collection to merge into
51 * \param[in] other collection to merge
52 * \param[in] strategy merge stratgy to use
53 * \details other collection is left unmodified.
55 void merge(ArticleCollection
& collection
,
56 const ArticleCollection
& other
,
57 MergeStrategy strategy
);
59 /*! get pointer to article.
60 * \param collection collection to search
61 * \param title title of the article to request
62 * \return pointer to article, or nullptr, if not found
64 std::shared_ptr
<Article
> get(const ArticleCollection
& collection
,
65 const std::string
& title
);
66 } // namespace CollectionUtils
67 } // namespace WikiWalker
68 #endif // WIKIWALKER_ARTICLE_COLLECTION_H