#include <algo.hpp>
Public Member Functions | |
streamable_type_serialization_proxy () | |
template<typename NodeType, typename SerType> | |
bool | operator() (NodeType &dest, const SerType &src) const |
Creates a property in dest, called 'v', and sets its value to src using node_traits<NodeType>::set(dest,"v",src). | |
template<typename NodeType, typename SerType> | |
bool | operator() (const NodeType &src, SerType &dest) const |
Looks for a property set by the serialize operator and sets dest to its value. |
It "should" work with any type which meets these conditions:
The class name of serialized objects will be taken from s11n_traits<>::class_name(), which isn't truly valid because most streamable types are never registed via s11n_traits. Hmmm.
Its output is significantly bigger than using, e.g. node properties to store them, but with this proxy any streamable can be treated as a full-fledged Serializable, which allows some generic container-based serialization to be done regardless of the underlying types (see the various standard container algos for examples).
ACHTUNG: never pass the same Serializable to the operators more than once or you will get duplicate and/or incorrect data.
Definition at line 510 of file algo.hpp.
s11n::streamable_type_serialization_proxy::streamable_type_serialization_proxy | ( | ) | [inline] |
bool s11n::streamable_type_serialization_proxy::operator() | ( | NodeType & | dest, | |
const SerType & | src | |||
) | const [inline] |
Creates a property in dest, called 'v', and sets its value to src using node_traits<NodeType>::set(dest,"v",src).
Always returns true unless no class name can be found for src, in which case it returns false to avoid inserting a non-name node into the data tree (which might result in unreadable data later).
bool s11n::streamable_type_serialization_proxy::operator() | ( | const NodeType & | src, | |
SerType & | dest | |||
) | const [inline] |
Looks for a property set by the serialize operator and sets dest to its value.
The default for dest, in the case of a missing property or nonconvertable value is dest itself.
If the property is missing this function throws an s11n_exception. [Design note: this seems a bit harsh.]
On success dest gets assigned the property's value and true is returned. This function cannot catch a case of inability to convert the value into a SerType: client code interested in doing so should compare dest's value to a known error value after this function returns or throw from that type's istream operator on error.