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 "JsonArray.h"
24 #include "JsonData.h"
25 #include "JsonValue.h"
26 
27 #include <memory>
28 #include <vector>
29 #include <utility>
30 
31 namespace 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();
52  JsonObjectPtr toSharedPtr() const;
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 }
61 
JsonData.h
armarx::JsonObject::size
uint size()
Definition: JsonObject.cpp:111
armarx::JsonObject::getKeys
std::vector< std::string > getKeys() const
Definition: JsonObject.cpp:137
armarx::JsonObject::writeJson
void writeJson(const JsonWriterPtr &writer) override
Definition: JsonObject.cpp:31
armarx::JsonObject::set
void set(const std::string &key, const JsonDataPtr &value)
Definition: JsonObject.cpp:65
armarx::JsonArray
Definition: JsonArray.h:34
armarx::JsonWriterPtr
std::shared_ptr< JsonWriter > JsonWriterPtr
Definition: JsonWriter.h:30
armarx::JsonObject::clear
void clear()
Definition: JsonObject.cpp:116
armarx::JsonObject::get
JsonDataPtr get(const std::string &key)
Definition: JsonObject.cpp:97
armarx::JsonObject::add
void add(const std::string &key, const JsonDataPtr &value)
Definition: JsonObject.cpp:45
armarx::JPathNavigator
Definition: JPathNavigator.h:35
JsonArray.h
armarx::JsonValue
Definition: JsonValue.h:34
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
JsonValue.h
armarx::JsonData
Definition: JsonData.h:33
armarx::JsonObject::remove
bool remove(const std::string &key)
Definition: JsonObject.cpp:85
armarx::JsonObject::toSharedPtr
JsonObjectPtr toSharedPtr() const
Definition: JsonObject.cpp:121
armarx::JsonObject
Definition: JsonObject.h:36
armarx::JsonObject::JsonObject
JsonObject()
Definition: JsonObject.cpp:27
armarx::JsonDataPtr
std::shared_ptr< JsonData > JsonDataPtr
Definition: JsonData.h:31
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::JsonObject::clone
JsonDataPtr clone() override
Definition: JsonObject.cpp:127
armarx::JsonObjectPtr
std::shared_ptr< JsonObject > JsonObjectPtr
Definition: JsonObject.h:34