VariantWriter.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 #include <memory>
24 #include <stack>
25 
28 
30 {
31  class VariantWriter : public type::WriterInterface<aron::type::VariantPtr>
32  {
33  public:
34  VariantWriter() = default;
35 
37 
38  ReturnType writeObject(const std::string& name,
39  const std::vector<std::string>& templates,
40  const std::vector<std::string>& templateInstantiations,
41  const std::map<std::string, ReturnType>& memberTypes,
42  const std::optional<ReturnType>& extends,
43  const type::Maybe maybe,
44  const Path& p = Path()) override;
45  ReturnType writeList(const ReturnType& acceptedType,
46  const type::Maybe maybe,
47  const Path& p = Path()) override;
48  ReturnType writeDict(const ReturnType& acceptedType,
49  const type::Maybe maybe,
50  const Path& p = Path()) override;
51  ReturnType writePair(const ReturnType& acceptedType1,
52  const ReturnType& acceptedType2,
53  const type::Maybe maybe,
54  const Path& p = Path()) override;
55  ReturnType writeTuple(const std::vector<ReturnType>& acceptedTypes,
56  const type::Maybe maybe,
57  const Path& p = Path()) override;
58 
59  ReturnType writeNDArray(const int ndim,
61  const std::string& defaultValue,
62  const type::Maybe maybe,
63  const Path& p = Path()) override;
64  ReturnType writeMatrix(const int rows,
65  const int cols,
66  const type::matrix::ElementType type,
67  const std::string& defaultValue,
68  const type::Maybe maybe,
69  const Path& p = Path()) override;
71  const std::string& defaultValue,
72  const type::Maybe maybe,
73  const Path& p = Path()) override;
74  ReturnType writeImage(const type::image::PixelType,
75  const std::string& defaultValue,
76  const type::Maybe maybe,
77  const Path& p = Path()) override;
78  ReturnType writePointCloud(const type::pointcloud::VoxelType,
79  const std::string& defaultValue,
80  const type::Maybe maybe,
81  const Path& p = Path()) override;
82 
83  ReturnType writeIntEnum(const std::string& name,
84  const std::map<std::string, int>& acceptedValues,
85  const std::string& defaultValue,
86  const type::Maybe maybe,
87  const Path& p = Path()) override;
88 
89  ReturnType writeInt(const std::optional<int>& defaultValue,
90  const type::Maybe maybe,
91  const Path& p = Path()) override;
92  ReturnType writeLong(const std::optional<long>& defaultValue,
93  const type::Maybe maybe,
94  const Path& p = Path()) override;
95  ReturnType writeFloat(const std::optional<float>& defaultValue,
96  const type::Maybe maybe,
97  const Path& p = Path()) override;
98  ReturnType writeDouble(const std::optional<double>& defaultValue,
99  const type::Maybe maybe,
100  const Path& p = Path()) override;
101  ReturnType writeString(const std::optional<std::string>& defaultValue,
102  const type::Maybe maybe,
103  const Path& p = Path()) override;
104  ReturnType writeBool(const std::optional<bool>& defaultValue,
105  const type::Maybe maybe,
106  const Path& p = Path()) override;
107 
108  ReturnType writeAnyObject(const type::Maybe maybe, const Path& p = Path()) override;
109  };
110 } // namespace armarx::aron::type::writer
armarx::aron::type::writer::VariantWriter::writeInt
ReturnType writeInt(const std::optional< int > &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a int from the params.
Definition: VariantWriter.cpp:193
armarx::aron::type::WriterInterface< aron::type::VariantPtr >::ReturnType
aron::type::VariantPtr ReturnType
Definition: Writer.h:41
armarx::aron::type::writer::VariantWriter::writePointCloud
ReturnType writePointCloud(const type::pointcloud::VoxelType, const std::string &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a pointcloud from the params.
Definition: VariantWriter.cpp:165
armarx::aron::type::writer::VariantWriter
Definition: VariantWriter.h:31
Writer.h
armarx::aron::type::writer::VariantWriter::getDescriptor
type::Descriptor getDescriptor(ReturnTypeConst &input) final
Definition: VariantWriter.cpp:33
armarx::aron::type::writer::VariantWriter::writeList
ReturnType writeList(const ReturnType &acceptedType, const type::Maybe maybe, const Path &p=Path()) override
armarx::aron::type::writer::VariantWriter::writeFloat
ReturnType writeFloat(const std::optional< float > &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a float from the params.
Definition: VariantWriter.cpp:215
armarx::aron::type::WriterInterface
The WriterInterface class.
Definition: Writer.h:38
armarx::aron::type::writer::VariantWriter::writeBool
ReturnType writeBool(const std::optional< bool > &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a bool from the params.
Definition: VariantWriter.cpp:248
armarx::aron::type::writer::VariantWriter::writeQuaternion
ReturnType writeQuaternion(const type::quaternion::ElementType, const std::string &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a quaternion from the params.
Definition: VariantWriter.cpp:139
armarx::aron::type::writer::VariantWriter::writeString
ReturnType writeString(const std::optional< std::string > &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a string from the params.
Definition: VariantWriter.cpp:237
armarx::aron::Path
The Path class.
Definition: Path.h:36
Variant.h
armarx::aron::type::writer::VariantWriter::writeObject
ReturnType writeObject(const std::string &name, const std::vector< std::string > &templates, const std::vector< std::string > &templateInstantiations, const std::map< std::string, ReturnType > &memberTypes, const std::optional< ReturnType > &extends, const type::Maybe maybe, const Path &p=Path()) override
Definition: VariantWriter.cpp:39
armarx::aron::type::WriterInterface< aron::type::VariantPtr >::ReturnTypeConst
typename std::add_const< ReturnType >::type ReturnTypeConst
Definition: Writer.h:42
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::ElementTypes::ElementType
ElementType
Definition: AbstractObjectSerializer.h:32
armarx::aron::type::writer::VariantWriter::VariantWriter
VariantWriter()=default
armarx::aron::type::writer::VariantWriter::writeDouble
ReturnType writeDouble(const std::optional< double > &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a double from the params.
Definition: VariantWriter.cpp:226
armarx::aron::type::writer::VariantWriter::writeDict
ReturnType writeDict(const ReturnType &acceptedType, const type::Maybe maybe, const Path &p=Path()) override
armarx::aron::type::writer::VariantWriter::writeMatrix
ReturnType writeMatrix(const int rows, const int cols, const type::matrix::ElementType type, const std::string &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a matrix from the params.
Definition: VariantWriter.cpp:122
armarx::aron::type::writer::VariantWriter::writeAnyObject
ReturnType writeAnyObject(const type::Maybe maybe, const Path &p=Path()) override
Construct a time from the params.
Definition: VariantWriter.cpp:259
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
armarx::aron::type::writer::VariantWriter::writeLong
ReturnType writeLong(const std::optional< long > &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a long from the params.
Definition: VariantWriter.cpp:204
armarx::aron::type::writer
Definition: NlohmannJSONWriter.cpp:32
armarx::aron::type::writer::VariantWriter::writeIntEnum
ReturnType writeIntEnum(const std::string &name, const std::map< std::string, int > &acceptedValues, const std::string &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a int enum from the params.
Definition: VariantWriter.cpp:178
armarx::aron::type::Descriptor
Descriptor
Definition: Descriptor.h:76
armarx::aron::type::writer::VariantWriter::writePair
ReturnType writePair(const ReturnType &acceptedType1, const ReturnType &acceptedType2, const type::Maybe maybe, const Path &p=Path()) override
Definition: VariantWriter.cpp:84
armarx::aron::type::writer::VariantWriter::writeNDArray
ReturnType writeNDArray(const int ndim, const type::ndarray::ElementType, const std::string &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a ndarray from the params.
Definition: VariantWriter.cpp:108
armarx::aron::type::writer::VariantWriter::writeTuple
ReturnType writeTuple(const std::vector< ReturnType > &acceptedTypes, const type::Maybe maybe, const Path &p=Path()) override
Definition: VariantWriter.cpp:97
armarx::aron::type::writer::VariantWriter::writeImage
ReturnType writeImage(const type::image::PixelType, const std::string &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a image from the params.
Definition: VariantWriter.cpp:152