Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

s11n::io::data_node_serializer< NodeT > Class Template Reference

data_node_serializer provides an interface for saving/loading a given abstract data node type to/from streams. More...

#include <data_node_io.hpp>

Inheritance diagram for s11n::io::data_node_serializer< NodeT >:

Inheritance graph
[legend]
List of all members.

Public Types

typedef NodeT node_type
 The underlying data type used to store serialized data.
typedef std::map< std::string,
std::string > 
translation_map
 A convenience typedef, mainly for subclasses.

Public Member Functions

 data_node_serializer ()
virtual ~data_node_serializer ()
virtual const translation_mapentity_translations () const
 Returns a map intended for use with s11n::io::strtool::translate_entities().
virtual bool serialize (const node_type &, std::ostream &)
 Must be implemented to format node_type to the given ostream.
virtual bool serialize (const node_type &src, const std::string &destfile)
 Overloaded to save dest to the given filename.
virtual node_typedeserialize (std::istream &)
 Must be implemented to parse a node_type from the given istream.
virtual node_typedeserialize (const std::string &src)
 Overloaded to load dest from the given filename.
std::string magic_cookie () const
 Gets this object's magic cookie.

Protected Member Functions

void magic_cookie (const std::string &c)
 Sets the magic cookie for this type.
node_typemetadata ()
 metadata is an experimental feature allowing serializers to store arbitrary serializer-specific information in their data steams.
const node_typemetadata () const
 A const overload of metadata().

Detailed Description

template<typename NodeT>
class s11n::io::data_node_serializer< NodeT >

data_node_serializer provides an interface for saving/loading a given abstract data node type to/from streams.

It is designed for containers which comply with s11n's Data Node interface and conventions.

Conventions:

Must provide:

typedef NodeT node_type

Two de/serialize functions, following the stream-based interface shown here (filename-based variants are optional, but convenient for clients).

Potential TODOs for 1.3/1.4:

Definition at line 143 of file data_node_io.hpp.


Member Typedef Documentation

template<typename NodeT>
typedef NodeT s11n::io::data_node_serializer< NodeT >::node_type
 

The underlying data type used to store serialized data.

Reimplemented in s11n::io::compact_serializer< NodeType >, s11n::io::tree_builder_lexer< NodeType, LexerSharingContext >, s11n::io::expat_serializer< NodeType >, s11n::io::funtxt_serializer< NodeType >, s11n::io::funxml_serializer< NodeType >, s11n::io::parens_serializer< NodeType >, s11n::io::simplexml_serializer< NodeType >, s11n::io::wesnoth_serializer< NodeType >, s11n::io::tree_builder_lexer< NodeType, sharing::funtxt_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::compact_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::funxml_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::wesnoth_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::parens_sharing_context >, and s11n::io::tree_builder_lexer< NodeType, sharing::simplexml_sharing_context >.

Definition at line 150 of file data_node_io.hpp.

template<typename NodeT>
typedef std::map<std::string,std::string> s11n::io::data_node_serializer< NodeT >::translation_map
 

A convenience typedef, mainly for subclasses.

Reimplemented in s11n::io::compact_serializer< NodeType >, and s11n::io::parens_serializer< NodeType >.

Definition at line 161 of file data_node_io.hpp.


Constructor & Destructor Documentation

template<typename NodeT>
s11n::io::data_node_serializer< NodeT >::data_node_serializer  )  [inline]
 

Definition at line 153 of file data_node_io.hpp.

template<typename NodeT>
virtual s11n::io::data_node_serializer< NodeT >::~data_node_serializer  )  [inline, virtual]
 

Definition at line 161 of file data_node_io.hpp.


Member Function Documentation

template<typename NodeT>
virtual node_type* s11n::io::data_node_serializer< NodeT >::deserialize const std::string &  src  )  [inline, virtual]
 

Overloaded to load dest from the given filename.

It supports zlib/bz2lib decompression for files if your s11n lib supports them.

This is virtual for the same reason as serialize(string).

Reimplemented in s11n::io::tree_builder_lexer< NodeType, LexerSharingContext >, s11n::io::funxml_serializer< NodeType >, s11n::io::tree_builder_lexer< NodeType, sharing::funtxt_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::compact_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::funxml_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::wesnoth_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::parens_sharing_context >, and s11n::io::tree_builder_lexer< NodeType, sharing::simplexml_sharing_context >.

Definition at line 275 of file data_node_io.hpp.

template<typename NodeT>
virtual node_type* s11n::io::data_node_serializer< NodeT >::deserialize std::istream &   )  [inline, virtual]
 

Must be implemented to parse a node_type from the given istream.

It should return true on success, false on error.

The default implementation always returns 0 and does nothing.

Note that this function does not use s11n::deserialize() in any way, and is only coincidentally related to it.

Subclasses should try not to have to buffer the whole stream before parsing, because object trees can be arbitrarily large and a buffered copy effectively doubles the memory needed to store the tree during the deserialization process. Buffering behaviour is unspecified by this interface, however, and subclasses may pre-buffer the whole stream content if they need to.

Reimplemented in s11n::io::tree_builder_lexer< NodeType, LexerSharingContext >, s11n::io::expat_serializer< NodeType >, s11n::io::funxml_serializer< NodeType >, s11n::io::tree_builder_lexer< NodeType, sharing::funtxt_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::compact_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::funxml_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::wesnoth_sharing_context >, s11n::io::tree_builder_lexer< NodeType, sharing::parens_sharing_context >, and s11n::io::tree_builder_lexer< NodeType, sharing::simplexml_sharing_context >.

Definition at line 259 of file data_node_io.hpp.

template<typename NodeT>
virtual const translation_map& s11n::io::data_node_serializer< NodeT >::entity_translations  )  const [inline, virtual]
 

Returns a map intended for use with s11n::io::strtool::translate_entities().

The default implementation returns an empty map.

Subclasses should override this to return a translation map, if they need one. The default map is empty.

Be aware that this may very well be called post-main(), so subclasses should take that into account and provide post-main()-safe maps!

Reimplemented in s11n::io::funtxt_serializer< NodeType >, s11n::io::funxml_serializer< NodeType >, s11n::io::parens_serializer< NodeType >, s11n::io::simplexml_serializer< NodeType >, and s11n::io::wesnoth_serializer< NodeType >.

Definition at line 182 of file data_node_io.hpp.

template<typename NodeT>
void s11n::io::data_node_serializer< NodeT >::magic_cookie const std::string &  c  )  [inline, protected]
 

Sets the magic cookie for this type.

Definition at line 300 of file data_node_io.hpp.

template<typename NodeT>
std::string s11n::io::data_node_serializer< NodeT >::magic_cookie  )  const [inline]
 

Gets this object's magic cookie.

Cookies are registered with class_loader< data_node_serializer<NodeType> > types to map files to file input parsers.

Definition at line 291 of file data_node_io.hpp.

template<typename NodeT>
const node_type& s11n::io::data_node_serializer< NodeT >::metadata  )  const [inline, protected]
 

A const overload of metadata().

Definition at line 316 of file data_node_io.hpp.

template<typename NodeT>
node_type& s11n::io::data_node_serializer< NodeT >::metadata  )  [inline, protected]
 

metadata is an experimental feature allowing serializers to store arbitrary serializer-specific information in their data steams.

Definition at line 311 of file data_node_io.hpp.

template<typename NodeT>
virtual bool s11n::io::data_node_serializer< NodeT >::serialize const node_type src,
const std::string &  destfile
[inline, virtual]
 

Overloaded to save dest to the given filename.

The default implementation treats destfile as a file name and passes the call on to serialize(node_type,ostream). The output file is compressed if zfstream::compression_policy() has been set to enable it.

Returns true on success, false on error.

This function is virtual so that Serializers which do not deal with i/ostreams (e.g., those which use a database connection) can override it to interpret destfile as, e.g., a database-related string (e.g., connection, db object name, or whatever).

Fixed in 1.0.2: returns false when destfile is empty.

Definition at line 228 of file data_node_io.hpp.

template<typename NodeT>
virtual bool s11n::io::data_node_serializer< NodeT >::serialize const node_type ,
std::ostream & 
[inline, virtual]
 

Must be implemented to format node_type to the given ostream.

It should return true on success, false on error.

The default implementation always returns false.

Note that this function does not use s11n::serialize() in any way, and is only coincidentally related to it.

Reimplemented in s11n::io::compact_serializer< NodeType >, s11n::io::expat_serializer< NodeType >, s11n::io::funtxt_serializer< NodeType >, s11n::io::funxml_serializer< NodeType >, s11n::io::parens_serializer< NodeType >, s11n::io::simplexml_serializer< NodeType >, and s11n::io::wesnoth_serializer< NodeType >.

Definition at line 201 of file data_node_io.hpp.


The documentation for this class was generated from the following file:
Generated on Sat Dec 10 13:42:14 2005 for libs11n-1.2.1 by  doxygen 1.4.4