Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members

s11n::abstract_creator< T > Struct Template Reference

abstract_creator is a helper to avoid some code having to know if a type is created on a stack or the heap. More...

#include <abstract_creator.h>

List of all members.

Public Types

typedef T value_type
 Same as (T).
typedef T base_value_type
 Same as (T).

Static Public Member Functions

bool create (value_type &v, const std::string &=std::string())
 This implementation does nothing and returns true.
void assign (value_type &lhs, const value_type &rhs)
 Assigs lhs to rhs and true.
value_type copy (const value_type &rhs)
 Returns a copy of.
void release (value_type &)
 Does nothing in this specialization.


Detailed Description

template<typename T>
struct s11n::abstract_creator< T >

abstract_creator is a helper to avoid some code having to know if a type is created on a stack or the heap.

This makes some template code easier to write, as it avoids syntax errors when trying something like:

if( object type is a pointer type ) delete(object);
else { ... }

This implementation creates items the stack via the default ctor. If instantiated with (T *) a pointer/heap-based specialization is activated instead.

Designed for use with, e.g., ListType::value_type, which will may be, e.g., either T or (T *).

These objects contain no state information.

Definition at line 45 of file abstract_creator.h.


Member Function Documentation

template<typename T>
bool s11n::abstract_creator< T >::create value_type v,
const std::string &  = std::string()
[inline, static]
 

This implementation does nothing and returns true.

The string argument is bogus for this implementation, and is used by the pointer specialization to implement polymorphic classloading of value_type.

Definition at line 60 of file abstract_creator.h.

template<typename T>
void s11n::abstract_creator< T >::release value_type  )  [inline, static]
 

Does nothing in this specialization.

Specializations which allocate resources are expected to release them here.

Note that release() exists because using a static boolean to flag a clean-up mode won't work:

typedef double T;
T val;
if( val is a pointer type ) { delete( val ); }
else ...

That will only work when T is actually a pointer type. Thus the following workaround:

typedef [some type] T;
T val;
typedef abstract_creator<T> AC;
assert( AC::create(val) ); // fine for (T) or (T *)
... use val ...
AC::release(val); // deletes pointers. No-op for value types
That works with pointers or non-pointers, and simply does nothing for non-pointers.

See object_reference_wrapper for a type which can wrap function calls to objects using the dot notation, regardless of their pointerness.

Definition at line 115 of file abstract_creator.h.


The documentation for this struct was generated from the following file:
Generated on Tue Oct 26 18:25:59 2004 for s11n by  doxygen 1.3.9.1