Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cJSONReader.h
Go to the documentation of this file.
1 //
5 #ifndef _INC_cJSONReader_H
6 #define _INC_cJSONReader_H
7 #ifndef NO_PRAGMA_ONCE
8 #pragma once
9 #endif
10 
11 #include "cJSON.h"
14 
15 namespace GrayLib
16 {
17  class cJSONReader;
18 
20  {
25 
26  public:
27  void* m_pVal;
28 
29  public:
30  cJSONReadVisitor(void* pVal)
31  : m_pVal(pVal)
32  {
33  }
34 
35  virtual void SetNull() = 0;
36  virtual void SetBool(bool bVal) = 0;
37  virtual void SetDouble(double dVal) = 0;
38  virtual void SetString(const char* pszString, StrLen_t nLen) = 0;
39 
40  virtual void SetArray() = 0;
41  virtual void SetMap() = 0;
42 
43  // create new child object. return nullptr = ERROR_CANCELED.
44  virtual void* MakeArrayElement(cJSONReader& r, ITERATE_t i) = 0;
45  virtual void* MakeMapElement(cJSONReader& r, const char* pszTag) = 0;
46  };
47 
49  {
52 
53  typedef cJSONReadVisitor SUPER_t;
54 
55  public:
57 
59  {
61  return *((cVariant*)m_pVal);
62  }
63 
64  virtual void SetNull() override;
65  virtual void SetBool(bool bVal) override;
66  virtual void SetDouble(double dVal) override;
67  virtual void SetString(const char* pszString, StrLen_t nLen) override;
68 
69  virtual void SetArray() override;
70  virtual void SetMap() override;
71 
72  // create new child object. return nullptr = ERROR_CANCELED.
73  virtual void* MakeArrayElement(cJSONReader& r, ITERATE_t i) override;
74  virtual void* MakeMapElement(cJSONReader& r, const char* pszTag) override;
75  };
76 
77  class GRAYLIB_LINK cJSONReader : public cTextReader, public cJSON
78  {
83  typedef cTextReader SUPER_t;
84 
85  public:
86  int m_iDepth;
87 
88  protected:
89  bool ReadWhitespace();
90 
91  HRESULT ReadString(char* pszOut, StrLen_t nSizeMax);
92  HRESULT ReadString(cJSONReadVisitor& rVisit);
93  HRESULT ReadArray(cJSONReadVisitor& rVisit);
94  HRESULT ReadMapElementName(OUT ATOMCHAR_t* pszName);
95  HRESULT ReadMap(cJSONReadVisitor& rVisit);
96 
97  public:
98  cJSONReader(const char* pszVal, StrLen_t nStrLenMax = StrT::k_LEN_MAX, StrLen_t iTabSize = cStrConst::k_TabSize);
99  cJSONReader(const cMemBlock& b, StrLen_t iTabSize = cStrConst::k_TabSize);
100  ~cJSONReader();
101 
102  HRESULT ReturnError(HRESULT hRes) const;
103  HRESULT ReadVisitor(cJSONReadVisitor& rVisit);
104  HRESULT ReadVar(OUT cVariant& rVar);
105 
106  static HRESULT GRAYCALL ReadVar(cStreamInput& stmIn, OUT cVariant& rVar);
107  };
108 }
109 
110 #endif
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cJSONReader.h:49
cVariant & get_V()
Definition: cJSONReader.h:58
Definition: cJSONReader.h:20
virtual void SetBool(bool bVal)=0
virtual void SetNull()=0
virtual void SetDouble(double dVal)=0
virtual void * MakeArrayElement(cJSONReader &r, ITERATE_t i)=0
void * m_pVal
Fill this target variant with the contents of the JSON.
Definition: cJSONReader.h:27
virtual void * MakeMapElement(cJSONReader &r, const char *pszTag)=0
virtual void SetString(const char *pszString, StrLen_t nLen)=0
virtual void SetMap()=0
cJSONReadVisitor(void *pVal)
Definition: cJSONReader.h:30
virtual void SetArray()=0
Definition: cJSONReader.h:78
int m_iDepth
Indent depth of reader.
Definition: cJSONReader.h:86
Definition: cJSON.h:23
Definition: cVariant.h:26
Definition: cMem.h:311
static const StrLen_t k_TabSize
default desired spaces for a tab.
Definition: StrConst.h:47
Definition: cStream.h:306
Definition: cTextPos.h:107
Definition: cMesh.h:22
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
static const StrLen_t k_LEN_MAX
arbitrary max size for Format() etc. NOTE: _MSC_VER says stack frame should be at least 16384
Definition: StrT.h:75