cxxtools::xml::XmlSerializer Class Reference

Serialize objects or object data to XML. More...

#include <cxxtools/xml/xmlserializer.h>

Public Member Functions

 XmlSerializer ()
 Construct a serializer without initializing the serializer for writing.
 XmlSerializer (std::ostream &os)
 Construct a serializer writing to a byte stream.
 XmlSerializer (cxxtools::xml::XmlWriter *writer)
 Construct a serializer writing to the given XmlWriter object.
 ~XmlSerializer ()
 Destructor.
void attach (std::ostream &os)
 Opens this serializer for writing into the given stream.
void attach (cxxtools::xml::XmlWriter &writer)
 Opens this serializer for writing into the given XmlWriter object.
void detach ()
 Detaches the currently set writer from this object.
void useXmlDeclaration (bool sw)
bool useXmlDeclaration () const
void useIndent (bool sw)
bool useIndent () const
void useEndl (bool sw)
bool useEndl () const
void useAttributes (bool sw)
bool useAttributes () const
template<typename T >
void serialize (const T &type, const std::string &name)
 Serialize an object to XML.
void finish ()

Static Public Member Functions

template<typename T >
static std::string toString (const T &type, const std::string &name, bool beautify=false)

Detailed Description

Serialize objects or object data to XML.

Thic class performs XML serialization of a single object or object data.

Constructor & Destructor Documentation

cxxtools::xml::XmlSerializer::XmlSerializer ( )

Construct a serializer without initializing the serializer for writing.

The serializer can be "opened" for writing by calling method attach().

cxxtools::xml::XmlSerializer::XmlSerializer ( std::ostream &  os)

Construct a serializer writing to a byte stream.

The serializer will write the objects as XML with UTF-8 encoding to the output stream.

cxxtools::xml::XmlSerializer::XmlSerializer ( cxxtools::xml::XmlWriter writer)

Construct a serializer writing to the given XmlWriter object.

The serializer will write the objects to the given XmlWriter object. This class will not free the given XmlWriter object. The caller is responsible to free it if needed.

cxxtools::xml::XmlSerializer::~XmlSerializer ( )

Destructor.

Member Function Documentation

void cxxtools::xml::XmlSerializer::attach ( std::ostream &  os)

Opens this serializer for writing into the given stream.

The serializer will write the objects as XML with UTF-8 encoding to the output stream.

This method does not have to be called if this XmlSerializer object was constructed using the constructor that takes an ostream or XmlWriter object. If this method is called anyway or called twice an std::logic_error is thrown.

void cxxtools::xml::XmlSerializer::attach ( cxxtools::xml::XmlWriter writer)

Opens this serializer for writing into the given XmlWriter object.

The serializer will write the objects to the given XmlWriter object.

This method does not have to be called if this XmlSerializer object was constructed using the constructor that takes an ostream or XmlWriter object. If this method is called anyway or called twice an std::logic_error is thrown.

This class will not free the given XmlWriter object. The caller is responsible to free it if needed.

void cxxtools::xml::XmlSerializer::detach ( )

Detaches the currently set writer from this object.

Before detaching the writer, the underlaying stream is flushed. If there is no currently set writer, nothing happens.

void cxxtools::xml::XmlSerializer::finish ( )
inline
template<typename T >
void cxxtools::xml::XmlSerializer::serialize ( const T &  type,
const std::string &  name 
)
inline

Serialize an object to XML.

The serializer will serialize the object type as XML to the assigned stream. The string name will be used as the instance name of type and appear as the name of the XML element. The type must be serializable.

template<typename T >
static std::string cxxtools::xml::XmlSerializer::toString ( const T &  type,
const std::string &  name,
bool  beautify = false 
)
inlinestatic
void cxxtools::xml::XmlSerializer::useAttributes ( bool  sw)
inline
bool cxxtools::xml::XmlSerializer::useAttributes ( ) const
inline
void cxxtools::xml::XmlSerializer::useEndl ( bool  sw)
inline
bool cxxtools::xml::XmlSerializer::useEndl ( ) const
inline
void cxxtools::xml::XmlSerializer::useIndent ( bool  sw)
inline
bool cxxtools::xml::XmlSerializer::useIndent ( ) const
inline
void cxxtools::xml::XmlSerializer::useXmlDeclaration ( bool  sw)
inline
bool cxxtools::xml::XmlSerializer::useXmlDeclaration ( ) const
inline

The documentation for this class was generated from the following file: