s11n::cleanup_ptr< SerializableT > Struct Template Reference

An auto_ptr-like type intended to simplify pointer/exception safety in some deserialization algorithms by providing a way to completely and safely destroy partially-deserialized objects. More...

#include <serialize.hpp>

List of all members.

Public Types

typedef SerializableT cleaned_type

Public Member Functions

 cleanup_ptr () throw ()
 Constructs an object pointing to nothing.
 cleanup_ptr (cleaned_type *p) throw ()
 Transfers ownership of p to this object.
 ~cleanup_ptr () throw ()
 Uses s11n::cleanup_serializable<cleaned_type>() to free up up this->get().
cleaned_typeoperator * ()
 Dereferences this object's pointed-to object.
cleaned_typeoperator-> () throw ()
 Returns the same as get().
cleaned_typeget () throw ()
 Returns this object's pointed-to object without transfering ownership.
void take (cleaned_type *p) throw ()
 Transfers ownership of p to this object.
cleaned_typerelease () throw ()
 Transfers ownership of this->get() to the caller.
void clean () throw ()
 Cleans up any pointed-to object and points this object at 0.
void swap (cleanup_ptr &rhs) throw ()
 Swaps ownership of pointers with rhs.


Detailed Description

template<typename SerializableT>
struct s11n::cleanup_ptr< SerializableT >

An auto_ptr-like type intended to simplify pointer/exception safety in some deserialization algorithms by providing a way to completely and safely destroy partially-deserialized objects.

SerializableT must either have an explicit s11n_traits specialization installed or work properly with the default functor provided by s11n_traits::cleanup_functor. In practice, this means that types which manage the memory of their contained pointers are safe to work with the default, whereas the cleanup of unmanaged child pointers (e.g., std containers) requires a proper specialization.

Note that this type does not have copy/assignment ctors, due to the conventional constness of their right-hand sides: use the swap() or take() members to take over a pointer.

Added in 1.1.3.

Definition at line 263 of file serialize.hpp.


Member Typedef Documentation

template<typename SerializableT>
typedef SerializableT s11n::cleanup_ptr< SerializableT >::cleaned_type

Definition at line 266 of file serialize.hpp.


Constructor & Destructor Documentation

template<typename SerializableT>
s11n::cleanup_ptr< SerializableT >::cleanup_ptr (  )  throw () [inline]

Constructs an object pointing to nothing.

Definition at line 282 of file serialize.hpp.

template<typename SerializableT>
s11n::cleanup_ptr< SerializableT >::cleanup_ptr ( cleaned_type p  )  throw () [inline]

Transfers ownership of p to this object.

Definition at line 288 of file serialize.hpp.

template<typename SerializableT>
s11n::cleanup_ptr< SerializableT >::~cleanup_ptr (  )  throw () [inline]

Uses s11n::cleanup_serializable<cleaned_type>() to free up up this->get().

Definition at line 296 of file serialize.hpp.


Member Function Documentation

template<typename SerializableT>
cleaned_type& s11n::cleanup_ptr< SerializableT >::operator * (  )  [inline]

Dereferences this object's pointed-to object.

If this object does not point to anything it throws a std::runtime_error with an informative what() message explaining the error.

Definition at line 306 of file serialize.hpp.

template<typename SerializableT>
cleaned_type* s11n::cleanup_ptr< SerializableT >::operator-> (  )  throw () [inline]

Returns the same as get().

Definition at line 318 of file serialize.hpp.

template<typename SerializableT>
cleaned_type* s11n::cleanup_ptr< SerializableT >::get (  )  throw () [inline]

Returns this object's pointed-to object without transfering ownership.

Definition at line 327 of file serialize.hpp.

template<typename SerializableT>
void s11n::cleanup_ptr< SerializableT >::take ( cleaned_type p  )  throw () [inline]

Transfers ownership of p to this object.

This member takes the place of copy/assign operators, since those conventionally take a const right-hand argument.

Destroys the object this object pointed to before taking over ownership. 0 is a legal value for p.

If (p == this->get()) then this function does nothing.

Postcondition: p == this->get()

Definition at line 346 of file serialize.hpp.

Referenced by s11n::cleanup_ptr< SerializableT >::clean().

template<typename SerializableT>
cleaned_type* s11n::cleanup_ptr< SerializableT >::release (  )  throw () [inline]

Transfers ownership of this->get() to the caller.

Postcondition: 0 == this->get()

Definition at line 361 of file serialize.hpp.

template<typename SerializableT>
void s11n::cleanup_ptr< SerializableT >::clean (  )  throw () [inline]

Cleans up any pointed-to object and points this object at 0.

Does nothing if this object points to no object.

Postcondition: 0 == this->get()

Definition at line 375 of file serialize.hpp.

References s11n::cleanup_ptr< SerializableT >::take().

template<typename SerializableT>
void s11n::cleanup_ptr< SerializableT >::swap ( cleanup_ptr< SerializableT > &  rhs  )  throw () [inline]

Swaps ownership of pointers with rhs.

Definition at line 383 of file serialize.hpp.


The documentation for this struct was generated from the following file:
Generated on Sun Apr 27 11:49:50 2008 for libs11n-1.2.6 by  doxygen 1.5.3