NlohmannJSONWriter.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 <sstream>
26 #include <stack>
27 
28 // Simox
29 #include <SimoxUtility/json.h>
30 
31 // Base Class
33 
35 {
36  class NlohmannJSONWriter : public WriterInterface<nlohmann::json>
37  {
38  public:
39  NlohmannJSONWriter() = default;
40 
42 
43  ReturnType writeObject(const std::string& name,
44  const std::vector<std::string>& templates,
45  const std::vector<std::string>& templateInstantiations,
46  const std::map<std::string, ReturnType>& memberTypes,
47  const std::optional<ReturnType>& extends,
48  const type::Maybe maybe,
49  const Path& p = Path()) override;
50  ReturnType writeList(const ReturnType& acceptedType,
51  const type::Maybe maybe,
52  const Path& p = Path()) override;
53  ReturnType writeDict(const ReturnType& acceptedType,
54  const type::Maybe maybe,
55  const Path& p = Path()) override;
56  ReturnType writePair(const ReturnType& acceptedType1,
57  const ReturnType& acceptedType2,
58  const type::Maybe maybe,
59  const Path& p = Path()) override;
60  ReturnType writeTuple(const std::vector<ReturnType>& acceptedTypes,
61  const type::Maybe maybe,
62  const Path& p = Path()) override;
63 
64  ReturnType writeNDArray(const int ndim,
66  const std::string& defaultValue,
67  const type::Maybe maybe,
68  const Path& p = Path()) override;
69  ReturnType writeMatrix(const int rows,
70  const int cols,
71  const type::matrix::ElementType type,
72  const std::string& defaultValue,
73  const type::Maybe maybe,
74  const Path& p = Path()) override;
76  const std::string& defaultValue,
77  const type::Maybe maybe,
78  const Path& p = Path()) override;
79  ReturnType writeImage(const type::image::PixelType,
80  const std::string& defaultValue,
81  const type::Maybe maybe,
82  const Path& p = Path()) override;
83  ReturnType writePointCloud(const type::pointcloud::VoxelType,
84  const std::string& defaultValue,
85  const type::Maybe maybe,
86  const Path& p = Path()) override;
87 
88  ReturnType writeIntEnum(const std::string& name,
89  const std::map<std::string, int>& acceptedValues,
90  const std::string& defaultValue,
91  const type::Maybe maybe,
92  const Path& p = Path()) override;
93 
94  ReturnType writeInt(const std::optional<int>& defaultValue,
95  const type::Maybe maybe,
96  const Path& p = Path()) override;
97  ReturnType writeLong(const std::optional<long>& defaultValue,
98  const type::Maybe maybe,
99  const Path& p = Path()) override;
100  ReturnType writeFloat(const std::optional<float>& defaultValue,
101  const type::Maybe maybe,
102  const Path& p = Path()) override;
103  ReturnType writeDouble(const std::optional<double>& defaultValue,
104  const type::Maybe maybe,
105  const Path& p = Path()) override;
106  ReturnType writeString(const std::optional<std::string>& defaultValue,
107  const type::Maybe maybe,
108  const Path& p = Path()) override;
109  ReturnType writeBool(const std::optional<bool>& defaultValue,
110  const type::Maybe maybe,
111  const Path& p = Path()) override;
112 
113  ReturnType writeAnyObject(const type::Maybe maybe, const Path& p = Path()) override;
114  };
115 } // namespace armarx::aron::type::writer
armarx::aron::type::WriterInterface< nlohmann::json >::ReturnType
nlohmann::json ReturnType
Definition: Writer.h:41
armarx::aron::type::writer::NlohmannJSONWriter::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: NlohmannJSONWriter.cpp:165
Writer.h
armarx::aron::type::writer::NlohmannJSONWriter::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: NlohmannJSONWriter.cpp:149
armarx::aron::type::writer::NlohmannJSONWriter::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: NlohmannJSONWriter.cpp:180
armarx::aron::type::WriterInterface
The WriterInterface class.
Definition: Writer.h:38
armarx::aron::type::writer::NlohmannJSONWriter::writeFloat
ReturnType writeFloat(const std::optional< float > &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a float from the params.
Definition: NlohmannJSONWriter.cpp:251
armarx::aron::type::writer::NlohmannJSONWriter::writeDict
ReturnType writeDict(const ReturnType &acceptedType, const type::Maybe maybe, const Path &p=Path()) override
Construct a dict from the params.
armarx::aron::type::writer::NlohmannJSONWriter::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
Construct an object from the params.
Definition: NlohmannJSONWriter.cpp:56
armarx::aron::type::writer::NlohmannJSONWriter::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: NlohmannJSONWriter.cpp:275
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::type::writer::NlohmannJSONWriter::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: NlohmannJSONWriter.cpp:193
armarx::aron::type::WriterInterface< nlohmann::json >::ReturnTypeConst
typename std::add_const< ReturnType >::type ReturnTypeConst
Definition: Writer.h:42
armarx::aron::type::writer::NlohmannJSONWriter::getDescriptor
type::Descriptor getDescriptor(ReturnTypeConst &input) final
Definition: NlohmannJSONWriter.cpp:50
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::aron::type::writer::NlohmannJSONWriter::writeAnyObject
ReturnType writeAnyObject(const type::Maybe maybe, const Path &p=Path()) override
Construct a time from the params.
Definition: NlohmannJSONWriter.cpp:298
armarx::aron::type::writer::NlohmannJSONWriter::writeDouble
ReturnType writeDouble(const std::optional< double > &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a double from the params.
Definition: NlohmannJSONWriter.cpp:263
armarx::aron::type::writer::NlohmannJSONWriter::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: NlohmannJSONWriter.cpp:207
armarx::aron::type::writer::NlohmannJSONWriter::writeList
ReturnType writeList(const ReturnType &acceptedType, const type::Maybe maybe, const Path &p=Path()) override
Construct a list from the params.
armarx::ElementTypes::ElementType
ElementType
Definition: AbstractObjectSerializer.h:32
armarx::aron::type::writer::NlohmannJSONWriter::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: NlohmannJSONWriter.cpp:134
armarx::aron::type::writer::NlohmannJSONWriter::writeInt
ReturnType writeInt(const std::optional< int > &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a int from the params.
Definition: NlohmannJSONWriter.cpp:227
armarx::aron::type::writer::NlohmannJSONWriter::writeTuple
ReturnType writeTuple(const std::vector< ReturnType > &acceptedTypes, const type::Maybe maybe, const Path &p=Path()) override
Construct a tuple from the params.
Definition: NlohmannJSONWriter.cpp:123
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
armarx::aron::type::writer::NlohmannJSONWriter
Definition: NlohmannJSONWriter.h:36
armarx::aron::type::writer
Definition: NlohmannJSONWriter.cpp:32
armarx::aron::type::writer::NlohmannJSONWriter::writeLong
ReturnType writeLong(const std::optional< long > &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a long from the params.
Definition: NlohmannJSONWriter.cpp:239
armarx::aron::type::Descriptor
Descriptor
Definition: Descriptor.h:76
armarx::aron::type::writer::NlohmannJSONWriter::NlohmannJSONWriter
NlohmannJSONWriter()=default
armarx::aron::type::writer::NlohmannJSONWriter::writeBool
ReturnType writeBool(const std::optional< bool > &defaultValue, const type::Maybe maybe, const Path &p=Path()) override
Construct a bool from the params.
Definition: NlohmannJSONWriter.cpp:286
armarx::aron::type::writer::NlohmannJSONWriter::writePair
ReturnType writePair(const ReturnType &acceptedType1, const ReturnType &acceptedType2, const type::Maybe maybe, const Path &p=Path()) override
Construct a pair from the params.
Definition: NlohmannJSONWriter.cpp:111