Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
JsonReader Class Reference

Represents a JSON reader which implements Archiver concept. More...

#include <archiver.h>

Public Member Functions

 JsonReader (const char *json)
 Constructor.
 
 ~JsonReader ()
 Destructor.
 
 operator bool () const
 
JsonReaderStartObject ()
 
JsonReaderMember (const char *name)
 
bool HasMember (const char *name) const
 
JsonReaderEndObject ()
 
JsonReaderStartArray (size_t *size=0)
 
JsonReaderEndArray ()
 
JsonReaderoperator& (bool &b)
 
JsonReaderoperator& (unsigned &u)
 
JsonReaderoperator& (int &i)
 
JsonReaderoperator& (double &d)
 
JsonReaderoperator& (std::string &s)
 
JsonReaderSetNull ()
 

Static Public Attributes

static const bool IsReader = true
 
static const bool IsWriter = !IsReader
 

Detailed Description

Definition at line 56 of file archiver.h.

Constructor & Destructor Documentation

◆ JsonReader()

JsonReader::JsonReader ( const char * json)
Parameters
jsonA non-const source json string for in-situ parsing.
Note
in-situ means the source JSON string will be modified after parsing.

Definition at line 31 of file archiver.cpp.

31 : mDocument(), mStack(), mError(false) {
32 mDocument = new Document;
33 DOCUMENT->Parse(json);
34 if (DOCUMENT->HasParseError())
35 mError = true;
36 else {
37 mStack = new JsonReaderStack;
39 }
40}
#define DOCUMENT
Definition archiver.cpp:26
#define STACK
Definition archiver.cpp:27
std::stack< JsonReaderStackItem > JsonReaderStack
Definition archiver.cpp:24
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition document.h:2325
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition document.h:2506
@ BeforeStart
An object/array is in the stack but it is not yet called by StartObject()/StartArray().
Definition archiver.cpp:12
Here is the call graph for this function:

◆ ~JsonReader()

JsonReader::~JsonReader ( )

Definition at line 42 of file archiver.cpp.

42 {
43 delete DOCUMENT;
44 delete STACK;
45}

Member Function Documentation

◆ EndArray()

JsonReader & JsonReader::EndArray ( )

Definition at line 109 of file archiver.cpp.

109 {
110 if (!mError) {
111 if (CURRENT.IsArray() && TOP.state == JsonReaderStackItem::Closed)
112 Next();
113 else
114 mError = true;
115 }
116 return *this;
117}
#define CURRENT
Definition archiver.cpp:29
#define TOP
Definition archiver.cpp:28
@ Closed
An array is closed after read all element, but before EndArray().
Definition archiver.cpp:14

◆ EndObject()

JsonReader & JsonReader::EndObject ( )

Definition at line 58 of file archiver.cpp.

58 {
59 if (!mError) {
60 if (CURRENT.IsObject() && TOP.state == JsonReaderStackItem::Started)
61 Next();
62 else
63 mError = true;
64 }
65 return *this;
66}
@ Started
An object/array is called by StartObject()/StartArray().
Definition archiver.cpp:13

◆ HasMember()

bool JsonReader::HasMember ( const char * name) const

Definition at line 83 of file archiver.cpp.

83 {
84 if (!mError && CURRENT.IsObject() && TOP.state == JsonReaderStackItem::Started)
85 return CURRENT.HasMember(name);
86 return false;
87}
std::string name
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Member()

JsonReader & JsonReader::Member ( const char * name)

Definition at line 68 of file archiver.cpp.

68 {
69 if (!mError) {
70 if (CURRENT.IsObject() && TOP.state == JsonReaderStackItem::Started) {
71 Value::ConstMemberIterator memberItr = CURRENT.FindMember(name);
72 if (memberItr != CURRENT.MemberEnd())
74 else
75 mError = true;
76 }
77 else
78 mError = true;
79 }
80 return *this;
81}
(Constant) member iterator for a JSON object value
Definition document.h:102

◆ operator bool()

JsonReader::operator bool ( ) const
inline

Definition at line 70 of file archiver.h.

70{ return !mError; }

◆ operator&() [1/5]

JsonReader & JsonReader::operator& ( bool & b)

Definition at line 119 of file archiver.cpp.

119 {
120 if (!mError) {
121 if (CURRENT.IsBool()) {
122 b = CURRENT.GetBool();
123 Next();
124 }
125 else
126 mError = true;
127 }
128 return *this;
129}

◆ operator&() [2/5]

JsonReader & JsonReader::operator& ( double & d)

Definition at line 155 of file archiver.cpp.

155 {
156 if (!mError) {
157 if (CURRENT.IsNumber()) {
158 d = CURRENT.GetDouble();
159 Next();
160 }
161 else
162 mError = true;
163 }
164 return *this;
165}
CK_ULONG d

◆ operator&() [3/5]

JsonReader & JsonReader::operator& ( int & i)

Definition at line 143 of file archiver.cpp.

143 {
144 if (!mError) {
145 if (CURRENT.IsInt()) {
146 i = CURRENT.GetInt();
147 Next();
148 }
149 else
150 mError = true;
151 }
152 return *this;
153}

◆ operator&() [4/5]

JsonReader & JsonReader::operator& ( std::string & s)

Definition at line 167 of file archiver.cpp.

167 {
168 if (!mError) {
169 if (CURRENT.IsString()) {
170 s = CURRENT.GetString();
171 Next();
172 }
173 else
174 mError = true;
175 }
176 return *this;
177}
char * s

◆ operator&() [5/5]

JsonReader & JsonReader::operator& ( unsigned & u)

Definition at line 131 of file archiver.cpp.

131 {
132 if (!mError) {
133 if (CURRENT.IsUint()) {
134 u = CURRENT.GetUint();
135 Next();
136 }
137 else
138 mError = true;
139 }
140 return *this;
141}

◆ SetNull()

JsonReader & JsonReader::SetNull ( )

Definition at line 179 of file archiver.cpp.

179 {
180 // This function is for JsonWriter only.
181 mError = true;
182 return *this;
183}

◆ StartArray()

JsonReader & JsonReader::StartArray ( size_t * size = 0)

Definition at line 89 of file archiver.cpp.

89 {
90 if (!mError) {
91 if (CURRENT.IsArray() && TOP.state == JsonReaderStackItem::BeforeStart) {
93 if (size)
94 *size = CURRENT.Size();
95
96 if (!CURRENT.Empty()) {
97 const Value* value = &CURRENT[TOP.index];
99 }
100 else
102 }
103 else
104 mError = true;
105 }
106 return *this;
107}
#define value
Definition pkcs11.h:157

◆ StartObject()

JsonReader & JsonReader::StartObject ( )

Definition at line 48 of file archiver.cpp.

48 {
49 if (!mError) {
50 if (CURRENT.IsObject() && TOP.state == JsonReaderStackItem::BeforeStart)
52 else
53 mError = true;
54 }
55 return *this;
56}

Member Data Documentation

◆ IsReader

const bool JsonReader::IsReader = true
static

Definition at line 88 of file archiver.h.

◆ IsWriter

const bool JsonReader::IsWriter = !IsReader
static

Definition at line 89 of file archiver.h.


The documentation for this class was generated from the following files: