10Duke Enterprise C++ SDK
Toggle main menu visibility
Loading...
Searching...
No Matches
SimpleJSONObject.h
1
#ifndef TENDUKE_JSON_SIMPLEJSONOBJECT_H
2
#define TENDUKE_JSON_SIMPLEJSONOBJECT_H
3
4
#include "json/JSONObject.h"
5
#include "./SimpleJSONElement.h"
6
7
namespace
tenduke
{
namespace
json
{
8
9
class
SimpleJSONObject :
public
virtual
::tenduke::json::JSONObject
,
public
::tenduke::json::SimpleJSONElement
10
{
11
public
:
12
SimpleJSONObject()
13
: SimpleJSONElement(::tenduke::json::JSONElement::OBJECT)
14
, properties({})
15
{
16
}
17
18
std::shared_ptr<::tenduke::json::JSONElement>
getProperty
(
const
std::string &propertyName)
const override
19
{
20
auto
property
= properties.find(propertyName);
21
22
if
(property == properties.end()) {
23
return
nullptr
;
24
}
25
26
return
property
->second;
27
}
28
29
bool
hasProperty
(
const
std::string &propertyName)
const override
30
{
31
return
properties.find(propertyName) != properties.end();
32
}
33
34
std::shared_ptr<::tenduke::json::JSONElement>
removeProperty
(
const
std::string &propertyName)
override
35
{
36
auto
property
=
getProperty
(propertyName);
37
if
(property !=
nullptr
) {
38
properties.erase(propertyName);
39
}
40
return
property;
41
}
42
43
const
std::map<std::string, std::shared_ptr<JSONElement>> &
getProperties
()
const override
44
{
45
return
properties;
46
}
47
48
std::string
asJSON
()
const override
49
{
50
std::string result =
"{"
;
51
bool
first =
true
;
52
for
(
auto
const
& property : properties) {
53
if
(!first) {
54
result +=
','
;
55
}
56
else
{
57
first =
false
;
58
}
59
result +=
'\"'
+
property
.first +
"\": "
+
property
.second->asJSON();
60
}
61
result +=
'}'
;
62
return
result;
63
}
64
65
virtual
void
addProperty(
66
const
std::string &name,
67
const
std::shared_ptr<::tenduke::json::JSONElement> &value
68
) {
69
properties[name] = value;
70
}
71
72
private
:
73
std::map<std::string, std::shared_ptr<::tenduke::json::JSONElement>> properties;
74
};
75
76
}}
77
78
#endif
//TENDUKE_JSON_SIMPLEJSONOBJECT_H
tenduke::json::JSONObject
JSON object element.
Definition
JSONObject.h:16
tenduke::json::SimpleJSONElement
Definition
SimpleJSONElement.h:11
tenduke::json::SimpleJSONObject::getProperty
std::shared_ptr<::tenduke::json::JSONElement > getProperty(const std::string &propertyName) const override
Returns object property by name.
Definition
SimpleJSONObject.h:18
tenduke::json::SimpleJSONObject::asJSON
std::string asJSON() const override
Serializes the element as JSON.
Definition
SimpleJSONObject.h:48
tenduke::json::SimpleJSONObject::getProperties
const std::map< std::string, std::shared_ptr< JSONElement > > & getProperties() const override
Returns all properties of this object.
Definition
SimpleJSONObject.h:43
tenduke::json::SimpleJSONObject::hasProperty
bool hasProperty(const std::string &propertyName) const override
Checks if the object has a property with given name.
Definition
SimpleJSONObject.h:29
tenduke::json::SimpleJSONObject::removeProperty
std::shared_ptr<::tenduke::json::JSONElement > removeProperty(const std::string &propertyName) override
Removes property from this object.
Definition
SimpleJSONObject.h:34
tenduke::json
JSON support.
Definition
JSONArray.h:10
tenduke
Root for classes, functions and globals of 10Duke C++ Client.
Definition
APIRequest.h:4
core
services
common
src
json
SimpleJSONObject.h
Generated by
1.17.0