3 #ifndef WIKIWALKER_ARTICLE_H
4 #define WIKIWALKER_ARTICLE_H
14 * represents a Wikipedia (Mediawiki) article and its links
19 //! representation of single link to other articles
20 using link
= std::weak_ptr
<const Article
>;
21 //! representation of collection of links to other articles
22 using link_collection
= std::vector
<link
>;
23 //! representation of iterator over links
24 using ArticleLinkIterator
= link_collection::iterator
;
25 //! representation of const iterator over links
26 using ArticleLinkConstIterator
= link_collection::const_iterator
;
28 /*! Create a new article from a title
29 * \param articleTitle The title of the article
31 explicit Article(std::string articleTitle
)
32 : title_(std::move(articleTitle
)), analyzed_(false), marked_(false)
36 /*! Get the title of the article
37 * \return title of the article
39 std::string
title() const
44 /*! get the number of links the article has.
45 * This throws an exception if state has not been set to anaylzed.
46 * \return number of links the article has.
47 * This also includes links to articles that are nullptr / already deleted
48 * by the smart pointers.
53 size_t countLinks() const;
55 /*! Add a link to another article.
56 * \param[in] article Pointer to the article this article links
58 * \returns Whether adding woth successful. Returns false if
59 * instance / pointer is already included.
61 * Automatically sets state to analyzed
62 * \see analyzed() const
65 bool addLink(link article
);
67 /*! Set article to be analyzed.
68 * State is automatically set by #addLink, but if
69 * article has no outgoing links, this must be called,
70 * otherwise #numLinks will throw an exception
71 * \param analyzed whether article has been analyzed
74 void analyzed(bool analyzed
);
76 /*! Get state if article was analyzed (for out links).
77 * \returns whether article was analyzed for outgoing links
79 bool analyzed() const;
81 /*! Set article to be marked.
82 * Some kind of "marking" for output usage. May be start point,
83 * may be end point, may be point of special interest.
84 * \param marked whether article is marked
86 void marked(bool marked
);
88 /*! Get state whether article was marked.
89 * \returns Whether article is marked.
93 /*! Get const_iterator to first linked article
94 * \returns const iterator to beginning of linked articles
96 ArticleLinkConstIterator
linkBegin() const;
98 /*! Get const_iterator to last linked article
99 * \returns const iterator to end of linked articles (behind last one)
101 ArticleLinkConstIterator
linkEnd() const;
105 link_collection links_
;
109 } // namespace WikiWalker
110 #endif // WIKIWALKER_ARTICLE_H