diff options
-rw-r--r-- | src/core/XML.cpp | 7 | ||||
-rw-r--r-- | src/core/XML.hpp | 23 | ||||
-rw-r--r-- | src/core/managed/Manager.cpp | 8 |
3 files changed, 34 insertions, 4 deletions
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<xml::Node> XMLNode = RttiBuilder("XMLNode"); +const Rtti<xml::Element> XMLElement = + RttiBuilder("XMLElement").parent(&XMLNode).composedOf(&XMLNode); +const Rtti<xml::Text> 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 <ostream> #include <vector> +#include <core/common/Rtti.hpp> #include <core/managed/Managed.hpp> #include <core/managed/ManagedContainer.hpp> @@ -101,19 +102,22 @@ public: * Additionally it might have other Nodes as children. */ class Element : public Node { +private: + ManagedVector<Node> children; + public: const std::string name; std::map<std::string, std::string> attributes; - ManagedVector<Node> children; Element(Manager &mgr, Handle<Element> parent, std::string name) - : Node(mgr, parent), name(std::move(name)) + : Node(mgr, parent), children(this), name(std::move(name)) { } Element(Manager &mgr, Handle<Element> parent, std::string name, std::map<std::string, std::string> 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<Node> &getChildren() const { return children; } + + void addChild(Handle<Node> child) { children.push_back(child); } + + void addChildren(std::vector<Handle<Node>> 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<xml::Node> XMLNode; +extern const Rtti<xml::Element> XMLElement; +extern const Rtti<xml::Text> 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 <iostream> #include <fstream> -#include "core/common/Rtti.hpp" -#include "core/model/Node.hpp" +#include <core/common/Rtti.hpp> +#include <core/model/Node.hpp> +#include <core/XML.hpp> #endif namespace ousia { @@ -598,6 +599,9 @@ void Manager::exportGraphviz(const char *filename) if (type.isa(RttiTypes::Node)) { name = dynamic_cast<const Node *>(objectPtr)->getName(); } + if (type.isa(RttiTypes::XMLElement)) { + name = dynamic_cast<const xml::Element *>(objectPtr)->name; + } // Print the node uintptr_t p = reinterpret_cast<uintptr_t>(objectPtr); |