#include <data_node_io.hpp>
Inheritance diagram for s11n::io::data_node_serializer< NodeT >:
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 155 of file data_node_io.hpp.
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, s11n::io::sharing::parens_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::compact_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::funtxt_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::simplexml_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::wesnoth_sharing_context >, and s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::funxml_sharing_context >.
Definition at line 162 of file data_node_io.hpp.
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 186 of file data_node_io.hpp.
s11n::io::data_node_serializer< NodeT >::data_node_serializer | ( | ) | [inline] |
Definition at line 165 of file data_node_io.hpp.
virtual s11n::io::data_node_serializer< NodeT >::~data_node_serializer | ( | ) | [inline, virtual] |
Definition at line 176 of file data_node_io.hpp.
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 201 of file data_node_io.hpp.
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 220 of file data_node_io.hpp.
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 247 of file data_node_io.hpp.
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, s11n::io::sharing::parens_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::compact_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::funtxt_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::simplexml_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::wesnoth_sharing_context >, and s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::funxml_sharing_context >.
Definition at line 278 of file data_node_io.hpp.
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, s11n::io::sharing::parens_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::compact_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::funtxt_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::simplexml_sharing_context >, s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::wesnoth_sharing_context >, and s11n::io::tree_builder_lexer< NodeType, s11n::io::sharing::funxml_sharing_context >.
Definition at line 294 of file data_node_io.hpp.
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 310 of file data_node_io.hpp.
void s11n::io::data_node_serializer< NodeT >::magic_cookie | ( | const std::string & | c | ) | [inline, protected] |
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 404 of file data_node_io.hpp.
const node_type& s11n::io::data_node_serializer< NodeT >::metadata | ( | ) | const [inline, protected] |