26 #include "../visitor/Visitor.h"
27 #include "../rw/Reader.h"
28 #include "../rw/Writer.h"
33 template <
class ReaderImplementation,
class WriterImplementation,
class DerivedT>
34 requires isReader<ReaderImplementation> && isWriter<WriterImplementation>
38 concept
isConverter = std::is_base_of<Converter<typename T::ReaderType, typename T::WriterType, typename T::This>,
T>
::value;
40 template <
class ConverterImplementation>
41 requires isConverter<ConverterImplementation>
42 typename ConverterImplementation::WriterReturnType
readAndWrite(
typename ConverterImplementation::ReaderInputType& o);
46 template <
class ReaderImplementation,
class WriterImplementation,
class DerivedT>
47 requires isReader<ReaderImplementation> && isWriter<WriterImplementation>
48 struct Converter :
virtual public Visitor<typename ReaderImplementation::InputType>
57 ReaderImplementation
r;
58 WriterImplementation
w;
65 return r.getDescriptor(o);
70 std::map<std::string, ReaderInputTypeNonConst> elementsOfInput;
71 std::map<std::string, WriterReturnType> elementsReturn;
73 r.readDict(o, elementsOfInput, p);
74 for (
const auto& [key,
value] : elementsOfInput)
76 auto converted = readAndWrite<DerivedT>(
value);
77 elementsReturn.insert({key, converted});
85 std::vector<ReaderInputTypeNonConst> elementsOfInput;
86 std::vector<WriterReturnType> elementsReturn;
88 r.readList(o, elementsOfInput, p);
89 for (
const auto&
value : elementsOfInput)
91 auto converted = readAndWrite<DerivedT>(
value);
92 elementsReturn.push_back(converted);
100 std::vector<int> shape;
101 std::vector<unsigned char>
data;
103 r.readNDArray(o, shape, type,
data, p);
127 r.readFloat(o, i, p);
135 r.readDouble(o, i, p);
151 r.readString(o, i, p);
167 template <
class ConverterImplementation>
168 requires isConverter<ConverterImplementation>
169 typename ConverterImplementation::WriterReturnType
readAndWrite(
typename ConverterImplementation::ReaderInputType& o)
171 ConverterImplementation
v;
173 return v.last_returned;