Classes | |
struct | s11n::abstract_creator< T > |
abstract_creator is a helper to avoid some code having to know if a type is created on a stack or the heap. More... | |
struct | s11n::abstract_creator< T * > |
A specialization of abstract_creator to create objects on the heap, using the s11n classloader. More... | |
class | s11n::aliaser |
aliaser is a helper class for mapping single-token aliases to arbitrary strings, e.g., similarly to typical Unix shell alias support. More... | |
class | s11n::argv_parser |
argv_parser is an object for parsing command line options. More... | |
class | s11n::children_holder< PType, CType > |
EXPERIMENTAL! More... | |
class | s11n::class_loader< BaseType, KeyType, UseSharedInstances > |
A basic templates-based classloader implementation, intended to work in conjunction with s11n::instantiator for loading classes via registered object factories. More... | |
class | s11n::data_node |
data_node is the next generation of s11n::s11n_node. More... | |
struct | s11n::data_node_child_serializer< NodeType > |
A helper functor to loop over serializable children. More... | |
struct | s11n::data_node_child_deserializer< ListType > |
A helper functor deserialize a set of data_nodes. More... | |
struct | s11n::streamable_type_serializer_proxy |
A Serializable Proxy for streamable types. More... | |
class | s11n::environment |
environment is an OO front-end to getenv()-like functionality. More... | |
struct | s11n::object_deleter |
Deletes an object passed to it. More... | |
struct | s11n::object_reference_wrapper< T > |
object_reference_wrapper is a type for giving access to T objects via their dot operator, regardless of whether they are pointers or not. More... | |
struct | s11n::object_reference_wrapper< T * > |
A specialization to wrap pointers to (T *) such that they can be accessed, via this wrapper, using a dot instead of -> . More... | |
struct | s11n::const_object_reference_wrapper< T > |
const_object_reference_wrapper is identical in usage to object_reference_wrapper, except that it deals with const objects. More... | |
struct | s11n::const_object_reference_wrapper< T * > |
A specialization to wrap pointers to (T *) such that they can be accessed, via this wrapper, using a dot instead of -> . More... | |
struct | s11n::pair_entry_deallocator |
A functor allowing pairs of PODs and pointers to be mixed together in any combination and be deallocated in a uniform way. More... | |
class | s11n::child_pointer_deep_copier< ListType > |
child_pointer_deep_copier is a functor to deep-copy a list of pointers into another list. More... | |
struct | s11n::child_pointer_deep_copier< ListType >::PtrStrip< T > |
struct | s11n::child_pointer_deep_copier< ListType >::PtrStrip< T * > |
struct | s11n::equal_to< ComparedType > |
Helper to avoid using bind1st/bind2nd. More... | |
struct | s11n::same_name< NameableT > |
Functor to return true if given NameableT objects match a certain name. More... | |
struct | s11n::object_factory< T, SubT > |
object_factory is a helper object factory for the classes instantiator and class_loader. More... | |
struct | s11n::instantiator_sharing_context |
Internal marker class. More... | |
class | s11n::instantiator< BaseType, KeyType, ContextType > |
instantiator is essentially a static classloader, capable of loading classes by using registered factories for a given set of keys (e.g., class names). More... | |
class | s11n::key_value_parser |
key_value_parser is a class for parsing "key=value"-style lines, like those which would come from a configuration file. More... | |
class | s11n::path_finder |
path_finder searches for keys using a set of prefixes (paths) and suffixes (file extensions). More... | |
struct | s11n::no_op_phoenix_initializer |
Internal helper class to provide a default no-op initializer for phoenixed objects. More... | |
struct | s11n::phoenix< BaseType, ContextType, InitializerType > |
phoenix is class for holding singleton-style instances of BaseType objects. More... | |
class | s11n::pointer_cleaner< T > |
A poor-man's garbage collector. More... | |
struct | s11n::pointer_cleaner< T >::object_deleter |
class | s11n::pointer_list< ChildType > |
pointer_list is a simple template class for a container of pointers to T, plus some memory management features. More... | |
struct | s11n::pointer_stripper< T > |
Helper class to strip pointers from value_type typedefs. More... | |
struct | s11n::pointer_stripper< T * > |
Specialization to make (T *) equivalent to (T). More... | |
struct | s11n::pointer_stripper< T & > |
class | s11n::property_server< ContextType, ObjIDType, KeyType > |
property_server is an experimental class for tying arbitrary properties to arbitrary objects. More... | |
class | s11n::property_store |
property_store is a class for storing arbitrary key/value pairs. More... | |
class | s11n::stdstring_tokenizer |
stdstring_tokenizer: More... | |
class | s11n::string_tokenizer |
string_tokenizer is a... More... | |
Typedefs | |
typedef std::map< std::string, std::string > | EntityMap |
Convenience typedef for use with translate_entities() and xml_entity_map(). | |
Enumerations | |
enum | CompressionPolicy { NoCompression = 0, GZipCompression = 1, BZipCompression = 2 } |
CompressionPolicy describes the framework-wide policy regarding compression when writing to files. More... | |
enum | TrimPolicy { TrimLeading = 0x01, TrimTrailing = 0x02, TrimAll = TrimLeading + TrimTrailing } |
A policy enum used by trim_string(). More... | |
Functions | |
template<typename IterT> void | delete_objects (IterT begin, IterT end) |
For each item in (begin,end] object_deleter()(*item) is called. | |
template<typename ListType> void | free_list_entries (ListType &c) |
Calls free_list_entries( c.begin(), c.end() ) and then erases the entries from c using it's erase() member fuction. | |
template<typename MapType> void | free_map_entries (MapType &map) |
Deletes any pointers in map, and does nothing for reference types. | |
template<typename T> size_t & | inst_count () |
Utility function to help keep an instance count of T. | |
void | class_loader_debug_level (int dlevel) |
Sets the framework-wide debug level. | |
int | class_loader_debug_level () |
Returns the framework-wide debug level. | |
template<typename NodeType, typename ChildType> void | add_child (NodeType &parent, ChildType *ch) |
Adds ch as a child of parent. | |
template<typename NodeType> NodeType & | create_child (NodeType &parent, const std::string nodename) |
Creates a new node, named nodename, as a child of parent. | |
template<typename NodeT, typename DestContainerT> size_t | find_children_by_name (const NodeT &parent, const std::string &name, DestContainerT &target) |
Each child in parent.children() which has the given name is copied into the target container. | |
template<typename NodeT> const NodeT * | find_child_by_name (const NodeT &parent, const std::string &name) |
Finds the FIRST child in parent with the given name and returns a pointer to it, or 0 if no such child is found. | |
template<typename NodeT> NodeT * | find_child_by_name (NodeT &parent, const std::string &name) |
A non-const overload of find_child_by_name(). | |
template<typename NodeType> void | dump_node_debug (const NodeType &n, std::ostream &os) |
Dumps some info about n to the given ostream, mostly useful for debugging failed deserialization. | |
template<typename DataNodeType, typename SerializableT> bool | serialize (DataNodeType &target, const SerializableT &src) |
Serializes src to target using a default API marshaling mechanism. | |
template<typename DataNodeType, typename DeserializableT> bool | deserialize (const DataNodeType &src, DeserializableT &target) |
Deserializes target from src using a default API marshaling mechanism. | |
template<typename DataNodeType, typename DeserializableT> DeserializableT * | deserialize (const DataNodeType &src) |
Tries to deserialize a DeserializableT from src, using classload<DeserializableT>() to load DeserializableT. | |
template<typename DataNodeType, typename SerializableT> bool | serialize_subnode (DataNodeType &target, const std::string &nodename, const SerializableT &src) |
Serializes src to as a subnode of target, named nodename. | |
template<typename DataNodeType, typename DeserializableT> bool | deserialize_subnode (const DataNodeType &src, const std::string &subnodename, DeserializableT &target) |
If a child named subnodename is found in src then this function returns deserialize( child, target ) and returns it's result, otherwise it returns 0. | |
template<typename DataNodeType, typename DeserializableT> DeserializableT * | deserialize_subnode (const DataNodeType &src, const std::string &subnodename) |
If a child named subnodename is found in src then this function returns the result of deserialize(child), otherwise it returns 0. | |
template<typename DataNodeType, typename SerializableType> SerializableType * | clone (const SerializableType &tocp) |
Clones an arbitrary SerializableType using it's DataNodeType serializable implementation. | |
template<typename NodeType, typename Type1, typename Type2> bool | s11n_cast (const Type1 &t1, Type2 &t2) |
"Casts" t1 to t2 using serialization. | |
void | compression_policy (CompressionPolicy c) |
Sets the framework-wide CompressionPolicy preference. | |
CompressionPolicy | compression_policy () |
Returns the framework-wide CompressionPolicy preference. | |
std::istream * | get_istream (const std::string &src, bool AsFile=true) |
Looks at the given file and tries to figure out what type of decompression stream, if any, should be used. | |
std::ostream * | get_ostream (const std::string &filename) |
Returns one of the following types of ostreams, depending on compression_policy() and compile-time library settings of HAVE_ZLIB and HAVE_BZLIB. | |
std::string | bytes_from_file (const std::string &fn, unsigned int bytes=128, bool read_past_nl=false) |
Returns the first 'bytes' bytes from the given file, assuming the file exists and can be read. | |
template<typename T> object_reference_wrapper< T > | reference_wrapper (T &t) |
A convenience function to return an object_reference_wrapper for t. | |
template<typename T> object_reference_wrapper< T > | reference_wrapper () |
A convenience function to return an empty object_reference_wrapper. | |
template<typename T> const_object_reference_wrapper< T > | const_reference_wrapper (const T &t) |
A convenience function to return a const_reference_wrapper wrapping t. | |
template<typename T> const_object_reference_wrapper< T > | const_reference_wrapper () |
A convenience function to return an empty const_reference_wrapper. | |
template<typename InputIt, typename OutputIt, typename Predicate> OutputIt | copy_if (InputIt first, InputIt last, OutputIt result, Predicate pred) |
For each item in [first,last), copies the item to OutputIt if pred(*item) returns true. | |
std::ostream & | operator<< (std::ostream &os, const key_value_parser &) |
enters k.key()=k.value() into os. | |
std::ostream & | operator<< (std::ostream &os, const path_finder &) |
operator << adds this object's path to os. | |
std::string & | operator<< (std::string &os, const path_finder &) |
Similar to the ostream version, it exports this object's path to the given string. | |
path_finder & | operator+= (path_finder &list, const std::string &p) |
Adds p to this object's path(). | |
template<typename BaseT> class_loader< BaseT > & | classloader () |
Returns BaseT's classloader. | |
template<typename BaseType> BaseType * | classload (const std::string key) |
See cllite::classload() for the docs. | |
template<typename BaseType, typename SubType> void | classloader_register (const std::string &classname) |
Registers SubType with BaseType's classloader, using a default object factory. | |
template<typename BaseType> void | classloader_register_base (const std::string &classname) |
template<typename BaseType> void | classloader_register_abstract (const std::string &classname) |
unsigned long | translate_entities (std::string &, const EntityMap &translation_map, bool reverse_translation=false) |
For each entry in the input string, the characters are mapped to string sequences using the given translation_map. | |
unsigned int | trim_string (std::string &, TrimPolicy=TrimAll) |
Trims leading and trailing whitespace from the input string and returns the number of whitespace characters removed. | |
std::string | trim_string (const std::string &, TrimPolicy=TrimAll) |
Trims leading and trailing whitespace from the input string and returns the trimmed string. | |
unsigned long | strip_slashes (std::string &str, const char slash= '\\') |
Attempts to remove all backslash-escaped chars from str. | |
unsigned long | escape_string (std::string &instring, const std::string &chars_to_escape, const std::string &escape_seq="\\") |
Adds an escape sequence in front of any characters in instring which are also in the list of chars_to_escape. | |
void | normalize_string (std::string &) |
normalize_string() is like trim_string() and strip_slashes(), combined, plus it removes leading/trailing quotes: | |
std::string | first_token (const std::string &) |
Returns the first whitespace-delimited token from the given string. | |
std::string | after_first_token (const std::string &) |
Returns the passed-in string, minus the first token. | |
unsigned int | int4hexchar (char c) |
Returns int values for chars '0'-'9', 'a'-'f' and 'A'-'F', else -1. | |
int | hex2int (const std::string &wd) |
Assumes wd to be a hex-encoded number. | |
template<typename value_type> value_type | from_string (const std::string &str, const value_type &errorVal) |
to_string() and from_string() provide an interface for converting strings into arbitrary other types and vice versa. | |
std::string | from_string (const char *str, const char *errorVal) |
A quasi-bogus overload to avoid the first-token-only problem of from_string<>(). | |
std::string | from_string (const std::string &str, const std::string &errorVal) |
A quasi-bogus overload to avoid the first-token-only problem of from_string<>(). | |
template<typename value_type> std::string | to_string (const value_type &obj) |
Returns a string representation of the given object, which must be ostreamble. | |
std::string | to_string (const char *obj) |
Overloader for strings-via-streams reasons. | |
std::string | to_string (const std::string &obj) |
Overloader for strings-via-streams reasons. |
As far as i know Rusty was the one to coin the phrase "s11n" (short for "serialization", in the same way that i18n is short for "internationalization").
In addition to the class documentation, please see the library manual, available in the source tree, in the docs subdir.
The most important places for clients to understand:
|
CompressionPolicy describes the framework-wide policy regarding compression when writing to files. (Sorry, pure stream-based compression isn't yet supported.) Setting to GZip/BZipCompression only enables compression if HAVE_ZLIB or HAVE_BZLIB ars set during library compilation, otherwise non-compressed streams are used in all cases. bzip compresses much better than gzip, but is notably slower. The speed should not make much of a difference unless you are working with very large data sets, and then you will notice that gzip is faster. Tip: you can use get_istream() on an arbitrary filename to get an appropriate input stream. Likewise, use get_ostream() to open writable a file with the policy-mandated stream type (if possible, defaulting to std::ofstream).
Definition at line 28 of file file_util.h. |
|
A policy enum used by trim_string().
Definition at line 36 of file string_util.h. |
|
Adds ch as a child of parent. Parent takes over ownership of ch. ContainerType must support: children().push_back( ChildType * ); Definition at line 45 of file data_node_algo.h. |
|
Returns the first 'bytes' bytes from the given file, assuming the file exists and can be read. It stops at the first newline character unless read_past_nl is true. On error an empty string is returned. This function is primarily intended to be used for looking for magic cookies. It is also sometimes useful, for example, for checking the type of a file or grabbing, e.g., the CVSROOT out of CVS/Root. Results are undefined with binary files. If this library is compiled with HAVE_ZLIB/HAVE_BZLIB set to true then this function supports transparent decompression of gzipped/bzipped files. It caches requests, so subsequent lookups are fast. |
|
Sets the framework-wide debug level. This is shared by all class_loaders, regardless of their templatized types. Currently only two values are supported: zero (no debugging output) and non-zero (all debugging output). Note that this uses a compile-time default, which means that if compiled without debugging, some debug messages will not show up because they happen pre-main(), before a client can set the debug level. |
|
Returns BaseT's classloader. See cllite::classloader() for important info. Definition at line 29 of file s11n_core.h. |
|
Registers SubType with BaseType's classloader, using a default object factory. SubType may be the same as BaseType. If BaseType is abstract it must first be registered as an abstract base, e.g., using s11n_CLASSLOADER_ABSTRACT_BASE(BaseType), and in that case BaseType should not be registered directly with this function. Maintenance warning: see the notes in this func! Definition at line 57 of file s11n_core.h. |
|
Clones an arbitrary SerializableType using it's DataNodeType serializable implementation. Returns a clone of tocp, or returns 0 on error. The caller owns the returned pointer. This copy is polymorphism-safe as long as all participating Serializables (re)implement the appropriate de/serialize operations, similarly to as they would do for a copy ctor or classical Clone() member function. Tip: clone() is a convenient way to test new de/serialize functions, e.g., for new Serializables, because if it works then deserializng from streams/files will also work. This function takes SerializableType through the whole de/serialize process, including classloading. Definition at line 432 of file data_node_serialize.h. References serialize(). |
|
Returns the framework-wide CompressionPolicy preference. See the s11n::CompressionPolicy enum. |
|
Sets the framework-wide CompressionPolicy preference. See the s11n::CompressionPolicy enum. |
|
For each item in [first,last), copies the item to OutputIt if pred(*item) returns true. Copied from: http://www.bauklimatik-dresden.de/privat/nicolai/html/en/cpp.html Definition at line 367 of file functor.h. Referenced by s11n::list::deserialize_pointer_list(), and find_children_by_name(). |
|
Creates a new node, named nodename, as a child of parent. Returns a reference to the new child, which parent now owns. NodeType must support: name( string ); children().push_back( NodeType * ); Definition at line 67 of file data_node_algo.h. Referenced by s11n::map::serialize_pair(), s11n::list::serialize_streamable_list(), and s11n::map::serialize_streamable_map_pairs(). |
|
For each item in (begin,end] object_deleter()(*item) is called. After this call the container from which the iterators come still contains the items but they are invalid - deleted pointers. The client should call erase(begin,end) to delete the entries, or use convenience function free_list_entries(), which accepts a list-style container. Definition at line 28 of file algo.h. Referenced by free_list_entries(). |
|
Tries to deserialize a DeserializableT from src, using Returns 0 on error, otherwise returns a pointer to a new object, which the caller takes ownership of. Definition at line 272 of file data_node_serialize.h. References deserialize(). |
|
If a child named subnodename is found in src then this function returns the result of deserialize(child), otherwise it returns 0. This is a convenience function: not part of the s11n kernel. Definition at line 404 of file data_node_serialize.h. References find_child_by_name(). |
|
If a child named subnodename is found in src then this function returns deserialize( child, target ) and returns it's result, otherwise it returns 0. This is a convenience function: not part of the s11n kernel. Definition at line 386 of file data_node_serialize.h. References find_child_by_name(). |
|
Adds an escape sequence in front of any characters in instring which are also in the list of chars_to_escape. Returns the number of escapes added. e.g., to escape (with a single backslash) all $, and \ in mystring with a backslash:
escape_string( mystring, "$%\\", "\\" ); (WARNING: the doxygen-generated HTML version of these docs may incorrectly show single backslashes in the above example!) |
|
A non-const overload of find_child_by_name(). Functionally identical to the const form, except for the constness of the parent argument and return value. Ownership of the returned pointer is not changed by calling this function (normally parent owns it, but clients may change that without affecting this function). When in doubt, i.e. during "normal usage", do NOT delete the returned pointer, because the parent node owns it. Definition at line 147 of file data_node_algo.h. |
|
Finds the FIRST child in parent with the given name and returns a pointer to it, or 0 if no such child is found. Ownership of the children does not change by calling this function: parent still owns it. Definition at line 124 of file data_node_algo.h. Referenced by s11n::list::deserialize_list(), s11n::map::deserialize_map(), s11n::map::deserialize_pair(), s11n::list::deserialize_streamable_list(), s11n::map::deserialize_streamable_map(), and deserialize_subnode(). |
|
Each child in parent.children() which has the given name is copied into the target container. Returns the number of items added to target. DestContainerT must support an insert iterator which will insert the pointer type contained in the list returned by parent.children(). i.e., it must hold (const SomeSerializableType *). Ownership of the children does not change by calling this function. Normally they are owned by the parent node (unless the client explicitely did something about that. Definition at line 100 of file data_node_algo.h. References copy_if(). Referenced by s11n::map::deserialize_streamable_map_pairs(). |
|
Calls free_list_entries( c.begin(), c.end() ) and then erases the entries from c using it's erase() member fuction. After this call, c will be empty. Definition at line 43 of file algo.h. References delete_objects(), and s11n::object_reference_wrapper< T >::good(). |
|
Deletes any pointers in map, and does nothing for reference types. This is used to treat arbitrary maps containing pointers or value types identically, by applying the same set of deallocation rules for both cases, simplifying some template implementations. Definition at line 60 of file algo.h. References s11n::object_reference_wrapper< T >::good(). |
|
to_string() and from_string() provide an interface for converting strings into arbitrary other types and vice versa. It supports any types which to which std::istream>>X and std::ostream<<X can be applied. One immediate use i can imagine for this class is converting arguments read in via the command-line or libreadline. Another is using it to simulate a multi-type std::map, where you store string representations of the data, which can be easily converted to the proper types via from_string(). Tries to from_string() a value of type value_type from the string str. Returns an object of type value_type, hopefully properly populated from the string, or errorVal if it cannot convert the value poperly. As errorVal is necessarily client/case-specific, you must supply your own error value. The error value need not be an error at all: this parameter is often used as a default value when pulling objects out of (e.g.) configuration object (with the intention being, "the one i ask for may not be there - in that case assume errorVal is the value i want"). The default implementation supports any type for which iostreams would work, as it uses those to do it's dirty work. You may, of course, specialize this class to de/serialize whatever you like. See the std::string specialization, below, for an example. Note that if you call from_string<T>(...) and T is one of std::string or char *, you will only get the first token from the string. To get around this, use the non-template forms, from_string( const std::string & ) and from_string( const char * ). This is a workaround until i learn how to properly specialize from_string<>() to handle string and (char *). i guess a Loki::TypeList would do the trick? This function is known to have problems with booleans: bool b = s11n::from_string( "foo", true ); because bool is normally an int of some type and the compiler may complain about ambiguity or type loss or some such. Definition at line 65 of file to_string.h. Referenced by s11n::property_store::get(), and s11n::data_node::get(). |
|
Looks at the given file and tries to figure out what type of decompression stream, if any, should be used. It will return one of the following types:
It will return NULL if it cannot open filename, or a std::ifstream if it cannot figure out a decompression scheme. It will only return one of the compressed stream types if this code is built with the appropriate macros: HAVE_ZLIB and HAVE_BZLIB, and then linked against -lgz and/or -lbz2. Thus, if this code is not built with compression support it is possible that it returns a std::ifstream reading from a compressed file. If AsFilename is true, input is treated as a file, otherwise it is treated as a string, for which an stringstream is returned. Compressor streams are currently only supported when AsFile is true. This feature has subtle uses in writing more generic client code for handling arbitrary input streams. Referenced by s11n::io::load_serializable(). |
|
Returns one of the following types of ostreams, depending on compression_policy() and compile-time library settings of HAVE_ZLIB and HAVE_BZLIB.
Note that this function only uses filename to pass to the stream's constructor, and does no checking of the file. The caller is responsible for deleting the pointer. For determining the type of input stream for a file, see s11n::get_istream(). Referenced by s11n::io::data_node_serializer< NodeType >::serialize(). |
|
Assumes wd to be a hex-encoded number. Returns it's decimal value. It may optionally be prefixed with '#', as in #ff00ff. Case is insignificant. |
|
Utility function to help keep an instance count of T. The returned reference should ONLY be modified from ctors and dtors of T. Definition at line 66 of file class_loader.h. |
|
normalize_string() is like trim_string() and strip_slashes(), combined, plus it removes leading/trailing quotes:
"this is a \ sample multi-line, backslash-escaped \ string." Will translate to: this is a sample multi-line, backslash-escaped string. |
|
"Casts" t1 to t2 using serialization. This will work whenever t1 and t2 are "compatible", whatever that really means. It can be used, e.g., to copy a list<int> to a vector<double>, provided both types have been proxied. Note that in the case of containers, the pointerness of the contained types is irrelevant: this works on both, thus a list<int> can be "cast" to a vector<double*>! As usual for a failed deserialization, if it returns false then t2 may be in an undefined state. There is no guaranty, however, that t2's deserialize operator will ever be called, as the serialization of t1 must first succeed for that to happen. Definition at line 460 of file data_node_serialize.h. References deserialize(), and serialize(). |
|
Serializes src to as a subnode of target, named nodename. Except for the addition of a subnode, it is identical to serialize( target, src ). This is a convenience function: not part of the s11n kernel. Definition at line 333 of file data_node_serialize.h. Referenced by s11n::data_node_child_serializer< NodeType >::operator()(). |
|
Attempts to remove all backslash-escaped chars from str. Removes backslash-escaped newlines from the input string, including any whitespace immediately following each backslash. The optional slash parameter defines the escape character. |
|
For each entry in the input string, the characters are mapped to string sequences using the given translation_map. Where no mappings exist, the input characters are left as-is. It returns the number of translations made. If reverse_translation == true then a reverse mapping is done: map values are treated as keys. This is useful, for example, for doing XML-entity-to-char conversions. It is amazingly INefficient, but seems to work okay. Referenced by s11n::io::key_value_serializer< NodeType >::operator()(), s11n::io::simplexml_serializer< NodeType >::serialize(), and s11n::io::funxml_serializer< NodeType >::serialize(). |