1#ifndef TENDUKE_JSON_SIMPLEJSONOBJECT_H
2#define TENDUKE_JSON_SIMPLEJSONOBJECT_H
4#include "json/JSONObject.h"
5#include "./SimpleJSONElement.h"
13 : SimpleJSONElement(::tenduke::json::JSONElement::OBJECT)
18 std::shared_ptr<::tenduke::json::JSONElement>
getProperty(
const std::string &propertyName)
const override
20 auto property = properties.find(propertyName);
22 if (property == properties.end()) {
26 return property->second;
29 bool hasProperty(
const std::string &propertyName)
const override
31 return properties.find(propertyName) != properties.end();
34 std::shared_ptr<::tenduke::json::JSONElement>
removeProperty(
const std::string &propertyName)
override
37 if (property !=
nullptr) {
38 properties.erase(propertyName);
43 const std::map<std::string, std::shared_ptr<JSONElement>> &
getProperties()
const override
50 std::string result =
"{";
52 for (
auto const & property : properties) {
59 result +=
'\"' +
property.first +
"\": " +
property.second->asJSON();
65 virtual void addProperty(
66 const std::string &name,
67 const std::shared_ptr<::tenduke::json::JSONElement> &value
69 properties[name] = value;
73 std::map<std::string, std::shared_ptr<::tenduke::json::JSONElement>> properties;
JSON object element.
Definition JSONObject.h:16
Definition SimpleJSONElement.h:11
std::shared_ptr<::tenduke::json::JSONElement > getProperty(const std::string &propertyName) const override
Returns object property by name.
Definition SimpleJSONObject.h:18
std::string asJSON() const override
Serializes the element as JSON.
Definition SimpleJSONObject.h:48
const std::map< std::string, std::shared_ptr< JSONElement > > & getProperties() const override
Returns all properties of this object.
Definition SimpleJSONObject.h:43
bool hasProperty(const std::string &propertyName) const override
Checks if the object has a property with given name.
Definition SimpleJSONObject.h:29
std::shared_ptr<::tenduke::json::JSONElement > removeProperty(const std::string &propertyName) override
Removes property from this object.
Definition SimpleJSONObject.h:34
JSON support.
Definition JSONArray.h:10
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4