Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cVariantData.h
Go to the documentation of this file.
1 //
4 
5 #ifndef _INC_cVariantData_H
6 #define _INC_cVariantData_H
7 #ifndef NO_PRAGMA_ONCE
8 #pragma once
9 #endif
10 
11 #include "cVariantType.h"
13 #include "GrayCore/include/cAtom.h"
16 #include "GrayCore/include/cTimeInt.h" // just predefine this? class Gray::cTimeInt;
17 #include "GrayCore/include/cTimeDouble.h" // just predefine this? class Gray::cTimeDouble;
19 
20 #ifndef _WIN32
21 typedef UINT32 COLORREF;
22 #endif
23 
24 namespace GrayLib
25 {
26  struct IXObject;
29  typedef UINT32 UID_t; // Sort of the same as a HASHCODE_t. cUID
30  class cVarMap;
31  class cVariantMap;
33  class cVariantData;
34  class cVariant;
35 
36  struct GRAYLIB_LINK cVariantCommon // static
37  {
40 
41  static const ITERATE_t k_MaxElements = 64*1024;
42  static const ITERATE_t k_MaxElements2 = 256;
43 
44  typedef INT32 CYS_t;
45  typedef INT64 CY_t;
46 
47  static const CYS_t k_CYSMul = 100;
48  static const CY_t k_CYMul = 10000;
49 
50  static StrLen_t GRAYCALL CopyLenQ(ATOMCHAR_t* pszDst, const ATOMCHAR_t* pszSrc, StrLen_t iLenMax, STR_BLOCK_TYPE eBlock);
51  };
52 
53 #pragma pack(push, 4) // must be packed in known format.
54 
56  {
60  public:
62  : cArrayStruct<cVariant>(iSize)
63  {
64  ASSERT(IS_INDEX_GOOD(iSize,k_MaxElements));
65  }
68  {
69  }
70 
71  size_t get_DataSize() const;
72  HRESULT SerializeOutput(cStreamOutput& file) const;
73  HRESULT SerializeInput2(cStreamInput& file);
74  COMPARE_t Compare(const cVariantArray& aVals) const;
75 
76  const cVariant& GetArrayElement(ITERATE_t index) const;
77  };
78 
80  {
84 
85  typedef cHeapBlock SUPER_t;
86 
87  private:
88  ITERATE_t m_nQty;
89  BYTE m_eVarTypeElem;
90 
91  public:
92  cVariantArrayT(ITERATE_t iSize, VARTYPE_TYPE eVarTypeElem);
94  ~cVariantArrayT();
95 
97  {
99  return m_nQty;
100  }
102  {
103  return (VARTYPE_TYPE)m_eVarTypeElem;
104  }
105  cVariantData* GetElemPtr(ITERATE_t i) const;
106  size_t get_DataSize() const;
107 
108  size_t GetHeapStats(OUT ITERATE_t& iAllocCount) const
109  {
110  return SUPER_t::GetHeapStats(iAllocCount);
111  }
112  HRESULT SerializeOutput(cStreamOutput& file) const;
113  HRESULT SerializeInput2(cStreamInput& file);
114  };
115 
116  template< class _TYPE = float >
118  {
121  public:
122  _TYPE m_v[3];
123 
124  public:
125  operator _TYPE*()
126  {
127  return m_v;
128  }
129  operator const _TYPE*() const
130  {
131  return m_v;
132  }
133  };
134 
135  template<class _TYPE>
137  {
141  BYTE m_data[sizeof(_TYPE)];
142  };
143 
145  {
150 
151  friend class cVariantArrayT;
152 
153  public:
154  union // of cVariantStub
155  {
156 #define cVariantTypeDEF(a,b,c,d,e,f) c m_##a;
157 #include "cVariantTypes.tbl"
158 #undef cVariantTypeDEF
159  } m_u;
160 
161  static const cVariantTypeDef k_VarTypeDef[VARTYPE_QTY];
162 
164  static bool sm_bShowUnsignedAsHex;
165 
166  protected:
167  void DestructData(VARTYPE_TYPE eVarType);
168  void construct_Array(ITERATE_t iSize);
169  void construct_Array(const cVariantArray& a);
170  void construct_ArrayT(ITERATE_t iSize, VARTYPE_TYPE eVarTypeElem);
171  void construct_ArrayT(const cVariantArrayT& a);
172  void construct_Atom(const cAtomRef& a);
173  void construct_Atom(const ATOMCHAR_t* p);
174  void construct_String(const cStringA& s);
175  void construct_String(const char* pszVal);
176  void construct_StringW(const cStringW& s);
177  void construct_StringW(const wchar_t* pwVal);
178  void construct_Blob(const void* pData, size_t nSize);
179  void construct_Blob(const cHeapBlock& b);
180  void construct_Map(cVariantMap* p);
181  void construct_XObj(IXObject* p);
182 
183  size_t GetDataSize(VARTYPE_TYPE eVarType) const;
184  const void* GetDataPtr(VARTYPE_TYPE eVarType) const;
185  size_t GetHeapStats(VARTYPE_TYPE eVarType, OUT ITERATE_t& iAllocCount) const;
186 
187  bool IsEmptyVar(VARTYPE_TYPE eVarType) const;
188  bool IsZeroVar(VARTYPE_TYPE eVarType) const;
189  void InitZeroVar(VARTYPE_TYPE eVarType);
190  void InitVar(VARTYPE_TYPE eVarType, const cVariantData& vVal);
191 
192  StrLen_t GetStr_Array(ATOMCHAR_t* pszStr, StrLen_t iLenMax) const;
193  StrLen_t GetStr_ArrayT(ATOMCHAR_t* pszStr, StrLen_t iLenMax) const;
194  StrLen_t GetStr_CY(ATOMCHAR_t* pszStr, StrLen_t iLenMax) const;
195  StrLen_t GetStr_CYS(ATOMCHAR_t* pszStr, StrLen_t iLenMax) const;
196  StrLen_t GetStr_Blob(ATOMCHAR_t* pszStr, StrLen_t nLenMax) const;
197  StrLen_t GetStr_HResult(ATOMCHAR_t* pszStr, StrLen_t iLenMax, bool bQuote = true) const;
198 
199  StrLen_t GetStrExpT(VARTYPE_TYPE eVarType, ATOMCHAR_t* pszStr, StrLen_t iLenMax, bool bInArray = true) const;
200 
201  public:
202  static inline const cVariantTypeDef& GetVarTypeDef(VARTYPE_TYPE eVarType) noexcept
203  {
205  if (IS_INDEX_BAD(eVarType, VARTYPE_QTY))
206  {
207  DEBUG_CHECK(false);
208  eVarType = VARTYPE_NoType;
209  }
210  return k_VarTypeDef[eVarType];
211  }
212  static bool GRAYCALL IsVarTypeCompatible(VARTYPE_TYPE eVarType1, VARTYPE_TYPE eVarType2);
213  static COMPARE_t GRAYCALL CompareDataPtr(VARTYPE_TYPE eVarType, const void* pData1, const void* pData2);
214 
215  static inline bool IsXObj(VARTYPE_TYPE eVarType) noexcept
216  {
217  return eVarType == VARTYPE_XObj || eVarType == VARTYPE_UID ;
218  }
219 
220  // ASSUME we know type.
221  cVariantArray& dref_Array() const; // AKA AsArray ??
222  cVariantArrayT& dref_ArrayT() const;
223  const cAtomRef& dref_Atom() const;
224  const cStringA& dref_String() const;
225  const cStringW& dref_StringW() const;
226  cHeapBlock& dref_Blob() const;
227  cVariantMapPtr& dref_Map() const;
228  CIXObjPtr& dref_XObj() const;
229 
230  HRESULT SerializeOutputType(cStreamOutput& file, VARTYPE_TYPE eVarType) const;
231  HRESULT SerializeInputType(cStreamInput& file, VARTYPE_TYPE eVarType);
232  };
233 
234 #pragma pack(pop)
235 
236 }
237 
238 #ifdef GRAY_DLL // force implementation/instantiate for DLL/SO.
239 namespace Gray
240 {
241  template class CArray<GrayLib::cVariant, const GrayLib::cVariant&>;
242  template class cArrayTyped<GrayLib::cVariant, const GrayLib::cVariant&>;
243 }
244 #endif
245 
246 #endif
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define CATTR_PACKED
Definition: GrayCore.h:87
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define IS_INDEX_GOOD(i, q)
cast the (likely) int to unsigned to check for negatives.
Definition: Index.h:35
#define IS_INDEX_BAD(i, q)
cast the (likely) int to unsigned to check for negatives.
Definition: Index.h:34
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define DEBUG_CHECK(exp)
Definition: cDebugAssert.h:90
UINT32 COLORREF
ABGR (high to low bits)
Definition: cVariantData.h:21
Definition: cVarMap.h:109
Definition: cVariantData.h:80
ITERATE_t GetSize() const
Definition: cVariantData.h:96
size_t GetHeapStats(OUT ITERATE_t &iAllocCount) const
Definition: cVariantData.h:108
VARTYPE_TYPE get_VarTypeElem() const
Definition: cVariantData.h:101
Definition: cVariantData.h:56
cVariantArray(const SUPER_t &a)
Definition: cVariantData.h:66
cVariantArray(ITERATE_t iSize=0)
Definition: cVariantData.h:61
Definition: cVariantData.h:145
static const cVariantTypeDef & GetVarTypeDef(VARTYPE_TYPE eVarType) noexcept
Definition: cVariantData.h:202
static IXObjMgr * sm_pIXObjMgr
For cVariant UID to XObject conversion.
Definition: cVariantData.h:163
static bool IsXObj(VARTYPE_TYPE eVarType) noexcept
Definition: cVariantData.h:215
static bool sm_bShowUnsignedAsHex
show unsigned as hex when converting to string. default=true
Definition: cVariantData.h:164
Definition: cVarMap.h:248
Definition: cVariantType.h:46
Definition: cVariantData.h:118
Definition: cVariant.h:26
Definition: cArray.h:99
Definition: cArray.h:932
Definition: cAtom.h:63
Definition: cHeap.h:156
Definition: cIUnkPtr.h:32
Definition: cMem.h:311
Definition: cRefPtr.h:225
Definition: cStream.h:306
Definition: cStream.h:126
Definition: IXObject.h:69
Definition: IXObject.h:46
Definition: cMesh.h:22
VARTYPE_TYPE
< define types of structure/record elements. (COM uses VARTYPE=VARENUM for this) stored as BYTE
Definition: cVariantType.h:19
@ VARTYPE_NoType
Definition: cVariantType.h:24
@ VARTYPE_QTY
Definition: cVariantType.h:29
DECLARE_INTERFACE(IScriptableSetter)
cRefPtr< cVariantMap > cVariantMapPtr
Definition: cVariantData.h:31
cIUnkPtr< IXObject > CIXObjPtr
Definition: cVariantData.h:26
HASHCODE32_t UID_t
Sort of the same as a HASHCODE_t. not the same as UIDINDEX_t.
Definition: cUID.h:18
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
int COMPARE_t
result of compare. 0=same, 1=a>b, -1=a<b
Definition: cValT.h:17
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
int ITERATE_t
like size_t but signed
Definition: Index.h:28
char ATOMCHAR_t
the char form (UNICODE or not) for an atom. (for symbolic names)
Definition: StrConst.h:15
STR_BLOCK_TYPE
< quotes/brackets and parenthesis must be matched.
Definition: StrT.h:27
uint16 index
Definition: sample3.cpp:29
Definition: cVariantData.h:37
INT32 CYS_t
type for 2 fixed point int for currency/money.
Definition: cVariantData.h:44
INT64 CY_t
type for 4 fixed point int for currency/money.
Definition: cVariantData.h:45
Definition: cVariantData.h:137