Reader.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 Fabian Peller (fabian dot peller 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 // STD/STL
24 #include <memory>
25 #include <optional>
26 #include <string>
27 #include <vector>
28 
29 // ArmarX
32 
33 namespace armarx::aron::data
34 {
35  template <class I>
37  {
38  public:
39  using InputType = I;
40  using InputTypeNonConst = typename std::remove_const<InputType>::type;
41 
42  virtual ~ReaderInterface() = default;
43 
45 
46  virtual void
47  readList(InputType& input, std::vector<InputTypeNonConst>& elements, Path&) = 0;
48  virtual void
49  readDict(InputType& input, std::map<std::string, InputTypeNonConst>& elements, Path&) = 0;
50 
51  virtual void readNDArray(InputType& input,
52  std::vector<int>& shape,
53  std::string& typeAsString,
54  std::vector<unsigned char>& data,
55  Path&) = 0;
56 
57  virtual void readInt(InputType& input, int& i, Path&) = 0;
58  virtual void readLong(InputType& input, long& i, Path&) = 0;
59  virtual void readFloat(InputType& input, float& i, Path&) = 0;
60  virtual void readDouble(InputType& input, double& i, Path&) = 0;
61  virtual void readString(InputType& input, std::string& s, Path&) = 0;
62  virtual void readBool(InputType& input, bool& i, Path&) = 0;
63 
64  virtual bool
65  readNull(InputType& input) // defaulted implementation
66  {
67  InputType nil = {};
68  return (input == nil);
69  }
70 
71  // Convenience methods
72  void
74  {
75  return readInt(input, i, p);
76  }
77 
78  void
80  {
81  return readLong(input, i, p);
82  }
83 
84  void
86  {
87  return readFloat(input, i, p);
88  }
89 
90  void
91  readPrimitive(InputType& input, double& i, Path& p)
92  {
93  return readDouble(input, i, p);
94  }
95 
96  void
97  readPrimitive(InputType& input, std::string& i, Path& p)
98  {
99  return readString(input, i, p);
100  }
101 
102  void
104  {
105  return readBool(input, i, p);
106  }
107 
108  // Convenience methods without path object
109  void
110  readList(InputType& input, std::vector<InputTypeNonConst>& elements)
111  {
112  Path p;
113  return readList(input, elements, p);
114  }
115 
116  void
117  readDict(InputType& input, std::map<std::string, InputTypeNonConst>& elements)
118  {
119  Path p;
120  return readDict(input, elements, p);
121  }
122 
123  void
125  std::vector<int>& shape,
126  std::string& typeAsString,
127  std::vector<unsigned char>& data)
128  {
129  Path p;
130  return readNDArray(input, shape, typeAsString, data, p);
131  }
132 
133  void
135  {
136  Path p;
137  return readInt(input, i, p);
138  }
139 
140  void
142  {
143  Path p;
144  return readLong(input, i, p);
145  }
146 
147  void
149  {
150  Path p;
151  return readFloat(input, i, p);
152  }
153 
154  void
156  {
157  Path p;
158  return readDouble(input, i, p);
159  }
160 
161  void
162  readString(InputType& input, std::string& s)
163  {
164  Path p;
165  return readString(input, s, p);
166  }
167 
168  void
170  {
171  Path p;
172  return readBool(input, i, p);
173  }
174 
175  void
177  {
178  return readInt(input, i);
179  }
180 
181  void
183  {
184  return readLong(input, i);
185  }
186 
187  void
189  {
190  return readFloat(input, i);
191  }
192 
193  void
195  {
196  return readDouble(input, i);
197  }
198 
199  void
200  readPrimitive(InputType& input, std::string& i)
201  {
202  return readString(input, i);
203  }
204 
205  void
207  {
208  return readBool(input, i);
209  }
210  };
211 
212  template <class T>
213  concept isReader = std::is_base_of<ReaderInterface<typename T::InputType>, T>::value;
214 } // namespace armarx::aron::data
armarx::aron::data::ReaderInterface< const data::VariantPtr >::InputTypeNonConst
typename std::remove_const< InputType >::type InputTypeNonConst
Definition: Reader.h:40
Descriptor.h
armarx::aron::data::ReaderInterface::readDict
void readDict(InputType &input, std::map< std::string, InputTypeNonConst > &elements)
Definition: Reader.h:117
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, double &i)
Definition: Reader.h:194
armarx::aron::data::ReaderInterface< const data::VariantPtr >::InputType
const data::VariantPtr InputType
Definition: Reader.h:39
Path.h
armarx::aron::data::ReaderInterface::readBool
void readBool(InputType &input, bool &i)
Definition: Reader.h:169
armarx::aron::data::ReaderInterface::readDict
virtual void readDict(InputType &input, std::map< std::string, InputTypeNonConst > &elements, Path &)=0
armarx::aron::data::Descriptor
Descriptor
Definition: Descriptor.h:179
armarx::aron::data::isReader
concept isReader
Definition: Reader.h:213
armarx::aron::data::ReaderInterface::readInt
virtual void readInt(InputType &input, int &i, Path &)=0
armarx::aron::data::ReaderInterface::readDouble
void readDouble(InputType &input, double &i)
Definition: Reader.h:155
armarx::aron::data::ReaderInterface::~ReaderInterface
virtual ~ReaderInterface()=default
armarx::aron::data::ReaderInterface::readString
void readString(InputType &input, std::string &s)
Definition: Reader.h:162
armarx::aron::data::ReaderInterface::readString
virtual void readString(InputType &input, std::string &s, Path &)=0
armarx::aron::Path
The Path class.
Definition: Path.h:35
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, long &i, Path &p)
Definition: Reader.h:79
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, std::string &i, Path &p)
Definition: Reader.h:97
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, bool &i)
Definition: Reader.h:206
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::aron::data::ReaderInterface::readList
void readList(InputType &input, std::vector< InputTypeNonConst > &elements)
Definition: Reader.h:110
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:12
armarx::aron::data::ReaderInterface::readFloat
virtual void readFloat(InputType &input, float &i, Path &)=0
armarx::aron::data::ReaderInterface::readFloat
void readFloat(InputType &input, float &i)
Definition: Reader.h:148
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, bool &i, Path &p)
Definition: Reader.h:103
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, float &i, Path &p)
Definition: Reader.h:85
armarx::aron::data
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:3
armarx::aron::data::ReaderInterface::getDescriptor
virtual data::Descriptor getDescriptor(InputType &input)=0
armarx::aron::data::ReaderInterface::readNDArray
void readNDArray(InputType &input, std::vector< int > &shape, std::string &typeAsString, std::vector< unsigned char > &data)
Definition: Reader.h:124
armarx::aron::data::ReaderInterface::readNDArray
virtual void readNDArray(InputType &input, std::vector< int > &shape, std::string &typeAsString, std::vector< unsigned char > &data, Path &)=0
armarx::aron::data::ReaderInterface::readNull
virtual bool readNull(InputType &input)
Definition: Reader.h:65
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, int &i, Path &p)
Definition: Reader.h:73
armarx::aron::data::ReaderInterface
Definition: Reader.h:36
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, float &i)
Definition: Reader.h:188
armarx::aron::data::ReaderInterface::readLong
void readLong(InputType &input, long &i)
Definition: Reader.h:141
armarx::aron::data::ReaderInterface::readLong
virtual void readLong(InputType &input, long &i, Path &)=0
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, long &i)
Definition: Reader.h:182
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, double &i, Path &p)
Definition: Reader.h:91
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, int &i)
Definition: Reader.h:176
T
float T
Definition: UnscentedKalmanFilterTest.cpp:38
armarx::aron::data::ReaderInterface::readList
virtual void readList(InputType &input, std::vector< InputTypeNonConst > &elements, Path &)=0
armarx::aron::data::ReaderInterface::readDouble
virtual void readDouble(InputType &input, double &i, Path &)=0
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::aron::data::ReaderInterface::readInt
void readInt(InputType &input, int &i)
Definition: Reader.h:134
armarx::aron::data::ReaderInterface::readBool
virtual void readBool(InputType &input, bool &i, Path &)=0
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, std::string &i)
Definition: Reader.h:200