s11nlite::micro_api< SerializableType > Class Template Reference

micro_api is of arguable utility, written just to see what happens. More...

#include <micro_api.hpp>

List of all members.

Public Types

typedef SerializableType serializable_type
 The base Serializable interface associated with this object.

Public Member Functions

 micro_api (const std::string &serclass)
 Constructs an object with the given serializer_class().
 ~micro_api ()
 Does nothing.
 micro_api ()
 Constructs an object with the same serializer_class() as s11nlite::serializer_class().
std::string serializer_class () const
 Returns the current serializer class name.
void serializer_class (const std::string &s)
 Sets the current serializer class name.
bool buffer (const serializable_type &src)
 Serializes src to an internal buffer, which may be fetched and cleared with buffer() and clear_buffer(), respectively.
std::string buffer () const
 Returns this object's buffered data, if any has been set using buffer(serializable_type).
void clear_buffer ()
 Clears any buffered data saved using buffer(serializable_type).
bool save (const serializable_type &src, const std::string &dest) const
 Saves src to dest, returning true on success and false on error.
bool save (const serializable_type &src, std::ostream &dest) const
 Overload taking an ostream.
serializable_typeload (const std::string &src) const
 Loads a serializable_type from src, returning 0 on failure and a valid pointer on success (which the caller owns).
serializable_typeload (std::istream &src) const
 An overload which takes an istream instead of a string.
serializable_typeload_buffer () const
 Loads a Serializable from the buffer() content, if any.


Detailed Description

template<typename SerializableType>
class s11nlite::micro_api< SerializableType >

micro_api is of arguable utility, written just to see what happens.

It is intended to be used for saving and loading sets of like-typed Serializables. For apps which do lots of loading and saving of homogeonous Serializables, micro_api can cut down on the amount of typing (intentionally ambiguous) needed:

s11nlite::micro_api<MyT> micro;
MyT my;
... populate my ...
micro.save( my, "somefile" );
...
MyT * your = micro.load( "somefile" );

Unlike the s11nlite interface, micro_api explicitely hides all node-level details. It does allow the user to set an output format (serializer class), as it may be desirable to save different collections of objects in different formats. For loading it uses s11nlite, so it supports any formats supported there.

Templatized on:

Any functions in this class might throw if their s11n[lite] counterparts do.

Definition at line 43 of file micro_api.hpp.


Member Typedef Documentation

template<typename SerializableType>
typedef SerializableType s11nlite::micro_api< SerializableType >::serializable_type

The base Serializable interface associated with this object.

Definition at line 50 of file micro_api.hpp.


Constructor & Destructor Documentation

template<typename SerializableType>
s11nlite::micro_api< SerializableType >::micro_api ( const std::string &  serclass  )  [inline]

Constructs an object with the given serializer_class().

Definition at line 80 of file micro_api.hpp.

template<typename SerializableType>
s11nlite::micro_api< SerializableType >::~micro_api (  )  [inline]

Does nothing.

Definition at line 85 of file micro_api.hpp.

template<typename SerializableType>
s11nlite::micro_api< SerializableType >::micro_api (  )  [inline]

Constructs an object with the same serializer_class() as s11nlite::serializer_class().

Definition at line 91 of file micro_api.hpp.


Member Function Documentation

template<typename SerializableType>
std::string s11nlite::micro_api< SerializableType >::serializer_class (  )  const [inline]

Returns the current serializer class name.

Definition at line 96 of file micro_api.hpp.

template<typename SerializableType>
void s11nlite::micro_api< SerializableType >::serializer_class ( const std::string &  s  )  [inline]

Sets the current serializer class name.

Definition at line 102 of file micro_api.hpp.

template<typename SerializableType>
bool s11nlite::micro_api< SerializableType >::buffer ( const serializable_type src  )  [inline]

Serializes src to an internal buffer, which may be fetched and cleared with buffer() and clear_buffer(), respectively.

Definition at line 111 of file micro_api.hpp.

template<typename SerializableType>
std::string s11nlite::micro_api< SerializableType >::buffer (  )  const [inline]

Returns this object's buffered data, if any has been set using buffer(serializable_type).

The buffer can be deserialized by wrapping it in an istringstream.

Definition at line 125 of file micro_api.hpp.

template<typename SerializableType>
void s11nlite::micro_api< SerializableType >::clear_buffer (  )  [inline]

Clears any buffered data saved using buffer(serializable_type).

Definition at line 131 of file micro_api.hpp.

template<typename SerializableType>
bool s11nlite::micro_api< SerializableType >::save ( const serializable_type src,
const std::string &  dest 
) const [inline]

Saves src to dest, returning true on success and false on error.

If the underlying call(s) to serialize throw then this function pass on the exception.

Definition at line 138 of file micro_api.hpp.

template<typename SerializableType>
bool s11nlite::micro_api< SerializableType >::save ( const serializable_type src,
std::ostream &  dest 
) const [inline]

Overload taking an ostream.

Definition at line 146 of file micro_api.hpp.

template<typename SerializableType>
serializable_type* s11nlite::micro_api< SerializableType >::load ( const std::string &  src  )  const [inline]

Loads a serializable_type from src, returning 0 on failure and a valid pointer on success (which the caller owns).

If the underlying call(s) to serialize throw then this function passes on the exception. In that case the object which was allocated for the process (if any) is destroyed, cleaned up by the s11n_traits::cleanup_functor mechanism, which is believed to be relatively safe from memory leaks.

Definition at line 163 of file micro_api.hpp.

template<typename SerializableType>
serializable_type* s11nlite::micro_api< SerializableType >::load ( std::istream &  src  )  const [inline]

An overload which takes an istream instead of a string.

Definition at line 171 of file micro_api.hpp.

template<typename SerializableType>
serializable_type* s11nlite::micro_api< SerializableType >::load_buffer (  )  const [inline]

Loads a Serializable from the buffer() content, if any.

The caller owns the returned pointer, which may be 0.

Definition at line 180 of file micro_api.hpp.


The documentation for this class was generated from the following file:
Generated on Thu Feb 8 10:20:48 2007 for libs11n-1.2.5 by  doxygen 1.5.0