From 57fe13de5c01bc8e5bbeb39acd131c9329245261 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 4 Jul 2014 11:15:44 +0200 Subject: Update streaming example with new implementation --- examples/cxx/tree/streaming/serializer.hxx | 91 ++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 6 deletions(-) (limited to 'examples/cxx/tree/streaming/serializer.hxx') diff --git a/examples/cxx/tree/streaming/serializer.hxx b/examples/cxx/tree/streaming/serializer.hxx index 4f2bf65..43fab69 100644 --- a/examples/cxx/tree/streaming/serializer.hxx +++ b/examples/cxx/tree/streaming/serializer.hxx @@ -1,4 +1,5 @@ // file : examples/cxx/tree/streaming/serializer.hxx +// author : Boris Kolpackov // copyright : not copyrighted - public domain #ifndef SERIALIZER_HXX @@ -59,6 +60,32 @@ public: const namespace_infomap&, const T& x); + // The next_open/close functions are like next() but split into two steps. + // next_open() serializes the object model fragment into an element leaving + // it open while next_close() closes the element. + // + template + void + next_open (const std::string& name, const T& x); + + template + void + next_open (const std::string& name, const namespace_infomap&, const T& x); + + template + void + next_open (const std::string& ns, const std::string& name, const T& x); + + template + void + next_open (const std::string& ns, + const std::string& name, + const namespace_infomap&, + const T& x); + + void + next_close (const std::string& name); + private: serializer (const serializer&); @@ -75,7 +102,13 @@ private: const namespace_infomap&); void - serialize (xercesc::DOMElement&); + serialize (xsd::cxx::xml::dom::auto_ptr); + + void + serialize_open (xsd::cxx::xml::dom::auto_ptr); + + void + serialize_close (const std::string& name); private: std::auto_ptr impl_; @@ -88,7 +121,7 @@ next (const std::string& name, const T& x) xsd::cxx::xml::dom::auto_ptr e ( create (name, namespace_infomap ())); *e << x; - serialize (*e); + serialize (e); } template @@ -97,7 +130,7 @@ next (const std::string& name, const namespace_infomap& map, const T& x) { xsd::cxx::xml::dom::auto_ptr e (create (name, map)); *e << x; - serialize (*e); + serialize (e); } template @@ -106,9 +139,8 @@ next (const std::string& ns, const std::string& name, const T& x) { xsd::cxx::xml::dom::auto_ptr e ( create (ns, name, namespace_infomap ())); - *e << x; - serialize (*e); + serialize (e); } template @@ -120,7 +152,54 @@ next (const std::string& ns, { xsd::cxx::xml::dom::auto_ptr e (create (ns, name, map)); *e << x; - serialize (*e); + serialize (e); +} + +template +inline void serializer:: +next_open (const std::string& name, const T& x) +{ + xsd::cxx::xml::dom::auto_ptr e ( + create (name, namespace_infomap ())); + *e << x; + serialize_open (e); +} + +template +inline void serializer:: +next_open (const std::string& name, const namespace_infomap& map, const T& x) +{ + xsd::cxx::xml::dom::auto_ptr e (create (name, map)); + *e << x; + serialize_open (e); +} + +template +inline void serializer:: +next_open (const std::string& ns, const std::string& name, const T& x) +{ + xsd::cxx::xml::dom::auto_ptr e ( + create (ns, name, namespace_infomap ())); + *e << x; + serialize_open (e); +} + +template +inline void serializer:: +next_open (const std::string& ns, + const std::string& name, + const namespace_infomap& map, + const T& x) +{ + xsd::cxx::xml::dom::auto_ptr e (create (ns, name, map)); + *e << x; + serialize_open (e); +} + +inline void serializer:: +next_close (const std::string& name) +{ + serialize_close (name); } #endif // SERIALIZER_HXX -- cgit v1.1