10Duke Scale C++ Client
Loading...
Searching...
No Matches
JSONUtils.h
1#ifndef TENDUKE_JSON_JSONUTILS_H
2#define TENDUKE_JSON_JSONUTILS_H
3
4#include "./JSONArray.h"
5#include "./JSONElement.h"
6#include "./JSONNumber.h"
7#include "./JSONObject.h"
8#include <cstdint>
9#include <map>
10#include <memory>
11#include <string>
12
13namespace tenduke { namespace json {
14
23
31tenduke::json::JSONArray * castToArray(const std::shared_ptr<tenduke::json::JSONElement> &element);
32
40tenduke::json::JSONArray * castToArray(const std::unique_ptr<tenduke::json::JSONElement> &element);
41
50
58tenduke::json::JSONObject * castToObject(const std::shared_ptr<tenduke::json::JSONElement> &element);
59
67tenduke::json::JSONObject * castToObject(const std::unique_ptr<tenduke::json::JSONElement> &element);
68
79std::int64_t toInt64(const JSONElement * element, bool throwIfInvalid = true, std::int64_t defaultValue = 0);
80
91std::int64_t toInt64(const JSONElement & element, bool throwIfInvalid = true, std::int64_t defaultValue = 0);
92
98bool isBooleanTrue(const JSONElement *element);
99
105bool isBooleanTrue(const std::unique_ptr<const JSONElement> &element);
106
112bool isBooleanTrue(const std::shared_ptr<const JSONElement> &element);
113
122tenduke::json::JSONArray * getArray(const json::JSONObject *object, const std::string &propertyName);
123
134bool getBool(const json::JSONObject *object, const std::string &propertyName, bool defaultValue = false);
135
145std::int32_t getInt32(const tenduke::json::JSONObject *object, const std::string &propertyName, std::int32_t defaultValue = 0);
146
156std::int64_t getInt64(const tenduke::json::JSONObject *object, const std::string &propertyName, std::int64_t defaultValue = 0);
157
166tenduke::json::JSONNumber * getNumber(const tenduke::json::JSONObject *object, const std::string &propertyName);
167
176tenduke::json::JSONObject * getObject(const tenduke::json::JSONObject *object, const std::string &propertyName);
177
190std::string getStdString(const tenduke::json::JSONObject &object, const std::string &propertyName, const std::string &defaultValue = {});
191
204std::string getStdString(const tenduke::json::JSONObject *object, const std::string &propertyName, const std::string &defaultValue = {});
205
212std::map<std::string, std::string> toMapOfStrings(const tenduke::json::JSONObject * object);
213
214}}
215
216#endif // TENDUKE_JSON_JSONUTILS_H
A JSON array.
Definition JSONArray.h:16
Superclass of JSON elements.
Definition JSONElement.h:12
Represents JSON number.
Definition JSONNumber.h:12
JSON object element.
Definition JSONObject.h:16
JSON support.
Definition JSONArray.h:10
std::int64_t toInt64(const JSONElement *element, bool throwIfInvalid=true, std::int64_t defaultValue=0)
Returns given element as std::int_64t, assuming the element is JSONNumber.
Definition JSONUtils.cpp:67
std::string getStdString(const tenduke::json::JSONObject &object, const std::string &propertyName, const std::string &defaultValue={})
Helper to get JSON object property as std::string.
Definition JSONUtils.cpp:177
tenduke::json::JSONArray * castToArray(tenduke::json::JSONElement *element)
Type-casts given element to JSONArray.
Definition JSONUtils.cpp:10
tenduke::json::JSONObject * castToObject(tenduke::json::JSONElement *element)
Type-casts given element to JSONObject.
Definition JSONUtils.cpp:34
tenduke::json::JSONArray * getArray(const json::JSONObject *object, const std::string &propertyName)
Helper to get JSON object property as tenduke::json::JSONArray.
Definition JSONUtils.cpp:140
bool getBool(const json::JSONObject *object, const std::string &propertyName, bool defaultValue=false)
Helper to get JSON object property as boolean.
Definition JSONUtils.cpp:83
tenduke::json::JSONObject * getObject(const tenduke::json::JSONObject *object, const std::string &propertyName)
Helper to get JSON object property as tenduke::json::JSONObject.
Definition JSONUtils.cpp:158
std::int64_t getInt64(const tenduke::json::JSONObject *object, const std::string &propertyName, std::int64_t defaultValue=0)
Helper to get numeric JSON object property as std::int64_t.
Definition JSONUtils.cpp:108
bool isBooleanTrue(const JSONElement *element)
Returns true if element is JSONBoolean with value true.
Definition JSONUtils.cpp:204
std::int32_t getInt32(const tenduke::json::JSONObject *object, const std::string &propertyName, std::int32_t defaultValue=0)
Helper to get numeric JSON object property as std::int32_t.
Definition JSONUtils.cpp:95
tenduke::json::JSONNumber * getNumber(const tenduke::json::JSONObject *object, const std::string &propertyName)
Helper to get JSON object property as tenduke::json::JSONNumber.
Definition JSONUtils.cpp:121
Root for classes, functions and globals of 10Duke C++ Client.
Definition BackendConfiguration.h:7