#include <micro_api.hpp>
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_type * | load (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_type * | load (std::istream &src) const |
An overload which takes an istream instead of a string. | |
serializable_type * | load_buffer () const |
Loads a Serializable from the buffer() content, if any. |
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.
|
The base Serializable interface associated with this object.
Definition at line 50 of file micro_api.hpp. |
|
Constructs an object with the given serializer_class().
Definition at line 80 of file micro_api.hpp. |
|
Does nothing.
Definition at line 85 of file micro_api.hpp. |
|
Constructs an object with the same serializer_class() as s11nlite::serializer_class().
Definition at line 91 of file micro_api.hpp. References s11nlite::micro_api< SerializableType >::serializer_class(). |
|
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. |
|
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. References s11nlite::micro_api< SerializableType >::save(). |
|
Clears any buffered data saved using buffer(serializable_type).
Definition at line 131 of file micro_api.hpp. |
|
An overload which takes an istream instead of a string.
Definition at line 171 of file micro_api.hpp. |
|
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. |
|
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. |
|
Overload taking an ostream.
Definition at line 146 of file micro_api.hpp. |
|
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. Referenced by s11nlite::micro_api< SerializableType >::buffer(). |
|
Sets the current serializer class name.
Definition at line 102 of file micro_api.hpp. |
|
Returns the current serializer class name.
Definition at line 96 of file micro_api.hpp. Referenced by s11nlite::micro_api< SerializableType >::micro_api(). |