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

s11n Namespace Reference

The s11n serialization (s11n) framework is an object serialization framework modelled heavily off work by Rusty Ballinger (bozo@users.sourceforge.net http://libfunutil.sourceforge.net). More...


Classes

struct  abstract_creator
 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  abstract_creator< T * >
 A specialization of abstract_creator to create objects on the heap, using the s11n classloader. More...
class  aliaser
 aliaser is a helper class for mapping single-token aliases to arbitrary strings, e.g. More...
class  argv_parser
 argv_parser is an object for parsing command line options. More...
class  children_holder
 EXPERIMENTAL! More...
class  class_loader
 A basic templates-based classloader implementation, intended to work in conjunction with s11n::instantiator for loading classes via registered object factories. More...
class  data_node
struct  data_node_child_serializer
 A helper functor to loop over serializable children. More...
struct  data_node_child_deserializer
 A helper functor deserialize a set of data_nodes. More...
struct  streamable_type_serializer_proxy
 A Serializable Proxy for streamable types. More...
class  environment
 environment is an OO front-end to getenv()-like functionality. More...
struct  object_deleter
 Deletes an object passed to it. More...
struct  object_reference_wrapper
 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  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  const_object_reference_wrapper
 const_object_reference_wrapper is identical in usage to object_reference_wrapper, except that it deals with const objects. More...
struct  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  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  child_pointer_deep_copier
 child_pointer_deep_copier is a functor to deep-copy a list of pointers into another list. More...
struct  equal_to
 Helper to avoid using bind1st/bind2nd. More...
struct  same_name
 Functor to return true if given NameableT objects match a certain name. More...
struct  object_factory
 object_factory is a helper object factory for the classes instantiator and class_loader. More...
struct  instantiator_sharing_context
 Internal marker class. More...
class  instantiator
 instantiator is essentially a static classloader, capable of loading classes by using registered factories for a given set of keys (e.g. More...
class  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  path_finder
 path_finder searches for keys using a set of prefixes (paths) and suffixes (file extensions). More...
struct  no_op_phoenix_initializer
 Internal helper class to provide a default no-op initializer for phoenixed objects. More...
struct  phoenix
 phoenix is class for holding singleton-style instances of BaseType objects. More...
class  pointer_cleaner
 A poor-man's garbage collector. More...
class  pointer_list
 pointer_list is a simple template class for a container of pointers to T, plus some memory management features. More...
struct  pointer_stripper
 Helper class to strip pointers from value_type typedefs. More...
struct  pointer_stripper< T * >
 Specialization to make (T *) equivalent to (T). More...
struct  pointer_stripper< T & >
class  property_server
 property_server is an experimental class for tying arbitrary properties to arbitrary objects. More...
class  property_store
 property_store is a class for storing arbitrary key/value pairs. More...
class  stdstring_tokenizer
 stdstring_tokenizer: More...
class  string_tokenizer
 string_tokenizer is a. More...

Namespaces

namespace  io
 The s11n::io namespace defines some i/o-related types which conform to the conventions expected by the s11n::de/serialize() free functions.
namespace  list
 The s11n::list namespace defines functors and algorithms for working with std::list/vector-style containers.
namespace  map
 The s11n::map namespace defines functors and algorithms for working with std::map and std::pair containers.
namespace  Private
 The Private namespace holds internal library types: these should not be used in client code.

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_finderoperator+= (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.


Detailed Description

The s11n serialization (s11n) framework is an object serialization framework modelled heavily off work by Rusty Ballinger (bozo@users.sourceforge.net http://libfunutil.sourceforge.net).

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:


Enumeration Type Documentation

enum s11n::CompressionPolicy
 

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).

Enumerator:
NoCompression  NoCompression implies just what it says - do not use compressed output streams.
GZipCompression  GZipCompression means to use the s11n::ogzstream class for output streams.
BZipCompression  BZipCompression means to use the s11n::obzstream class for output streams.

Definition at line 28 of file file_util.h.

enum s11n::TrimPolicy
 

A policy enum used by trim_string().

Enumerator:
TrimLeading  Trim only leading spaces.
TrimTrailing  Trim only trailing spaces.
TrimAll  Trim leading and trailing spaces.

Definition at line 36 of file string_util.h.


Function Documentation

template<typename NodeType, typename ChildType>
void s11n::add_child NodeType &  parent,
ChildType *  ch
 

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.

std::string s11n::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.

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.

void s11n::class_loader_debug_level int  dlevel  ) 
 

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.

template<typename BaseT>
class_loader<BaseT>& s11n::classloader  ) 
 

Returns BaseT's classloader.

See cllite::classloader() for important info.

Definition at line 29 of file s11n_core.h.

template<typename BaseType, typename SubType>
void s11n::classloader_register const std::string &  classname  ) 
 

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.

