summaryrefslogtreecommitdiff
path: root/slicer/xml/serializer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'slicer/xml/serializer.cpp')
-rw-r--r--slicer/xml/serializer.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp
index 6f5df3a..c6c6c5f 100644
--- a/slicer/xml/serializer.cpp
+++ b/slicer/xml/serializer.cpp
@@ -8,6 +8,11 @@
#include <stdexcept>
#include <glibmm/ustring.h>
+NAMEDFACTORY(".xml", Slicer::XmlFileSerializer, Slicer::FileSerializerFactory);
+NAMEDFACTORY(".xml", Slicer::XmlFileDeserializer, Slicer::FileDeserializerFactory);
+NAMEDFACTORY("application/xml", Slicer::XmlStreamSerializer, Slicer::StreamSerializerFactory);
+NAMEDFACTORY("application/xml", Slicer::XmlStreamDeserializer, Slicer::StreamDeserializerFactory);
+
namespace Slicer {
const std::string md_attribute = "xml:attribute";
const std::string md_text = "xml:text";
@@ -274,6 +279,33 @@ namespace Slicer {
ModelTreeProcessElement(doc->create_root_node(name), mp, defaultElementCreator);
}
+ XmlStreamSerializer::XmlStreamSerializer(std::ostream & s) :
+ strm(s)
+ {
+ }
+
+ XmlStreamDeserializer::XmlStreamDeserializer(std::istream & s) :
+ strm(s)
+ {
+ }
+
+ void
+ XmlStreamDeserializer::Deserialize(ModelPartPtr modelRoot)
+ {
+ xmlpp::DomParser dom;
+ dom.parse_stream(strm);
+ auto doc = dom.get_document();
+ DocumentTreeIterate(doc, modelRoot);
+ }
+
+ void
+ XmlStreamSerializer::Serialize(ModelPartPtr modelRoot)
+ {
+ xmlpp::Document doc;
+ modelRoot->OnEachChild(boost::bind(&XmlSerializer::ModelTreeIterateRoot, &doc, _1, _2));
+ doc.write_to_stream(strm);
+ }
+
XmlFileSerializer::XmlFileSerializer(const boost::filesystem::path & p) :
path(p)
{