26 #include "../rw/Reader.h"
27 #include "../rw/Writer.h"
28 #include "../visitor/Visitor.h"
33 template <
class ReaderImplementation,
class WriterImplementation,
class DerivedT>
34 requires isReader<ReaderImplementation> && isWriter<WriterImplementation>
39 std::is_base_of<Converter<typename T::ReaderType, typename T::WriterType, typename T::This>,
42 template <
class ConverterImplementation>
43 requires isConverter<ConverterImplementation>
44 typename ConverterImplementation::WriterReturnType
45 readAndWrite(
typename ConverterImplementation::ReaderInputType& o);
49 template <
class ReaderImplementation,
class WriterImplementation,
class DerivedT>
50 requires isReader<ReaderImplementation> && isWriter<WriterImplementation>
52 struct Converter :
virtual public Visitor<typename ReaderImplementation::InputType>
61 ReaderImplementation
r;
62 WriterImplementation
w;
70 return r.getDescriptor(o);
78 std::map<std::string, ReaderInputTypeNonConst> elementsOfInput;
80 std::vector<std::string> templates;
81 std::vector<std::string> templateInstantiations;
83 std::map<std::string, WriterReturnType> elementsReturn;
85 r.readObject(o, name, templates, templateInstantiations, elementsOfInput, maybe, p);
86 for (
const auto& [key,
value] : elementsOfInput)
88 auto converted = readAndWrite<DerivedT>(
value);
89 elementsReturn.insert({key, converted});
93 name, templates, templateInstantiations, elementsReturn, std::nullopt, maybe, p);
104 r.readDict(o, acceptedType, maybe, p);
106 auto converted = readAndWrite<DerivedT>(acceptedType);
119 r.readList(o, acceptedType, maybe, p);
121 auto converted = readAndWrite<DerivedT>(acceptedType);
135 r.readPair(o, acceptedType1, acceptedType2, maybe, p);
137 auto converted1 = readAndWrite<DerivedT>(acceptedType1);
138 auto converted2 = readAndWrite<DerivedT>(acceptedType2);
148 std::vector<ReaderInputTypeNonConst> acceptedTypes;
149 std::vector<WriterReturnType> elementsReturn;
152 r.readTuple(o, acceptedTypes, maybe, p);
154 for (
const auto& el : acceptedTypes)
156 auto converted = readAndWrite<DerivedT>(el);
157 elementsReturn.push_back(converted);
170 std::string defaultValue;
173 r.readNDArray(o, ndim, type, defaultValue, maybe, p);
174 last_returned =
w.writeNDArray(ndim, type, defaultValue, maybe, p);
184 std::string defaultValue;
188 r.readMatrix(o, rows, cols, type, defaultValue, maybe, p);
189 last_returned =
w.writeMatrix(rows, cols, type, defaultValue, maybe, p);
199 std::string defaultValue;
201 r.readQuaternion(o, type, defaultValue, maybe, p);
211 type::image::PixelType type;
212 std::string defaultValue;
214 r.readImage(o, type, defaultValue, maybe, p);
224 type::pointcloud::VoxelType type;
225 std::string defaultValue;
227 r.readPointCloud(o, type, defaultValue, maybe, p);
238 std::map<std::string, int>
values;
239 std::string defaultValue;
241 r.readIntEnum(o, name,
values, defaultValue, maybe, p);
252 std::optional<int> defaultValue;
253 r.readInt(o, defaultValue, maybe, p);
264 std::optional<long> defaultValue;
265 r.readLong(o, defaultValue, maybe, p);
276 std::optional<float> defaultValue;
277 r.readFloat(o, defaultValue, maybe, p);
288 std::optional<double> defaultValue;
289 r.readDouble(o, defaultValue, maybe, p);
300 std::optional<bool> defaultValue;
301 r.readBool(o, defaultValue, maybe, p);
312 std::optional<std::string> defaultValue;
313 r.readString(o, defaultValue, maybe, p);
325 "A visitor got type but the enum is unknown.");
333 template <
class ConverterImplementation>
334 requires isConverter<ConverterImplementation>
336 typename ConverterImplementation::WriterReturnType
339 ConverterImplementation
v;
341 return v.last_returned;