diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/XML.cpp | 11 | ||||
-rw-r--r-- | src/core/XML.hpp | 17 |
2 files changed, 20 insertions, 8 deletions
diff --git a/src/core/XML.cpp b/src/core/XML.cpp index ad69ba1..038cb86 100644 --- a/src/core/XML.cpp +++ b/src/core/XML.cpp @@ -4,7 +4,12 @@ namespace ousia { namespace xml { -void Element::serialize(std::ostream& out, unsigned int tabdepth) +void Node::serialize(std::ostream& out){ + out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; + doSerialize(out, 0); +} + +void Element::doSerialize(std::ostream& out, unsigned int tabdepth) { for (unsigned int t = 0; t < tabdepth; t++) { out << '\t'; @@ -15,7 +20,7 @@ void Element::serialize(std::ostream& out, unsigned int tabdepth) } out << ">\n"; for (auto &n : children) { - n->serialize(out, tabdepth + 1); + n->doSerialize(out, tabdepth + 1); } for (unsigned int t = 0; t < tabdepth; t++) { out << '\t'; @@ -23,7 +28,7 @@ void Element::serialize(std::ostream& out, unsigned int tabdepth) out << "</" << name << ">\n"; } -void Text::serialize(std::ostream& out, unsigned int tabdepth) +void Text::doSerialize(std::ostream& out, unsigned int tabdepth) { for (unsigned int t = 0; t < tabdepth; t++) { out << '\t'; diff --git a/src/core/XML.hpp b/src/core/XML.hpp index 824d6ce..9ca124a 100644 --- a/src/core/XML.hpp +++ b/src/core/XML.hpp @@ -57,18 +57,25 @@ namespace xml { * implement. */ class Node : public Managed { + public: Node(Manager &mgr) : Managed(mgr){}; /** - * When called this Node should serialize its data and write it to the - * given output stream. In case of Elements this includes child elements. + * This method writes an XML prolog and the XML representing the current + * node, including all children, to the given output stream. + * @param out is the output stream the serialized data shall be written to. + */ + void serialize(std::ostream &out); + /** + * This method just writes the XML representation of this node to the + * output stream, without the XML prolog. * * @param out the output stream the serialized data shall be written * to. * @param tabdepth the current tabdepth for prettier output. */ - virtual void serialize(std::ostream &out, unsigned int tabdepth) = 0; + virtual void doSerialize(std::ostream &out, unsigned int tabdepth) = 0; }; /** @@ -103,7 +110,7 @@ public: * * The end tag of this element. * */ - void serialize(std::ostream &out, unsigned int tabdepth = 0) override; + void doSerialize(std::ostream &out, unsigned int tabdepth) override; }; class Text : public Node { @@ -116,7 +123,7 @@ public: * This just writes the text to the output. * */ - void serialize(std::ostream &out, unsigned int tabdepth = 0) override; + void doSerialize(std::ostream &out, unsigned int tabdepth) override; }; } } |