From 302565043bed0dc68bbe5e86ab94d94b15e43424 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 9 Jan 2015 15:25:13 +0100 Subject: Added RTTI information for XML classes, made children vector of XML elements private and added name printout to Manager debug graphviz function. --- src/core/XML.cpp | 7 +++++++ src/core/XML.hpp | 23 +++++++++++++++++++++-- src/core/managed/Manager.cpp | 8 ++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/XML.cpp b/src/core/XML.cpp index 7f03b35..affa75f 100644 --- a/src/core/XML.cpp +++ b/src/core/XML.cpp @@ -45,4 +45,11 @@ void Text::doSerialize(std::ostream &out, unsigned int tabdepth) out << text << '\n'; } } + +namespace RttiTypes { +const Rtti XMLNode = RttiBuilder("XMLNode"); +const Rtti XMLElement = + RttiBuilder("XMLElement").parent(&XMLNode).composedOf(&XMLNode); +const Rtti XMLText = RttiBuilder("XMLText").parent(&XMLNode); +} } diff --git a/src/core/XML.hpp b/src/core/XML.hpp index b4b803d..25c8dae 100644 --- a/src/core/XML.hpp +++ b/src/core/XML.hpp @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -101,19 +102,22 @@ public: * Additionally it might have other Nodes as children. */ class Element : public Node { +private: + ManagedVector children; + public: const std::string name; std::map attributes; - ManagedVector children; Element(Manager &mgr, Handle parent, std::string name) - : Node(mgr, parent), name(std::move(name)) + : Node(mgr, parent), children(this), name(std::move(name)) { } Element(Manager &mgr, Handle parent, std::string name, std::map attributes) : Node(mgr, parent), + children(this), name(std::move(name)), attributes(std::move(attributes)) { @@ -127,6 +131,15 @@ public: * */ void doSerialize(std::ostream &out, unsigned int tabdepth) override; + + const ManagedVector &getChildren() const { return children; } + + void addChild(Handle child) { children.push_back(child); } + + void addChildren(std::vector> c) + { + children.insert(children.end(), c.begin(), c.end()); + } }; class Text : public Node { @@ -145,5 +158,11 @@ public: void doSerialize(std::ostream &out, unsigned int tabdepth) override; }; } + +namespace RttiTypes { +extern const Rtti XMLNode; +extern const Rtti XMLElement; +extern const Rtti XMLText; +} } #endif diff --git a/src/core/managed/Manager.cpp b/src/core/managed/Manager.cpp index 5428ea1..3950ce2 100644 --- a/src/core/managed/Manager.cpp +++ b/src/core/managed/Manager.cpp @@ -26,8 +26,9 @@ #if defined(MANAGER_DEBUG_PRINT) || defined(MANAGER_GRAPHVIZ_EXPORT) #include #include -#include "core/common/Rtti.hpp" -#include "core/model/Node.hpp" +#include +#include +#include #endif namespace ousia { @@ -598,6 +599,9 @@ void Manager::exportGraphviz(const char *filename) if (type.isa(RttiTypes::Node)) { name = dynamic_cast(objectPtr)->getName(); } + if (type.isa(RttiTypes::XMLElement)) { + name = dynamic_cast(objectPtr)->name; + } // Print the node uintptr_t p = reinterpret_cast(objectPtr); -- cgit v1.2.3