10Duke Scale C++ Client
Loading...
Searching...
No Matches
JSONBuilder.h
1#ifndef TENDUKE_JSON_JSONBUILDER_H
2#define TENDUKE_JSON_JSONBUILDER_H
3
4#include <cstdint>
5#include <string>
6
7namespace tenduke { namespace json {
8
9class JSONObjectBuilder;
10
15{
16 friend class JSONBuilder;
17 friend class JSONObjectBuilder;
18public:
23 explicit JSONArrayBuilder(bool pretty);
24
36 JSONArrayBuilder & element(const std::string &object);
37
38private:
39 bool first;
40 bool pretty;
41
42 std::string json;
43};
44
49{
50 friend class JSONBuilder;
51 friend class JSONArrayBuilder;
52public:
57 explicit JSONObjectBuilder(bool pretty = true);
58
59public:
66 JSONObjectBuilder & property(const char *name, const JSONArrayBuilder &array);
67
74 JSONObjectBuilder & property(const char *name, const JSONObjectBuilder &object);
75
82 JSONObjectBuilder & property(const char *name, bool value);
83
91 JSONObjectBuilder & property(const char *name, const char * value, bool evenIfValueEmpty = false);
92
100 JSONObjectBuilder & property(const char *name, const std::string &value, bool evenIfValueEmpty = false);
101
108 JSONObjectBuilder & property(const char *name, int value);
109
116 JSONObjectBuilder & property(const char *name, std::int64_t value);
117
124 JSONObjectBuilder & property(const char *name, std::uint64_t value);
125
132 JSONObjectBuilder & property(const std::string &name, const JSONArrayBuilder &array);
133
140 JSONObjectBuilder & property(const std::string &name, const JSONObjectBuilder &object);
141
148 JSONObjectBuilder & property(const std::string &name, bool value);
149
157 JSONObjectBuilder & property(const std::string &name, const char *value, bool evenIfValueEmpty = false);
158
166 JSONObjectBuilder & property(const std::string &name, const std::string &value, bool evenIfValueEmpty = false);
167
174 JSONObjectBuilder & property(const std::string &name, int value);
175
182 JSONObjectBuilder & property(const std::string &name, std::int64_t value);
183
190 JSONObjectBuilder & property(const std::string &name, std::uint64_t value);
191
192private:
193 void appendPropertyName(const char *name);
194 JSONObjectBuilder & resetFirst();
195
196private:
197 bool firstProperty;
198 bool pretty;
199 std::string json;
200};
201
208{
209public:
214 explicit JSONBuilder(bool pretty = true);
215
216public:
222 JSONArrayBuilder startArray(bool pretty = true);
223
229 JSONObjectBuilder startObject(bool pretty = true);
230
237
244
249 std::string build();
250
251private:
252 std::string json;
253 bool pretty;
254};
255
256}}
257
258#endif //TENDUKE_JSON_JSONBUILDER_H
Builds JSON-array.
Definition JSONBuilder.h:15
JSONArrayBuilder & element(const JSONObjectBuilder &object)
Adds JSON-object to array.
Definition JSONBuilder.cpp:225
NOTE: This class is for now INTERNAL USE ONLY.
Definition JSONBuilder.h:208
JSONArrayBuilder startArray(bool pretty=true)
Starts building array.
Definition JSONBuilder.cpp:69
std::string build()
Builds the json.
Definition JSONBuilder.cpp:48
JSONObjectBuilder startObject(bool pretty=true)
Starts building object.
Definition JSONBuilder.cpp:74
JSONBuilder & array(const JSONArrayBuilder &a)
Adds array to document.
Definition JSONBuilder.cpp:61
JSONBuilder & object(const JSONObjectBuilder &o)
Adds object to document.
Definition JSONBuilder.cpp:53
Builds JSON objects.
Definition JSONBuilder.h:49
JSONObjectBuilder & property(const char *name, const JSONArrayBuilder &array)
Adds JSON array property.
Definition JSONBuilder.cpp:93
JSON support.
Definition JSONArray.h:10
Root for classes, functions and globals of 10Duke C++ Client.
Definition BackendConfiguration.h:7