#include <data_node_io.hpp>
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_map & | entity_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_type * | deserialize (std::istream &) |
Must be implemented to parse a node_type from the given istream. | |
virtual node_type * | deserialize (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_type & | metadata () |
metadata is an experimental feature allowing serializers to store arbitrary serializer-specific information in their data steams. | |
const node_type & | metadata () const |
A const overload of metadata(). |
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.
|
|
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. |
|
Definition at line 153 of file data_node_io.hpp. |
|
Definition at line 161 of file data_node_io.hpp. |
|
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. |
|
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. |
|
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. |
|
Sets the magic cookie for this type.
Definition at line 300 of file data_node_io.hpp. |
|
Gets this object's magic cookie.
Cookies are registered with Definition at line 291 of file data_node_io.hpp. |
|
A const overload of metadata().
Definition at line 316 of file data_node_io.hpp. |
|
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. |
|
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. |
|
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. |