gatelib  2.1
g_cont_ref.h
1 #pragma once
2 
3 #include "g_cont_ref_custom.h"
4 #include "g_cont_ref_const.h"
5 
6 namespace g
7 {
8 namespace cont
9 {
10 
11 template < class T > class ref : public ref_custom<T>
12 {
13 public:
14  ref(){ G_VERBOSE_MSG_L5("ref constructor."); }
15 
16 #if G_AUTOPTION_ON_MSVC > 0 //Viual Studio Only
17  ref(const ref& other){ G_VERBOSE_MSG_L5("ref copy constructor"); ref_custom<T>::mRefTake<T>(other); }
18  ref& operator = (const ref& other) { G_VERBOSE_MSG_L5("ref copy operator"); ref_custom<T>::mRefTake<T>(other); return *this; }
19 
20  template <class O> ref(const ref<O>& other):ref_custom<T>() { G_VERBOSE_MSG_L5("ref copy constructor (OTHER)"); this->mRefTake<O>(other); }
21  template <class O> ref& operator = ( const ref<O>& other ) { G_VERBOSE_MSG_L5("ref copy operator()"); this->mRefTake<O> (other); return *this; }
22  template <class O> bool tryRefTakeDynamically ( ref<O>& o ) { return this->mRefTakeTryDynamically<O>(o); }
23 #else
24  ref(const ref& other){ G_VERBOSE_MSG_L5("ref(const ref& other)"); this->mRefTake(other); }
25  ref& operator = (const ref& other) { G_VERBOSE_MSG_L5("ref& operator = (ref& other )"); this->mRefTake(other); return *this; }
26 
27  template <class O> ref(const ref<O>& other):ref_custom<T>() { G_VERBOSE_MSG_L5("ref(const ref<O>& other)"); this->mRefTake(other); }
28  template <class O> ref& operator = ( const ref<O>& other ) { G_VERBOSE_MSG_L5("ref& operator = ( ref<O> other )"); this->mRefTake (other); return *this; }
29  template <class O> bool tryRefTakeDynamically ( ref<O>& o ) { return this->mRefTakeTryDynamically(o); }
30 
31 #endif
32 
33  T& operator *() { G_VERBOSE_MSG_L5("T& ref_custom::operator *()"); return *this->mGetObjP(); }
34  T* operator ->() { G_VERBOSE_MSG_L5("T* ref_custom::operator ->()");return this->mGetObjP(); }
35  const T& operator *() const { G_VERBOSE_MSG_L5("const T& ref_custom::operator *()");return *this->mGetObjP(); }
36  const T* operator ->() const { G_VERBOSE_MSG_L5("const T* ref_custom::operator ->()");return this->mGetObjP(); }
37 
38  static ref g_cont_new ( AllocationPolicyAbstract* d_alloc_policy = AllocationPolicyAbstract::get_FromStandardPolicy ( ) )
39  {
40  ref<T> result;
41 
42  new ( result.mAllocateMemForObject(d_alloc_policy) )T();
43  result.mIncRef ( );//allocation has succeeded inc ref will cause deletion of T(), as ref count elapses.
44 
45  return result;
46  }
47 };
48 
49 }//namespace g
50 }//namespace cont
51 
52 
53 
Definition: g.mthread.ThreadSimpleEvent.h:5