#include <abstract_creator.h>
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. |
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.
|
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. |
|
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 typesThat 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. |