JsonArray.cpp
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 #include "JsonArray.h"
22 
24 
25 namespace armarx
26 {
28  {
29  }
30 
31  JsonArray::JsonArray(const std::vector<JsonValue>& values)
32  {
33  for (const JsonValue& v : values)
34  {
35  add(v);
36  }
37  }
38 
39  void JsonArray::writeJson(const JsonWriterPtr& writer)
40  {
41  writer->startArray();
42 
43  for (JsonDataPtr e : elements)
44  {
45  e->writeJson(writer);
46  }
47 
48  writer->endArray();
49  }
50 
51 
53  {
54  elements.push_back(value);
55  }
56 
58  {
59  add(value.toSharedPtr());
60  }
61 
63  {
64  add(value.toSharedPtr());
65  }
66 
68  {
69  elements.at(index) = value;
70  }
71 
72  void JsonArray::set(uint index, const JsonValue& value)
73  {
74  JsonDataPtr valuePtr(new JsonValue(value));
75  set(index, valuePtr);
76  }
77 
79  {
80  if (index >= elements.size())
81  {
82  throw LocalException("Out of range.");
83  }
84 
85  elements.erase(elements.begin() + index);
86  }
87 
89  {
90  return elements.size();
91  }
92 
94  {
95  elements.clear();
96  }
97 
99  {
100  JsonArrayPtr ptr(new JsonArray(*this));
101  return ptr;
102  }
103 
105  {
106  JsonArrayPtr a(new JsonArray);
107  for (const JsonDataPtr& e : elements)
108  {
109  a->add(e->clone());
110  }
111  return a;
112  }
113 }
armarx::JsonArray::JsonArray
JsonArray()
Definition: JsonArray.cpp:27
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::JsonArrayPtr
std::shared_ptr< JsonArray > JsonArrayPtr
Definition: JsonArray.h:32
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::JsonArray
Definition: JsonArray.h:34
armarx::JsonWriterPtr
std::shared_ptr< JsonWriter > JsonWriterPtr
Definition: JsonWriter.h:30
armarx::JsonArray::size
uint size()
Definition: JsonArray.cpp:88
armarx::JsonArray::toSharedPtr
JsonArrayPtr toSharedPtr() const
Definition: JsonArray.cpp:98
JsonArray.h
armarx::JsonValue
Definition: JsonValue.h:34
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::JsonArray::writeJson
void writeJson(const JsonWriterPtr &writer) override
Definition: JsonArray.cpp:39
armarx::JsonArray::add
void add(const JsonDataPtr &value)
Definition: JsonArray.cpp:52
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::JsonArray::remove
void remove(uint index)
Definition: JsonArray.cpp:78
armarx::JsonDataPtr
std::shared_ptr< JsonData > JsonDataPtr
Definition: JsonData.h:31
armarx::JsonArray::clear
void clear()
Definition: JsonArray.cpp:93
armarx::JsonArray::clone
JsonDataPtr clone() override
Definition: JsonArray.cpp:104
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::JsonArray::set
void set(uint index, const JsonDataPtr &value)
Definition: JsonArray.cpp:67
Exception.h