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