Writer.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 
28 // ArmarX
29 #include <RobotAPI/interface/aron.h>
31 
32 namespace armarx::aron::type
33 {
34  /**
35  * @brief The WriterInterface class. It defines the interface to construct aron representations (e.g. variant or nlohmann::json)
36  */
37  template <class R>
39  {
40  public:
41  using ReturnType = R;
42  using ReturnTypeConst = typename std::add_const<ReturnType>::type;
43 
44  virtual ~WriterInterface() = default;
45 
47 
48  /// Construct an object from the params
49  virtual ReturnType writeObject(const std::string& name,
50  const std::vector<std::string>& templates,
51  const std::vector<std::string>& templateInstantiations,
52  const std::map<std::string, ReturnType>& memberTypes,
53  const std::optional<ReturnType>& extends,
54  const type::Maybe maybe,
55  const Path& p) = 0;
56 
57  /// Construct a list from the params
58  virtual ReturnType
59  writeList(const ReturnType& acceptedType, const type::Maybe maybe, const Path& p) = 0;
60 
61  /// Construct a dict from the params
62  virtual ReturnType
63  writeDict(const ReturnType& acceptedType, const type::Maybe maybe, const Path& p) = 0;
64 
65  /// Construct a pair from the params
66  virtual ReturnType writePair(const ReturnType& acceptedType1,
67  const ReturnType& acceptedType2,
68  const type::Maybe maybe,
69  const Path& p) = 0;
70 
71  /// Construct a tuple from the params
72  virtual ReturnType writeTuple(const std::vector<ReturnType>& acceptedTypes,
73  const type::Maybe maybe,
74  const Path& p) = 0;
75 
76  /// Construct a ndarray from the params
77  virtual ReturnType writeNDArray(const int ndim,
78  const type::ndarray::ElementType type,
79  const std::string& defaultValue,
80  const type::Maybe maybe,
81  const Path& p) = 0;
82 
83  /// Construct a matrix from the params
84  virtual ReturnType writeMatrix(const int rows,
85  const int cols,
86  const type::matrix::ElementType type,
87  const std::string& defaultValue,
88  const type::Maybe maybe,
89  const Path& p) = 0;
90 
91  /// Construct a quaternion from the params
93  const std::string& defaultValue,
94  const type::Maybe maybe,
95  const Path& p) = 0;
96 
97  /// Construct a image from the params
98  virtual ReturnType writeImage(const type::image::PixelType type,
99  const std::string& defaultValue,
100  const type::Maybe maybe,
101  const Path& p) = 0;
102 
103  /// Construct a pointcloud from the params
104  virtual ReturnType writePointCloud(const type::pointcloud::VoxelType,
105  const std::string& defaultValue,
106  const type::Maybe maybe,
107  const Path& p) = 0;
108 
109  /// Construct a int enum from the params
110  virtual ReturnType writeIntEnum(const std::string& name,
111  const std::map<std::string, int>& acceptedValues,
112  const std::string& defaultValue,
113  const type::Maybe maybe,
114  const Path& p) = 0;
115 
116  /// Construct a int from the params
117  virtual ReturnType writeInt(const std::optional<int>& defaultValue,
118  const type::Maybe maybe,
119  const Path& p) = 0;
120 
121  /// Construct a long from the params
122  virtual ReturnType writeLong(const std::optional<long>& defaultValue,
123  const type::Maybe maybe,
124  const Path& p) = 0;
125 
126  /// Construct a float from the params
127  virtual ReturnType writeFloat(const std::optional<float>& defaultValue,
128  const type::Maybe maybe,
129  const Path& p) = 0;
130 
131  /// Construct a double from the params
132  virtual ReturnType writeDouble(const std::optional<double>& defaultValue,
133  const type::Maybe maybe,
134  const Path& p) = 0;
135 
136  /// Construct a string from the params
137  virtual ReturnType writeString(const std::optional<std::string>& defaultValue,
138  const type::Maybe maybe,
139  const Path& p) = 0;
140 
141  /// Construct a bool from the params
142  virtual ReturnType writeBool(const std::optional<bool>& defaultValue,
143  const type::Maybe maybe,
144  const Path& p) = 0;
145 
146  /// Construct a time from the params
147  virtual ReturnType writeAnyObject(const type::Maybe maybe, const Path& p) = 0;
148 
149  /// write a null
150  virtual ReturnType
151  writeNull(const Path& p = Path()) // defaulted implementation
152  {
153  (void)p;
154  return {};
155  }
156  };
157 
158  template <class T>
159  concept isWriter = std::is_base_of<WriterInterface<typename T::ReturnType>, T>::value;
160 } // namespace armarx::aron::type
armarx::aron::type::WriterInterface< nlohmann::json >::ReturnType
nlohmann::json ReturnType
Definition: Writer.h:41
armarx::aron::type::WriterInterface::writeLong
virtual ReturnType writeLong(const std::optional< long > &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a long from the params.
armarx::aron::type::WriterInterface::writeNull
virtual ReturnType writeNull(const Path &p=Path())
write a null
Definition: Writer.h:151
armarx::aron::type::WriterInterface::writeImage
virtual ReturnType writeImage(const type::image::PixelType type, const std::string &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a image from the params.
armarx::aron::type::WriterInterface
The WriterInterface class.
Definition: Writer.h:38
armarx::aron::type::WriterInterface::writeNDArray
virtual ReturnType writeNDArray(const int ndim, const type::ndarray::ElementType type, const std::string &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a ndarray from the params.
armarx::aron::type::WriterInterface::writeTuple
virtual ReturnType writeTuple(const std::vector< ReturnType > &acceptedTypes, const type::Maybe maybe, const Path &p)=0
Construct a tuple from the params.
armarx::aron::type::WriterInterface::writeDict
virtual ReturnType writeDict(const ReturnType &acceptedType, const type::Maybe maybe, const Path &p)=0
Construct a dict from the params.
armarx::aron::type::WriterInterface::writePointCloud
virtual ReturnType writePointCloud(const type::pointcloud::VoxelType, const std::string &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a pointcloud from the params.
armarx::aron::type::WriterInterface::writeDouble
virtual ReturnType writeDouble(const std::optional< double > &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a double from the params.
armarx::aron::Path
The Path class.
Definition: Path.h:36
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::aron::type::WriterInterface< nlohmann::json >::ReturnTypeConst
typename std::add_const< ReturnType >::type ReturnTypeConst
Definition: Writer.h:42
armarx::aron::type::WriterInterface::writePair
virtual ReturnType writePair(const ReturnType &acceptedType1, const ReturnType &acceptedType2, const type::Maybe maybe, const Path &p)=0
Construct a pair from the params.
armarx::aron::type::WriterInterface::getDescriptor
virtual type::Descriptor getDescriptor(ReturnTypeConst &input)=0
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::aron::type::isWriter
concept isWriter
Definition: Writer.h:159
armarx::aron::type::WriterInterface::writeMatrix
virtual ReturnType writeMatrix(const int rows, const int cols, const type::matrix::ElementType type, const std::string &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a matrix from the params.
armarx::aron::type
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:9
armarx::aron::type::WriterInterface::writeObject
virtual 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)=0
Construct an object from the params.
armarx::ElementTypes::ElementType
ElementType
Definition: AbstractObjectSerializer.h:32
armarx::aron::type::WriterInterface::writeFloat
virtual ReturnType writeFloat(const std::optional< float > &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a float from the params.
armarx::aron::type::WriterInterface::writeString
virtual ReturnType writeString(const std::optional< std::string > &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a string from the params.
armarx::aron::type::WriterInterface::writeAnyObject
virtual ReturnType writeAnyObject(const type::Maybe maybe, const Path &p)=0
Construct a time from the params.
Exception.h
armarx::aron::type::WriterInterface::writeBool
virtual ReturnType writeBool(const std::optional< bool > &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a bool from the params.
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
armarx::aron::type::WriterInterface::writeQuaternion
virtual ReturnType writeQuaternion(const type::quaternion::ElementType type, const std::string &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a quaternion from the params.
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::aron::type::WriterInterface::~WriterInterface
virtual ~WriterInterface()=default
armarx::aron::type::WriterInterface::writeList
virtual ReturnType writeList(const ReturnType &acceptedType, const type::Maybe maybe, const Path &p)=0
Construct a list from the params.
armarx::aron::type::Descriptor
Descriptor
Definition: Descriptor.h:76
armarx::aron::type::WriterInterface::writeIntEnum
virtual ReturnType writeIntEnum(const std::string &name, const std::map< std::string, int > &acceptedValues, const std::string &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a int enum from the params.
armarx::aron::type::WriterInterface::writeInt
virtual ReturnType writeInt(const std::optional< int > &defaultValue, const type::Maybe maybe, const Path &p)=0
Construct a int from the params.