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 <string>
26 #include <optional>
27 
28 // ArmarX
29 #include <RobotAPI/interface/aron.h>
31 
32 // Known types
34 
35 namespace armarx::aron::data
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  virtual ReturnType writeList(const std::vector<ReturnType>& elements, const Path& p) = 0;
49  virtual ReturnType writeDict(const std::map<std::string, ReturnType>& elements, const std::optional<ReturnType>& extends, const Path& p) = 0;
50 
51  virtual ReturnType writeNDArray(const std::vector<int>& shape, const std::string& typeAsString, const unsigned char* data, const Path& p) = 0;
52 
53  virtual ReturnType writeInt(const int i, const Path& p) = 0;
54  virtual ReturnType writeLong(const long i, const Path& p) = 0;
55  virtual ReturnType writeFloat(const float i, const Path& p) = 0;
56  virtual ReturnType writeDouble(const double i, const Path& p) = 0;
57  virtual ReturnType writeString(const std::string& i, const Path& p) = 0;
58  virtual ReturnType writeBool(const bool i, const Path& p) = 0;
59 
60  virtual ReturnType writeNull() // defaulted implementation
61  {
62  return {};
63  }
64 
65  // Convenience methods
66  ReturnType writePrimitive(const int i, const Path& p = Path())
67  {
68  return writeInt(i, p);
69  }
70 
71  ReturnType writePrimitive(const long i, const Path& p = Path())
72  {
73  return writeLong(i, p);
74  }
75 
76  ReturnType writePrimitive(const float i, const Path& p = Path())
77  {
78  return writeFloat(i, p);
79  }
80 
81  ReturnType writePrimitive(const double i, const Path& p = Path())
82  {
83  return writeDouble(i, p);
84  }
85 
86  ReturnType writePrimitive(const std::string& i, const Path& p = Path())
87  {
88  return writeString(i, p);
89  }
90 
91  ReturnType writePrimitive(const bool i, const Path& p = Path())
92  {
93  return writeBool(i, p);
94  }
95  };
96 
97  template <class T>
98  concept isWriter = std::is_base_of<WriterInterface<typename T::ReturnType>, T>::value;
99 }
armarx::aron::data::WriterInterface< data::VariantPtr >::ReturnType
data::VariantPtr ReturnType
Definition: Writer.h:41
armarx::aron::data::WriterInterface::writeInt
virtual ReturnType writeInt(const int i, const Path &p)=0
armarx::aron::data::WriterInterface::writeList
virtual ReturnType writeList(const std::vector< ReturnType > &elements, const Path &p)=0
armarx::aron::data::WriterInterface::writeLong
virtual ReturnType writeLong(const long i, const Path &p)=0
armarx::aron::data::WriterInterface::writeNDArray
virtual ReturnType writeNDArray(const std::vector< int > &shape, const std::string &typeAsString, const unsigned char *data, const Path &p)=0
armarx::aron::data::WriterInterface::writeDouble
virtual ReturnType writeDouble(const double i, const Path &p)=0
armarx::aron::data::Descriptor
Descriptor
Definition: Descriptor.h:193
armarx::aron::data::WriterInterface::writeNull
virtual ReturnType writeNull()
Definition: Writer.h:60
armarx::aron::data::WriterInterface::~WriterInterface
virtual ~WriterInterface()=default
armarx::aron::data::WriterInterface::writePrimitive
ReturnType writePrimitive(const int i, const Path &p=Path())
Definition: Writer.h:66
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::data::WriterInterface::writeString
virtual ReturnType writeString(const std::string &i, const Path &p)=0
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::aron::data::WriterInterface::getDescriptor
virtual data::Descriptor getDescriptor(ReturnTypeConst &input)=0
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
forward_declarations.h
armarx::aron::data
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:3
armarx::aron::data::WriterInterface::writePrimitive
ReturnType writePrimitive(const long i, const Path &p=Path())
Definition: Writer.h:71
armarx::aron::data::WriterInterface::writeBool
virtual ReturnType writeBool(const bool i, const Path &p)=0
Exception.h
armarx::aron::data::WriterInterface::writeDict
virtual ReturnType writeDict(const std::map< std::string, ReturnType > &elements, const std::optional< ReturnType > &extends, const Path &p)=0
armarx::aron::data::WriterInterface< data::VariantPtr >::ReturnTypeConst
typename std::add_const< ReturnType >::type ReturnTypeConst
Definition: Writer.h:42
armarx::aron::data::WriterInterface::writePrimitive
ReturnType writePrimitive(const double i, const Path &p=Path())
Definition: Writer.h:81
armarx::aron::data::isWriter
concept isWriter
Definition: Writer.h:98
armarx::aron::data::WriterInterface::writePrimitive
ReturnType writePrimitive(const std::string &i, const Path &p=Path())
Definition: Writer.h:86
armarx::aron::data::WriterInterface::writeFloat
virtual ReturnType writeFloat(const float i, const Path &p)=0
armarx::aron::data::WriterInterface::writePrimitive
ReturnType writePrimitive(const bool i, const Path &p=Path())
Definition: Writer.h:91
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::aron::data::WriterInterface::writePrimitive
ReturnType writePrimitive(const float i, const Path &p=Path())
Definition: Writer.h:76
armarx::aron::data::WriterInterface
Definition: Writer.h:38