Smart Pointers

copy_on_write_policy Class Template Reference

#include <smart_ptr.hpp>

List of all members.


Detailed Description

template<class REFERENCE_POLICY = ref_default_policy, class LOCK_POLICY = lock_default_policy, class WEAK_SUPPORT_POLICY = no_weak_support>
class copy_on_write_policy< REFERENCE_POLICY, LOCK_POLICY, WEAK_SUPPORT_POLICY >

This is a copy on write ownership policy. This policy is a mixture of a deep copy clone policy and the shared pointer policy. It shares the pointer as long as no attempt is made to access the pointee through non-constant operator->().
When access is made to the non-constant operator->(), the smart pointer clones itself if it's being referenced. When it clones itself, it performs a deep copy of the pointee.
Example Usage.

#include "../shape_test.h"

void example_copy_on_write_policy_usage()
{
        smart_ptr<ShapeWithNoCloneLogic, copy_on_write_policy<> > 
                pShapeWithNoCloneLogic1 = new CircleWithNoCloneLogic;

        smart_ptr<ShapeWithNoCloneLogic, copy_on_write_policy<> > 
                pShapeWithNoCloneLogic2(pShapeWithNoCloneLogic1);
        cout << pShapeWithNoCloneLogic2->GetTypeName() << endl;

        smart_ptr<Shape, copy_on_write_policy<> > pShape1 = new Square("Blue");
        smart_ptr<Shape, copy_on_write_policy<> > pShape2 = pShape1;
        cout << pShape2->GetShapeName() << endl;

        smart_ptr<Shape, copy_on_write_policy<ref_count_policy> > pShape3 = pShape1;
        smart_ptr<Shape, copy_on_write_policy<ref_link_policy> > pShape4 = pShape1;
        smart_ptr<Shape, copy_on_write_policy<ref_intrusive_policy> > pShape5 = pShape1;
}

See also:
smart_ptr, shared_ptr_policy, deep_copy_policy, ref_link_policy, ref_count_policy, ref_intrusive_policy, intrusive_lock_policy
Note:
The Ownership policy classes must take the lowest common denominator of arguments for constructor and common functions. Although this policy doesn't need the additional arguments, other policies do, and therefore to keep a standard interface, it must also take the additional arguments.

Definition at line 775 of file smart_ptr.hpp.

Public Member Functions

 copy_on_write_policy ()
template<class T1, class F1, class T2>
 copy_on_write_policy (REFERENCE_POLICY &src, const T1 &type, const F1 &, const T2 &)
template<class T, class F>
get_non_constant_ptr (T &type, F clone_fct)


The documentation for this class 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]