Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cCodedPtr.h
Go to the documentation of this file.
1 //
6 //
7 
8 #ifndef _INC_cCodedPtr_H
9 #define _INC_cCodedPtr_H
10 #ifndef NO_PRAGMA_ONCE
11 #pragma once
12 #endif
13 
14 #include "../GrayLibBase.h"
15 
16 namespace GrayLib
17 {
18  typedef void* (WINAPI *cCodedPtrFUNC_t)(void*); // like FARPROC but translates a pointer.
19 
20  template<class TYPE, cCodedPtrFUNC_t _TYPE_ENC_FUNC, cCodedPtrFUNC_t _TYPE_DEC_FUNC >
21  class cCodedPtrT
22  {
26 
27  private:
28  void* m_pCoded; // encoded pointer.
29  public:
30  cCodedPtrT(TYPE* pObj = nullptr)
31  : m_pCoded(_TYPE_ENC_FUNC(pObj))
32  {
33  }
35  {
36  }
37 
38  TYPE* get_Ptr() const
39  {
41  return((TYPE*)_TYPE_DEC_FUNC(m_pCoded));
42  }
43 
44  operator TYPE*() const
45  {
46  return(get_Ptr());
47  }
48 
49  TYPE& operator *() const
50  {
51  ASSERT(m_pCoded != nullptr); return(*get_Ptr());
52  }
53 
54  TYPE* operator ->() const
55  {
56  ASSERT(m_pCoded != nullptr); return(get_Ptr());
57  }
58  };
59 
60 #ifdef _WIN32
61  template<class TYPE>
62  class CCodedSystemPtr : public cCodedPtrT < TYPE, EncodeSystemPointer, DecodeSystemPointer >
63  {
69  public:
70  CCodedSystemPtr(TYPE* pObj = nullptr) : cCodedPtrT(pObj)
71  {
72  }
73  };
74  template<class TYPE>
75  class cCodedPtr : public cCodedPtrT < TYPE, EncodePointer, DecodePointer >
76  {
81 
82  public:
83  cCodedPtr(TYPE* pObj = nullptr) : cCodedPtrT(pObj)
84  {
85  }
86  };
87 #endif
88 };
89 
90 #endif // _INC_cCodedPtr_H
#define TYPE
Definition: StrT.cpp:38
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cCodedPtr.h:22
TYPE & operator*() const
Definition: cCodedPtr.h:49
~cCodedPtrT()
Definition: cCodedPtr.h:34
cCodedPtrT(TYPE *pObj=nullptr)
Definition: cCodedPtr.h:30
TYPE * get_Ptr() const
Definition: cCodedPtr.h:38
TYPE * operator->() const
Definition: cCodedPtr.h:54
Definition: cMesh.h:22
void *(WINAPI * cCodedPtrFUNC_t)(void *)
Definition: cCodedPtr.h:18