From ce3dfdff0d03697bf0c9e0cc9fb45dc6ef7c4ba9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 13 Mar 2013 12:42:37 +0200 Subject: Add support for XML serializing values other than std::string --- cutl/xml/serializer.hxx | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'cutl/xml/serializer.hxx') diff --git a/cutl/xml/serializer.hxx b/cutl/xml/serializer.hxx index e3fef54..591a20a 100644 --- a/cutl/xml/serializer.hxx +++ b/cutl/xml/serializer.hxx @@ -50,17 +50,20 @@ namespace cutl typedef xml::qname qname_type; - // Serialize to std::ostream. Name is used in diagnostics to identify - // the document being serialized. std::ios_base::failure exception is - // used to report io errors (badbit and failbit). The indentation - // argument specifies the number of indentation spaces that should - // be used for pretty-printing. If 0 is passed, no pretty-printing - // is performed. + // Serialize to std::ostream. Output name is used in diagnostics to + // identify the document being serialized. std::ios_base::failure + // exception is used to report io errors (badbit and failbit). The + // indentation argument specifies the number of indentation spaces + // that should be used for pretty-printing. If 0 is passed, no + // pretty-printing is performed. // serializer (std::ostream&, - const std::string& name, + const std::string& output_name, unsigned short indentation = 2); + const std::string& + output_name () const {return oname_;} + // Serialization functions. // public: @@ -96,19 +99,37 @@ namespace cutl void attribute (const qname_type& qname, const std::string& value); + template + void + attribute (const qname_type& qname, const T& value); + void attribute (const std::string& name, const std::string& value); + template + void + attribute (const std::string& name, const T& value); + void attribute (const std::string& ns, const std::string& name, const std::string& value); + template + void + attribute (const std::string& ns, + const std::string& name, + const T& value); + // Characters. // void characters (const std::string& value); + template + void + characters (const T& value); + // Namespaces declaration. If prefix is empty, then the default // namespace is declared. If both prefix and namespace are empty, // then the default namespace declaration is cleared (xmlns=""). @@ -140,7 +161,7 @@ namespace cutl private: std::ostream& os_; std::ostream::iostate os_state_; // Original exception state. - const std::string name_; + const std::string oname_; genxWriter s_; genxSender sender_; -- cgit v1.1