#include <stdexcept>
#include <s11n.net/s11n/tags.hpp>
#include <s11n.net/s11n/serialize.tpp>
Go to the source code of this file.
Namespaces | |
namespace | s11n |
namespace | s11n::Detail |
Functions | |
template<typename DataNodeType, typename SerializableT> | |
bool | serialize (DataNodeType &target, const SerializableT &src) |
Serializes src to target using the default API marshaling mechanism. | |
template<typename SerializableType> | |
void | cleanup_serializable (SerializableType &s) throw () |
Calls s11n_traits<SerializableType>::cleanup_functor()(s). | |
template<typename SerializableType> | |
void | cleanup_serializable (SerializableType *&s) throw () |
This overload provides cleanup handling for pointer types. | |
template<typename DataNodeType, typename DeserializableT> | |
bool | deserialize (const DataNodeType &src, DeserializableT &target) |
Deserializes target from src using the default API marshaling mechanism. | |
template<typename DataNodeType, typename DeserializableT> | |
bool | deserialize (const DataNodeType &src, DeserializableT *&target) |
Like the standard form of deserialize(), but if passed a null pointer, it attempts to classload the class and assign the passed-in pointer to it. | |
template<typename DataNodeType, typename DeserializableT> | |
bool | deserialize (const DataNodeType &src, cleanup_ptr< DeserializableT > &target) |
Identical to deserialize(const DataNodeType&,DeserializableT*&) except that it works on a cleanup_ptr<>. | |
template<typename DataNodeType, typename DeserializableT> | |
DeserializableT * | deserialize (const DataNodeType &src) |
Tries to deserialize a DeserializableT from src, using s11n_traits<DeserializableT>::factory_type()(node_traits<DataNodeType>::class_name(src)) to create a new DeserializableT. | |
template<typename DataNodeType, typename SerializableType> | |
SerializableType * | s11n_clone (const SerializableType &tocp) |
Clones an arbitrary SerializableType using its DataNodeType serialization implementation. | |
template<typename NodeType, typename Type1, typename Type2> | |
bool | s11n_cast (const Type1 &t1, Type2 &t2) |
"Casts" t1 to t2 using serialization. |
|
This overload provides cleanup handling for pointer types. This simplifies many algorithms over using s11n_traits<SerializableType>::cleanup_functor directly, as the algorithms do not need to care if they're using pointer-qualified types or not in order to clean them up properly. SerializableType requirements are as for the non-pointered variant of this function, plus:
This function does nothing if s is null, otherwise it calls cleanup_serializable(*s), deletes s, then assigns it to 0. Postcondition: (0 == s) Added in 1.1.3. |
|
Calls s11n_traits<SerializableType>::cleanup_functor()(s). This function is declared as no-throw because of its logical role in the destruction process, and dtors are normally prohibited from throwing. Any exceptions caught by this function are silently ignored (a warning might go out to a debug channel, probably cerr, but don't rely on it). SerializableType requirements:
Technically, if the type can be delete()d without leaking pointers, it's safe for use with this function, but this function SHOULD NOT be used as general cleanup tool. It is ONLY intended to be used with REGISTERED Serializables. This function guarantees not to leak when "cleaning up" containers holding unmanaged pointers as long as the associated cleanup_functors do their part. The model is such that once a cleanup_functor is in place for a given type, this function will inherently walk it and invoke the cleanup rules, which includes freeing any pointers along the way. Added in 1.1.3. |
|
Tries to deserialize a DeserializableT from src, using DeserializableT may not be a pointer-qualified type. On error it returns 0 or propagates on an exception, otherwise returns a pointer to a new object, which the caller takes ownership of. As of 1.1.3, this function relies on s11n::cleanup_serializable() in order to be able to specify what happens to the internally allocated object if deserialization fails. That function is called on the object before this function returns if deserialization fails. Prior to 1.1.3 this function would leak if this function failed and if DeserializableT contained unmanaged pointers (even indirectly, via sub-containment), such as in list<int*> or list<map<int,string*>>. |
|
Identical to deserialize(const DataNodeType&,DeserializableT*&) except that it works on a cleanup_ptr<>. The target may be empty (pointing to zero): if it is then dynamic loading is attempted, as described in the docs for the non-cleanup_ptr variant of this function. Returns true if target.get() is non-0 at the time this function exits (regardless of its value at entry time). |
|
Like the standard form of deserialize(), but if passed a null pointer, it attempts to classload the class and assign the passed-in pointer to it. If passed a non-null target then it behaves as if target were a reference, simply passing on the target after dereferencing it. For example:
T * t = 0; deserialize<NodeType,T>( mynode, t ); // t will be non-0 if it worked.
T * x = new X; if( deserialize<NodeType,T>( mynode, x ) ) { // x is now populated exactly as if we had called: // deserialize<NodeType,T>( mynode, *x ); } To get the class name, the algorithm first tries node_traits<DataNodeType>::class_name(src). If it cannot load a class using that name, it tries s11n_traits<DeserializableT>::class_name(target). Underlying calls to s11n::cl::classload() and serialization proxies may throw. If they do, the exception is passed on to the caller. If passed a null pointer and this function fails, target is not modified. If deserialization fails, any internally-created (DeserializableT*) is deallocated using cleanup_serializable(). If passed a non-null pointer and the function fails, behaviour is as for the non-pointer variant of deserialize() - target may or may not be in a defined state, as defined by the specific proxy algorithm. Added in s11n version 1.1.3. |
|
Deserializes target from src using the default API marshaling mechanism. Returns true on success. On error it returns false or passes on an exception. In either case, target might be in an undefined state, and may need manual interaction to free up resources (e.g., a list of pointers might have some pointers which need to be cleaned up during exception handling). The exact definition of its state after a failure is specified by the algorithm which deserializes the target (as defined via s11n_traits<DeserializableT>::deserialize_functor). Referenced by s11n::io::data_node_serializer< NodeType >::deserialize(). |
|
"Casts" t1 to t2 using serialization. This will work whenever t1 and t2 are "semantically 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. In practice, this means: if Type1 and Type2 both use the same, or compatible, de/ser algorithms, they are s11n_cast-able to one another. 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. Type2 may not currently be a pointer type, but Type1 may be. This will be fixed someday (when someone complains). Exceptions and errors: On error this function will return false or propagate an exception, as dictated by serialize() and then deserialize() (in that order). If Type1 and Type2 are not guaranteed to be monomorphic or base-most Serializable types, then it is good practice to explicitely specify them as templatized parameters, and not rely on implicit type selection, which might choose the wrong type (not the base-most one, which is what s11n is "keyed" to), which will mean that s11n "can't find" the registration code for the type. Definition at line 393 of file s11nlite.hpp. References s11nlite::instance(). |
|
Clones an arbitrary SerializableType using its DataNodeType serialization implementation. This function was renamed from clone() in version 1.1. Definition at line 384 of file s11nlite.hpp. References s11nlite::instance(). |
|
Serializes src to target using the default API marshaling mechanism. On success it always returns true, else false. If a the underlying operation throws, it will pass on the exception. Referenced by s11n::io::data_node_serializer< NodeType >::serialize(). |