diff --git a/lib/node.cpp b/lib/node.cpp index d1a373b..72cf242 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -19,3 +19,8 @@ void Node::Inspect(int indent) { child->Inspect(indent + 1); } } + +std::ostream &operator<<(std::ostream &os, Node const &node) { + os << node.ToHtml(); + return os; +} diff --git a/lib/node.h b/lib/node.h index 6009d1c..b50a224 100644 --- a/lib/node.h +++ b/lib/node.h @@ -19,12 +19,23 @@ /// Reference: https://www.youtube.com/watch?v=AmjoK55h68Y&t=166s class Node { + /** + * @brief Override the '<<' operator to write the content of the node + * directly. + * + * This overridden operator will simply write the result of this->ToHtml to + * the stream. + * + * @author Hayden Hargreaves (hhargreaves2006@gmail.com) + */ + friend std::ostream &operator<<(std::ostream &os, Node const &node); + protected: /** * @brief List of children nodes. * - * Most nodes will not have children, but some may, therefore this class must - * have it. + * Most nodes will not have children, but some may, therefore this class + * must have it. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ @@ -58,8 +69,8 @@ public: /** * @brief Return a read-only (const) list of children. * - * Return our list of unique ptrs, they are const and therefore only have read - * access. + * Return our list of unique ptrs, they are const and therefore only have + * read access. * * @author Hayden Hargreaves (hhargreaves2006@gmail.com) */ diff --git a/lib/structureNode.cpp b/lib/structureNode.cpp index 9516c3b..2c5740f 100644 --- a/lib/structureNode.cpp +++ b/lib/structureNode.cpp @@ -15,7 +15,7 @@ string DocumentNode::ToHtml() const { "head>\n\t\n"; for (const auto &child : this->GetChilren()) { - ss << child->ToHtml(); + ss << *child; } ss << "\n\t\n"; @@ -36,7 +36,7 @@ string HeadingNode::ToHtml() const { ss << ""; for (const auto &child : this->GetChilren()) { - ss << child->ToHtml(); + ss << *child; } ss << "\n"; @@ -48,7 +48,7 @@ string ParagraphNode::ToHtml() const { ss << "

"; for (const auto &child : this->GetChilren()) { - ss << child->ToHtml(); + ss << *child; } ss << "

\n"; @@ -61,7 +61,7 @@ string ListNode::ToHtml() const { ss << (this->ordered ? "
    " : "
" : "") << "\n"; @@ -74,7 +74,7 @@ string CodeBlockNode::ToHtml() const { ss << "\n"; for (const auto &child : this->GetChilren()) { - ss << child->ToHtml() << "\n"; + ss << *child << "\n"; } ss << "\n"; diff --git a/src/main.cpp b/src/main.cpp index 514d4e2..5607075 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,7 @@ void test_nodes() { root.AddChild(std::move(para)); root.AddChild(std::move(list)); - std::cout << root.ToHtml() << std::endl; + std::cout << root << std::endl; } /** @@ -86,5 +86,4 @@ void test_document_converter() { dc.ConvertWatcher(); } -int main(int argc, char **argv) { - test_document_converter(); } +int main(int argc, char **argv) { test_document_converter(); }