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 <string>
26 #include <vector>
27 #include <optional>
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 readList(InputType& input, std::vector<InputTypeNonConst>& elements, Path&) = 0;
47  virtual void readDict(InputType& input, std::map<std::string, InputTypeNonConst>& elements, Path&) = 0;
48 
49  virtual void readNDArray(InputType& input, std::vector<int>& shape, std::string& typeAsString, std::vector<unsigned char>& data, Path&) = 0;
50 
51  virtual void readInt(InputType& input, int& i, Path&) = 0;
52  virtual void readLong(InputType& input, long& i, Path&) = 0;
53  virtual void readFloat(InputType& input, float& i, Path&) = 0;
54  virtual void readDouble(InputType& input, double& i, Path&) = 0;
55  virtual void readString(InputType& input, std::string& s, Path&) = 0;
56  virtual void readBool(InputType& input, bool& i, Path&) = 0;
57 
58  virtual bool readNull(InputType& input) // defaulted implementation
59  {
60  InputType nil = {};
61  return (input == nil);
62  }
63 
64  // Convenience methods
65  void readPrimitive(InputType& input, int& i, Path& p)
66  {
67  return readInt(input, i, p);
68  }
69 
70  void readPrimitive(InputType& input, long& i, Path& p)
71  {
72  return readLong(input, i, p);
73  }
74 
75  void readPrimitive(InputType& input, float& i, Path& p)
76  {
77  return readFloat(input, i, p);
78  }
79 
80  void readPrimitive(InputType& input, double& i, Path& p)
81  {
82  return readDouble(input, i, p);
83  }
84 
85  void readPrimitive(InputType& input, std::string& i, Path& p)
86  {
87  return readString(input, i, p);
88  }
89 
90  void readPrimitive(InputType& input, bool& i, Path& p)
91  {
92  return readBool(input, i, p);
93  }
94 
95  // Convenience methods without path object
96  void readList(InputType& input, std::vector<InputTypeNonConst>& elements)
97  {
98  Path p;
99  return readList(input, elements, p);
100  }
101 
102  void readDict(InputType& input, std::map<std::string, InputTypeNonConst>& elements)
103  {
104  Path p;
105  return readDict(input, elements, p);
106  }
107 
108  void readNDArray(InputType& input, std::vector<int>& shape, std::string& typeAsString, std::vector<unsigned char>& data)
109  {
110  Path p;
111  return readNDArray(input, shape, typeAsString, data, p);
112  }
113 
114  void readInt(InputType& input, int& i)
115  {
116  Path p;
117  return readInt(input, i, p);
118  }
119 
120  void readLong(InputType& input, long& i)
121  {
122  Path p;
123  return readLong(input, i, p);
124  }
125 
126  void readFloat(InputType& input, float& i)
127  {
128  Path p;
129  return readFloat(input, i, p);
130  }
131 
132  void readDouble(InputType& input, double& i)
133  {
134  Path p;
135  return readDouble(input, i, p);
136  }
137 
138  void readString(InputType& input, std::string& s)
139  {
140  Path p;
141  return readString(input, s, p);
142  }
143 
144  void readBool(InputType& input, bool& i)
145  {
146  Path p;
147  return readBool(input, i, p);
148  }
149 
151  {
152  return readInt(input, i);
153  }
154 
155  void readPrimitive(InputType& input, long& i)
156  {
157  return readLong(input, i);
158  }
159 
160  void readPrimitive(InputType& input, float& i)
161  {
162  return readFloat(input, i);
163  }
164 
165  void readPrimitive(InputType& input, double& i)
166  {
167  return readDouble(input, i);
168  }
169 
170  void readPrimitive(InputType& input, std::string& i)
171  {
172  return readString(input, i);
173  }
174 
175  void readPrimitive(InputType& input, bool& i)
176  {
177  return readBool(input, i);
178  }
179 
180 
181  };
182 
183  template <class T>
184  concept isReader = std::is_base_of<ReaderInterface<typename T::InputType>, T>::value;
185 }
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:102
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, double &i)
Definition: Reader.h:165
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:144
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:193
armarx::aron::data::isReader
concept isReader
Definition: Reader.h:184
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:132
armarx::aron::data::ReaderInterface::~ReaderInterface
virtual ~ReaderInterface()=default
armarx::aron::data::ReaderInterface::readString
void readString(InputType &input, std::string &s)
Definition: Reader.h:138
armarx::aron::data::ReaderInterface::readString
virtual void readString(InputType &input, std::string &s, Path &)=0
armarx::aron::Path
The Path class.
Definition: Path.h:36
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, long &i, Path &p)
Definition: Reader.h:70
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, std::string &i, Path &p)
Definition: Reader.h:85
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, bool &i)
Definition: Reader.h:175
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:96
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
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:126
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, bool &i, Path &p)
Definition: Reader.h:90
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, float &i, Path &p)
Definition: Reader.h:75
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:108
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:58
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, int &i, Path &p)
Definition: Reader.h:65
armarx::aron::data::ReaderInterface
Definition: Reader.h:36
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, float &i)
Definition: Reader.h:160
armarx::aron::data::ReaderInterface::readLong
void readLong(InputType &input, long &i)
Definition: Reader.h:120
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:155
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, double &i, Path &p)
Definition: Reader.h:80
armarx::aron::data::ReaderInterface::readPrimitive
void readPrimitive(InputType &input, int &i)
Definition: Reader.h:150
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
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:114
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:170