Smart Pointers

clone_static_function_allocator_policy Struct Reference

#include <smart_ptr.hpp>

List of all members.


Detailed Description

This is an allocator policy that uses a static cloning method. This policy requires that the target class have a static clone function. Each derived class must implement the static clone function. This includes derived derived classes, and so-on.
Example Usage.

struct ShapeWithStaticCloneLogic
{
        ShapeWithStaticCloneLogic(){}
        ~ShapeWithStaticCloneLogic(){}
        ShapeWithStaticCloneLogic(const ShapeWithStaticCloneLogic& src){}
        virtual std::string GetTypeName()const = 0;
};

struct CircleWithStaticCloneLogic : public ShapeWithStaticCloneLogic
{
        CircleWithStaticCloneLogic(){}
        ~CircleWithStaticCloneLogic(){}
        CircleWithStaticCloneLogic(const CircleWithStaticCloneLogic& src){}
        std::string GetTypeName()const{return "Circle";}
        inline static CircleWithStaticCloneLogic* do_clone(const CircleWithStaticCloneLogic& Src){return new CircleWithStaticCloneLogic(Src);}
};

void example_clone_static_function_allocator_policy_usage()
{
        smart_ptr<ShapeWithStaticCloneLogic, ownership_default_policy, clone_static_function_allocator_policy> vShape1(new CircleWithStaticCloneLogic);
        smart_ptr<ShapeWithStaticCloneLogic, ownership_default_policy, clone_static_function_allocator_policy> vShape2(vShape1);
        std::cout << vShape2->GetTypeName() << std::cout;
}

Note:
This policy is able to avoid slicing better, because is can detect slicing at compile time. This policy requires about the same amount of maintenance as the clone_function_allocator_policy, but more maintenance than the allocator_default_policy, because each derived class has to implement the static cloning function. Because of this cloning function requirement, this policy is less generic than the allocator_default_policy
See also:
smart_ptr, allocator_default_policy, clone_function_allocator_policy, allocator_array_policy

Definition at line 208 of file smart_ptr.hpp.

Static Public Member Functions

template<typename T_obj>
static T_obj * allocate (const T_obj *ptr)
 allocate clones the input argument by calling static function do_clone.
template<typename T_obj>
static void deallocate (T_obj *ptr)


Member Function Documentation

static T_obj* allocate const T_obj *  ptr  )  [inline, static]
 

allocate clones the input argument by calling static function do_clone.

Precondition:
Target type requires static do_clone function
Parameters:
[in] ptr valid pointer or NULL
Returns:
A new object, or NULL if input parameter is NULL

Definition at line 216 of file smart_ptr.hpp.

static void deallocate T_obj *  ptr  )  [inline, static]
 

Parameters:
[in] ptr valid pointer or NULL

Definition at line 224 of file smart_ptr.hpp.


The documentation for this struct was generated from the following file:
Generated on Wed Mar 29 21:58:59 2006 for Smart Pointers by  doxygen 1.4.6.Axter [Axter-Extended-Version]