Proud::RefCount< T > Class Template Reference

Public Types

typedef RefCount< T > Type
 

Public Member Functions

intptr_t GetRefCount ()
 
 RefCount (T *p=0)
 
 RefCount (const Type &other)
 
void Reset ()
 
void reset ()
 
Typeoperator= (const Type &other)
 
 operator T * () const
 
T * operator-> () const
 
T * get () const
 

Detailed Description

template<typename T>
class Proud::RefCount< T >

Smart pointer class. Please refer to <a target="_blank" href="http://guide.nettention.com/cpp_en#smart_ptr" >Smart Pointer</a>.

When using RefCount, the following must be considered.
- When RefCount refers object for the first time, it creates Tombstone. And when joint reference object appears, this tombstone will be shared.
  In other words, there is a time cost(memory allocation, 1 time) to create tombstone initially. 
- Cannot cast to related class types that are different to each other. Which means, RefCount<CFile> cannot be copied to RefCount<CObject>.  
  Type cast must be performed each time when coding as class type of RefCount entered higher possible base class.
class Base {};
class A:public Base {};
void Foo()
{
RefCount<A> a;
RefCount<Base> b;
a = b; // Error
}
void Foo2()
{
RefCount<Base> a;
RefCount<Base> b(new A);
a = b; // OK
A* p = (A*)a.get(); // This must be done to refer type A.
}
Parameters
TType of object that is to be handled by smart pointer
AllocTone of the values of AllocType
IsThreadSafe<NEVER USED!> If true then it is safe that many threads handle the variable of this smart pointer. But it reduces overall performance.

Constructor & Destructor Documentation

template<typename T>
Proud::RefCount< T >::RefCount ( T *  p = 0)
inlineexplicit

Constructor. Brings the ownership of the object that pointer p points.

template<typename T>
Proud::RefCount< T >::RefCount ( const Type other)
inline

Copy assignment operator

Member Function Documentation

template<typename T>
intptr_t Proud::RefCount< T >::GetRefCount ( )
inline

Returns the number of other variable objects that refer this object. In other words, the number of referring.