Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cSingletonPtr.h
Go to the documentation of this file.
1 //
5 //
6 
7 #ifndef _INC_cSingletonPtr_H
8 #define _INC_cSingletonPtr_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 
13 #include "cSingleton.h"
14 #include "cRefPtr.h"
15 
16 namespace Gray
17 {
18  template <class TYPE>
19  class cSingletonSmart : public cSingleton<TYPE>, public cRefBase
20  {
26 
27  protected:
28  cSingletonSmart(TYPE* pObject, const TYPEINFO_t& rAddrCode, int iRefCountStart = 0)
29  : cSingleton<TYPE>(pObject, rAddrCode)
30  , cRefBase(iRefCountStart)
31  {
33  }
35  };
36 
37  template <class TYPE>
38  class cSingletonPtr : protected cRefPtr < TYPE > // protected for read only.
39  {
42  typedef cRefPtr<TYPE> SUPER_t;
43 
44  public:
45  cSingletonPtr(bool bInit = true) : cRefPtr<TYPE>(bInit ? TYPE::get_Single() : nullptr)
46  {
48  }
49  void InitPtr()
50  {
53  this->put_Ptr(TYPE::get_Single());
54  }
55  void ReleasePtr()
56  {
58  }
59  bool isValidPtr() const
60  {
61  return SUPER_t::isValidPtr();
62  }
63  TYPE* operator -> () const
64  {
65  ASSERT_N(this->m_p != nullptr);
66  return this->m_p;
67  }
68 #if 1
69  TYPE* get_Ptr() const
70  {
72  ASSERT_N(this->m_p != nullptr);
73  return this->m_p;
74  }
75 #endif
76  };
77 };
78 #endif
#define TYPE
Definition: StrT.cpp:38
#define ASSERT_N(exp)
Definition: cDebugAssert.h:70
#define CHEAPOBJECT_IMPL
Definition: cHeapObject.h:32
TYPE * m_p
Pointer to some object of TYPE.
Definition: cPtrFacade.h:28
Definition: cRefPtr.h:22
Definition: cRefPtr.h:225
bool isValidPtr() const
Definition: cRefPtr.h:288
void ReleasePtr()
Definition: cRefPtr.h:320
void put_Ptr(TYPE *p)
Definition: cRefPtr.h:310
Definition: cSingletonPtr.h:39
cSingletonPtr(bool bInit=true)
Definition: cSingletonPtr.h:45
bool isValidPtr() const
Definition: cSingletonPtr.h:59
TYPE * get_Ptr() const
Definition: cSingletonPtr.h:69
void ReleasePtr()
Definition: cSingletonPtr.h:55
void InitPtr()
Definition: cSingletonPtr.h:49
TYPE * operator->() const
Definition: cSingletonPtr.h:63
Definition: cSingletonPtr.h:20
cSingletonSmart(TYPE *pObject, const TYPEINFO_t &rAddrCode, int iRefCountStart=0)
Definition: cSingletonPtr.h:28
Definition: cSingleton.h:127
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
std::type_info TYPEINFO_t
Definition: cTypeInfo.h:29