10Duke Enterprise C++ Client
Loading...
Searching...
No Matches
SimpleJSONArray.h
1#ifndef TENDUKE_JSON_SIMPLEJSONARRAY_H
2#define TENDUKE_JSON_SIMPLEJSONARRAY_H
3
4#include "json/JSONArray.h"
5
6#include "./SimpleJSONElement.h"
7
8namespace tenduke { namespace json {
9
10class SimpleJSONArray : public virtual ::tenduke::json::JSONArray, public ::tenduke::json::SimpleJSONElement
11{
12public:
13 SimpleJSONArray()
14 : ::tenduke::json::SimpleJSONElement(::tenduke::json::JSONElement::Type::ARRAY),
15 values({})
16 {
17 }
18
19 bool isEmpty() const override
20 {
21 return values.empty();
22 }
23
24 std::size_t getSize() const override
25 {
26 return values.size();
27 }
28
29 const std::vector<std::shared_ptr<::tenduke::json::JSONElement>> & getValues() const override
30 {
31 return values;
32 }
33
34 std::string asJSON() const override
35 {
36 std::string result = "[";
37 bool first = true;
38 for (const auto& v : values) {
39 if (!first) {
40 result += ", ";
41 }
42 else {
43 first = false;
44 }
45 result += v->asJSON();
46 }
47 return result + "]";
48 }
49
50 virtual void add(const std::shared_ptr<::tenduke::json::JSONElement> element)
51 {
52 values.emplace_back(element);
53 }
54
55private:
56 std::vector<std::shared_ptr<::tenduke::json::JSONElement>> values;
57};
58
59}} // tenduke
60
61#endif //TENDUKE_JSON_SIMPLEJSONARRAY_H
A JSON array.
Definition JSONArray.h:16
std::string asJSON() const override
Serializes the element as JSON.
Definition SimpleJSONArray.h:34
std::size_t getSize() const override
Returns number of elements in the array.
Definition SimpleJSONArray.h:24
bool isEmpty() const override
Checks if the array is empty.
Definition SimpleJSONArray.h:19
const std::vector< std::shared_ptr<::tenduke::json::JSONElement > > & getValues() const override
Returns the elements of the array.
Definition SimpleJSONArray.h:29
Definition SimpleJSONElement.h:11
JSON support.
Definition JSONArray.h:10
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4