template<typename DataNodeType, typename SerializableType>
SerializableType* s11n::clone const SerializableType &  tocp  ) 
 

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

CompressionPolicy s11n::compression_policy  ) 
 

Returns the framework-wide CompressionPolicy preference.

See the s11n::CompressionPolicy enum.

void s11n::compression_policy CompressionPolicy  c  ) 
 

Sets the framework-wide CompressionPolicy preference.

See the s11n::CompressionPolicy enum.

template<typename InputIt, typename OutputIt, typename Predicate>
OutputIt s11n::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.

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

template<typename NodeType>
NodeType& s11n::create_child NodeType &  parent,
const std::string  nodename
 

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(), s11n::map::serialize_streamable_map(), and s11n::map::serialize_streamable_map_pairs().

template<typename IterT>
void s11n::delete_objects IterT  begin,
IterT  end
 

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

template<typename DataNodeType, typename DeserializableT>
DeserializableT* s11n::deserialize const DataNodeType &  src  ) 
 

Tries to deserialize a DeserializableT from src, using classload<DeserializableT>() to load DeserializableT.

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

template<typename DataNodeType, typename DeserializableT>
DeserializableT* s11n::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.

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

template<typename DataNodeType, typename DeserializableT>
bool s11n::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.

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

Referenced by s11nlite::deserialize_subnode().

unsigned long s11n::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.

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!)

template<typename NodeT>
NodeT* s11n::find_child_by_name NodeT &  parent,
const std::string &  name
 

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.

template<typename NodeT>
const NodeT* s11n::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.

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 s11nlite::deserialize(), 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().

template<typename NodeT, typename DestContainerT>
size_t s11n::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.

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

template<typename ListType>
void s11n::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.

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

template<typename MapType>
void s11n::free_map_entries MapType &  map  ) 
 

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

template<typename value_type>
value_type s11n::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.

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::map::deserialize_streamable_map(), s11n::property_store::get(), and s11n::data_node::get().

std::istream* s11n::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.

It will return one of the following types:

  • std::ifstream
  • s11n::gzstream
  • s11n::bzstream

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::data_node_serializer< NodeType >::deserialize(), s11n::io::load_node(), s11nlite::load_serializable(), and s11n::io::load_serializable().

std::ostream* s11n::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.

  • s11n::ogzstream
  • s11n::obzstream
  • std::ofstream

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 s11nlite::save(), s11n::io::save_serializable(), and s11n::io::data_node_serializer< NodeType >::serialize().

int s11n::hex2int const std::string &  wd  ) 
 

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.

template<typename T>
size_t& s11n::inst_count  ) 
 

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.

void s11n::normalize_string std::string &   ) 
 

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.
           

template<typename NodeType, typename Type1, typename Type2>
bool s11n::s11n_cast const Type1 &  t1,
Type2 &  t2
 

"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().

template<typename DataNodeType, typename SerializableT>
bool s11n::serialize_subnode DataNodeType &  target,
const std::string &  nodename,
const SerializableT &  src
 

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

unsigned long s11n::strip_slashes std::string &  str,
const char  slash = '\\'
 

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.

unsigned long s11n::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.

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


Generated on Thu Jun 16 16:18:12 2005 for s11n by  doxygen 1.4.3-20050530