Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

XmlSerializer Class Reference

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

#include <cxxtools/xml/xmlserializer.h>

List of all members.

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.
template<typename T>
void serialize (const T &type, const std::string &name)
 Serialize an object to XML.
void finish ()
void flush ()


Detailed Description

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

Constructor & Destructor Documentation

XmlSerializer (  ) 

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

XmlSerializer ( std::ostream &  os  ) 

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

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

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.


Member Function Documentation

void attach ( std::ostream &  os  ) 

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 attach ( cxxtools::xml::XmlWriter &  writer  ) 

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 detach (  ) 

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

void serialize ( const T &  type,
const std::string &  name 
)

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.

Copyright © 2008 The Tntnet Development Team
Tntnet 1.6