JsonObject.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
17* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
18* GNU General Public License
19*/
20
21#pragma once
22
23#include <memory>
24#include <utility>
25#include <vector>
26
27#include "JsonArray.h"
28#include "JsonData.h"
29#include "JsonValue.h"
30
31namespace armarx
32{
33 class JsonObject;
34 using JsonObjectPtr = std::shared_ptr<JsonObject>;
35
36 class JsonObject : public JsonData
37 {
38 friend class JPathNavigator;
39
40 public:
41 JsonObject();
42 void writeJson(const JsonWriterPtr& writer) override;
43 void add(const std::string& key, const JsonDataPtr& value);
44 void add(const std::string& key, const JsonValue& value);
45 void add(const std::string& key, const JsonArray& value);
46 void set(const std::string& key, const JsonDataPtr& value);
47 void set(const std::string& key, const JsonValue& value);
48 bool remove(const std::string& key);
49 JsonDataPtr get(const std::string& key);
50 uint size();
51 void clear();
53 JsonDataPtr clone() override;
54 std::vector<std::string> getKeys() const;
55
56 private:
57 std::vector<std::pair<std::string, JsonDataPtr>> elements;
58 int getKeyIndex(const std::string& key);
59 };
60} // namespace armarx
void add(const std::string &key, const JsonDataPtr &value)
JsonObjectPtr toSharedPtr() const
std::vector< std::string > getKeys() const
void set(const std::string &key, const JsonDataPtr &value)
friend class JPathNavigator
Definition JsonObject.h:38
bool remove(const std::string &key)
void writeJson(const JsonWriterPtr &writer) override
JsonDataPtr get(const std::string &key)
JsonDataPtr clone() override
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< JsonObject > JsonObjectPtr
Definition JsonObject.h:34
std::shared_ptr< JsonData > JsonDataPtr
Definition JsonData.h:31
std::shared_ptr< JsonWriter > JsonWriterPtr
Definition JsonWriter.h:30