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
41  {
42  writer->startArray();
43 
44  for (JsonDataPtr e : elements)
45  {
46  e->writeJson(writer);
47  }
48 
49  writer->endArray();
50  }
51 
52  void
54  {
55  elements.push_back(value);
56  }
57 
58  void
60  {
61  add(value.toSharedPtr());
62  }
63 
64  void
66  {
67  add(value.toSharedPtr());
68  }
69 
70  void
72  {
73  elements.at(index) = value;
74  }
75 
76  void
78  {
79  JsonDataPtr valuePtr(new JsonValue(value));
80  set(index, valuePtr);
81  }
82 
83  void
85  {
86  if (index >= elements.size())
87  {
88  throw LocalException("Out of range.");
89  }
90 
91  elements.erase(elements.begin() + index);
92  }
93 
94  uint
96  {
97  return elements.size();
98  }
99 
100  void
102  {
103  elements.clear();
104  }
105 
108  {
109  JsonArrayPtr ptr(new JsonArray(*this));
110  return ptr;
111  }
112 
115  {
116  JsonArrayPtr a(new JsonArray);
117  for (const JsonDataPtr& e : elements)
118  {
119  a->add(e->clone());
120  }
121  return a;
122  }
123 } // namespace armarx
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:95
armarx::JsonArray::toSharedPtr
JsonArrayPtr toSharedPtr() const
Definition: JsonArray.cpp:107
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:855
armarx::JsonArray::writeJson
void writeJson(const JsonWriterPtr &writer) override
Definition: JsonArray.cpp:40
armarx::JsonArray::add
void add(const JsonDataPtr &value)
Definition: JsonArray.cpp:53
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:84
armarx::JsonDataPtr
std::shared_ptr< JsonData > JsonDataPtr
Definition: JsonData.h:31
armarx::JsonArray::clear
void clear()
Definition: JsonArray.cpp:101
armarx::JsonArray::clone
JsonDataPtr clone() override
Definition: JsonArray.cpp:114
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::JsonArray::set
void set(uint index, const JsonDataPtr &value)
Definition: JsonArray.cpp:71
Exception.h