|
#include <smart_ptr.hpp>
Inheritance diagram for smart_ptr:
#include <vector> #include <list> #include <deque> #include <set> #include <map> #include "../shape_test.h" #include "../baseclass_test.h" #include "../smartptr/smart_ptr.hpp" //Only required header for normal smart_ptr usage void example_smart_ptr_usage() { smart_ptr<Shape> pShape1(new Circle("blue")); smart_ptr<Base, deep_copy_policy<> > pBase1 = new Derived1; smart_ptr<Shape, shared_ptr_policy<ref_link_policy>, clone_function_allocator_policy > pShape2(new Square("white")); smart_ptr<Base, copy_on_write_policy<> > pBase3(new Derived2); smart_ptr<Shape, shared_ptr_policy<>, clone_function_allocator_policy > pShape4(new Square("red")); smart_ptr<Base, copy_on_write_policy<ref_link_policy> > pBase5(new Derived1); smart_ptr<Shape, shared_ptr_policy<ref_link_policy> , clone_static_function_allocator_policy> pShape6(new Square("black")); std::vector<smart_ptr<Shape> > vShape; std::list<smart_ptr<Shape, deep_copy_policy<> > > lstShape; std::deque<smart_ptr<Shape, copy_on_write_policy<ref_link_policy>, clone_static_function_allocator_policy> > dqShape; //The smart_ptr can also be used with sorted containers (std::map, std::set). //When used with sorted containers, the base class must have an operator<() function. std::map<int, smart_ptr<Shape> > mShape1; std::map<smart_ptr<Shape>, int> mShape2; std::set<smart_ptr<Shape> > sShape; }
The arithmetic policy will not compile on VC++ 6.0, and it's excluded via #ifdef
To have greater compatibility and efficiency, it's better to use an STL container of smart_ptr than to use the boost pointer containers.
For greater efficiency and more flexibility, it's better to use smart_ptr, than to use boost::shared_ptr.
Definition at line 1159 of file smart_ptr.hpp.
Constructors and Destructor | |
template<typename T_obj> | |
smart_ptr (T_obj *type) | |
Normal constructor which takes a valid pointer. smart_ptr will only clone the type that is pass to the constructor. | |
smart_ptr (const smart_ptr &Src) | |
Copy constructor. | |
smart_ptr (implement_default_object use_default_obj=eYes) | |
Default constructor needed for std::map. | |
~smart_ptr () throw () | |
Destructor. | |
template<class CompatibleDerivedT, class OWNERSHIP_POLICY_T, class ALLOCATOR_POLICY_T, class CHECKING_POLICY_T, class COMPARISON_SEMANTIC_POLICY_T, class STREAM_OPERATOR_SEMANTIC_POLICY_T, class ARITHMETIC_SEMANTIC_POLICY_T> | |
smart_ptr (const smart_ptr< CompatibleDerivedT, OWNERSHIP_POLICY_T, ALLOCATOR_POLICY_T, CHECKING_POLICY_T, COMPARISON_SEMANTIC_POLICY_T, STREAM_OPERATOR_SEMANTIC_POLICY_T, ARITHMETIC_SEMANTIC_POLICY_T > &Src) | |
Constructor for smart pointer derived type smart_ptr<DerivedT>. | |
Operators | |
template<class CompatibleDerivedT, class OWNERSHIP_POLICY_T, class ALLOCATOR_POLICY_T, class CHECKING_POLICY_T, class COMPARISON_SEMANTIC_POLICY_T, class STREAM_OPERATOR_SEMANTIC_POLICY_T, class ARITHMETIC_SEMANTIC_POLICY_T> | |
smart_ptr & | operator= (const smart_ptr< CompatibleDerivedT, OWNERSHIP_POLICY_T, ALLOCATOR_POLICY_T, CHECKING_POLICY_T, COMPARISON_SEMANTIC_POLICY_T, STREAM_OPERATOR_SEMANTIC_POLICY_T, ARITHMETIC_SEMANTIC_POLICY_T > &Src) |
smart_ptr & | operator= (smart_ptr &Src) |
Assignment operator. | |
bool | operator! () const |
arith_retrn_type & | operator+= (const smart_ptr &Src) |
template<class T2> | |
arith_retrn_type & | operator+= (const T2 &Src) |
arith_retrn_type & | operator-= (const smart_ptr &Src) |
template<class T2> | |
arith_retrn_type & | operator-= (const T2 &Src) |
ownership_retrn_type_pointee | operator-> () |
ownership_retrn_type_ref | operator * () |
ownership_retrn_type_pointee | operator-> () const |
ownership_retrn_type_ref | operator * () const |
arith_retrn_type | operator+ (const smart_ptr &a, const smart_ptr &b) |
arith_retrn_type | operator- (const smart_ptr &a, const smart_ptr &b) |
Synchronize Methods | |
void | lock () const |
lock function is used with lock policy, and can be called manually (directly), or automatically through scope_lock. | |
void | unlock () const |
unlock function is used with lock policy, and can be called manually (directly), or automatically through scope_lock. | |
void | trylock () const |
trylock is an optional synchronization function that can be used with the lock policy. Use islock function to test trylock success. Some implementations do not support trylock and islock logic. | |
void | islock () const |
islock is an optional synchronization function that can be used with the lock policy. The islock function should never be used with lock() method, and should only be used with trylock(). Some implementations do not support trylock and islock logic. | |
Misc Methods | |
template<class T2> | |
smart_ptr & | equal (const T2 &Src) |
Use equal method to test if two pointee's are equal to each other. This does not test if the address of the pointers are equal to each other, and instead test if what the pointers are pointing to, are equal to each other. | |
clone_fct_Type | get_function_ptr () const |
The get_function_ptr method is mainly for internal usage, but it can not be made private/protected because policy methods require access to this method. | |
void | swap (smart_ptr< T > &other) throw () |
The swap method is not used by any policy, and it's implemented here to make this class compatible with generic coding. | |
template<class PT, class FPT> | |
void | make_clone (PT *&ptr, FPT &func_ptr) const |
The make_clone method is used to allow other smart pointers access to the cloning logic. One of the main reasons it's required, is because a derived T type, would not have access to the private members (m_clone_fct & m_type), so without make_clone, it would be difficult to clone smart_ptr's if the T type where not the same. | |
static void | set_default_object (const smart_ptr &NewValue) |
For added safety, call set_default_object to set default object before using this class as the second type in a std::map container. | |
Common Pointer Access Methods | |
T * | get_ptr () |
const T * | c_ptr () const |
const T & | c_ref () const |
Friends | |
template<class T1> | |
bool | operator== (const smart_ptr &a, const T1 &b) |
template<class T1> | |
bool | operator!= (const smart_ptr &a, const T1 &b) |
template<class T1> | |
bool | operator> (const smart_ptr &a, const T1 &b) |
template<class T1> | |
bool | operator< (const smart_ptr &a, const T1 &b) |
template<class T1> | |
bool | operator>= (const smart_ptr &a, const T1 &b) |
template<class T1> | |
bool | operator<= (const smart_ptr &a, const T1 &b) |
template<class TS> | |
TS & | operator>> (TS &is, smart_ptr &obj) |
template<class TS> | |
TS & | operator<< (TS &io, const smart_ptr &obj) |