Update TODO
[dueringa_WikiWalker.git] / src / ToGraphvizWriter.cpp
blob2fd3131648a667c3ee868c83a905916658786556
1 //! \file ToGraphvizWriter.cpp
3 #include "ToGraphvizWriter.h"
5 #include <string>
6 // uh-oh...
7 #include <regex>
9 #include "Article.h"
11 namespace WikiWalker
13 static void writeHeader(std::ostream& os)
15 os << "digraph G {";
16 os << std::endl;
19 static void writeFooter(std::ostream& os)
21 os << "}";
22 os << std::endl;
25 /*! \bug When writing an #Article only, attributes are only set on the article
26 * itself. Attributes won't be written on linked articles.
27 * However, when writing an #ArticleCollection, all articles are included, so
28 * all attibutes will be written.
30 static void writeArticle(const Article* a, std::ostream& os)
32 std::string atitle = a->title();
34 // search for quotes
35 std::regex re(R"(")");
36 // replace by escaped quote
37 atitle = std::regex_replace(atitle, re, R"(\")");
39 // marked articles are printed as box
40 if(a->marked()) {
41 os << R"(")" << atitle << R"(" [shape=box];)" << std::endl;
44 if(!a->analyzed()) {
45 os << R"(")" << atitle << R"(" [fillcolor=gray,style=filled];)"
46 << std::endl;
49 // unanalyzed articles are printed greyed out
50 for(auto al = a->linkBegin(); al != a->linkEnd(); al++) {
51 auto lck_article = al->lock();
52 if(lck_article != nullptr) {
53 std::string alinkedtitle = lck_article->title();
54 os << R"(")" << atitle << R"(" -> ")"
55 << std::regex_replace(alinkedtitle, re, R"(\")") << R"(";)"
56 << std::endl;
61 void ToGraphvizWriter::output(const Article* a, std::ostream& os)
63 writeHeader(os);
65 writeArticle(a, os);
67 writeFooter(os);
70 void ToGraphvizWriter::output(const CollectionUtils::ArticleCollection& ac,
71 std::ostream& os)
73 writeHeader(os);
75 for(auto a : ac) {
76 writeArticle(a.second.get(), os);
79 writeFooter(os);
81 } // namespace WikiWalker