Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cObject.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cObject_H
7 #define _INC_cObject_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "PtrCast.h"
13 #include "cDebugAssert.h"
14 #include "cMem.h"
15 
16 namespace Gray
17 {
18  class cArchive;
19 
20  template <UINT32 _SIGVALID = 0xCA11AB11>
22  {
25 
27  private:
28  const UINT32 m_nVer;
29  const size_t m_nSizeofThis;
30 
31  public:
32  cObjectSignature(UINT32 nVer, size_t nSizeofThis)
33  : m_nVer(nVer), m_nSizeofThis(nSizeofThis)
34  {
35  }
37  {
38  }
39 
40  bool inline IsValidSignature(UINT32 nVer, size_t nSizeofThis) const
41  {
45 
46  if (!SUPER_t::isValidSignature())
47  return false;
48  if (nVer != m_nVer || nSizeofThis != m_nSizeofThis)
49  return false;
50  return true;
51  }
52  };
53 
54 #if defined(_MFC_VER)
55 #define COBJECT_IsValidCheck() cMem::IsValid(this,4) // not in _MFC_VER.
56 #else
57 
58 #ifdef _DEBUG
59 #define ASSERT_VALID(p) (p)->AssertValid() // Emulate MFC
60 #else
61 #define ASSERT_VALID(p) ASSERT((p)!=nullptr)
62 #endif
63 
64 #define COBJECT_IsValidCheck() CObject::isValidCheck() // check stuff but no ASSERT
65 
67  {
72 
73  public:
74  virtual ~CObject()
75  {
76  }
77  virtual bool isValidCheck() const noexcept
78  {
81  if (!cMem::IsValid(this, 4)) // at least not null. (or near it)
82  {
83  DEBUG_CHECK(false);
84  return false;
85  }
86  if (!IS_TYPE_OF(CObject, this)) // structure definitions are valid..
87  {
88  DEBUG_CHECK(false);
89  return false;
90  }
91  return true;
92  }
93  virtual void AssertValid() const
94  {
96  ASSERT(isValidCheck());
97  }
98 
99  virtual void Serialize(cArchive& a); // Emulate MFC method.
100  };
101 #endif // _MFC_VER
102 
103 #ifndef _MFC_VER
104  // Dynamic cObject is one that can be created knowing only its name and perhaps some interface that it supports. using cObjectFactory<T>
105 #define DECLARE_DYNAMIC(c) //__noop
106 #define IMPLEMENT_DYNAMIC(c, cb) //__noop
107 #endif // _MFC_VER
108 
109 };
110 
111 #endif
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define IS_TYPE_OF(t, p)
Definition: PtrCast.h:23
#define DECLSPEC_NOVTABLE
Definition: SysTypes.h:322
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define DEBUG_CHECK(exp)
Definition: cDebugAssert.h:90
Definition: cObject.h:67
virtual void AssertValid() const
< memory allocation and structure definitions are valid.
Definition: cObject.h:93
virtual bool isValidCheck() const noexcept
< memory allocation and structure definitions are valid.
Definition: cObject.h:77
virtual ~CObject()
Definition: cObject.h:74
Definition: cArchive.h:20
Definition: cMem.h:249
Definition: cObject.h:22
cObjectSignature(UINT32 nVer, size_t nSizeofThis)
Definition: cObject.h:32
bool IsValidSignature(UINT32 nVer, size_t nSizeofThis) const
Definition: cObject.h:40
~cObjectSignature()
Definition: cObject.h:36
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
class __DECL_IMPORT cArchive
Definition: cString.h:28
static bool __stdcall IsValid(const void *pData, size_t nSize=1, bool bWriteAccess=false) noexcept
Definition: cMem.cpp:33