VariantHelperFactory.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  * @package RobotAPI
17  * @author Christoph Pohl ( christoph dot pohl at kit dot edu )
18  * @date 04.11.22
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <list>
26 
29 
32 
34 {
35  namespace factories
36  {
37  struct VariantHelper : armarx::Factory<VariantHelper, type::Descriptor>
38  {
39  explicit VariantHelper(Key){};
40 
41  virtual ~VariantHelper() = default;
42 
43  virtual std::string to_string(const armarx::aron::data::VariantPtr&) const = 0;
44 
46  const std::string& string) const = 0;
47 
48  virtual aron::data::VariantPtr from_string(const std::string&,
49  const armarx::aron::Path& path) const = 0;
50  };
51  } // namespace factories
52 
53  namespace products
54  {
55  template <type::Descriptor DescT>
56  struct VariantHelper : factories::VariantHelper::Registrar<VariantHelper<DescT>>
57  {
58  using RegistrarT = factories::VariantHelper::Registrar<VariantHelper<DescT>>;
59  static constexpr type::Descriptor id = DescT;
60 
61  explicit VariantHelper() : RegistrarT(typename RegistrarT::Registration()){};
62 
63  [[nodiscard]] std::string to_string(const data::VariantPtr& ptr) const override;
64 
66  const std::string& string) const override;
67 
68  [[nodiscard]] aron::data::VariantPtr
69  from_string(const std::string&, const armarx::aron::Path& path) const override;
70  };
71 
72  } // namespace products
73 
74  template <>
75  std::string
77 
78  template <>
80  const std::string&,
81  const armarx::aron::Path& path) const;
82 
83  template <>
86  const std::string&) const;
87 
88  template <>
89  std::string
91 
92  template <>
94  const std::string&,
95  const armarx::aron::Path& path) const;
96 
97  template <>
100  const std::string&) const;
101 
102  template <>
103  std::string
105 
106  template <>
108  const std::string&,
109  const armarx::aron::Path& path) const;
110 
111  template <>
114  const std::string&) const;
115 
116  template <>
117  std::string
119 
120  template <>
122  const std::string&,
123  const armarx::aron::Path& path) const;
124 
125  template <>
128  const std::string&) const;
129 
130  template <>
131  std::string
133 
134  template <>
136  const std::string&,
137  const armarx::aron::Path& path) const;
138 
139  template <>
142  const std::string&) const;
143 
144  template <>
146  const data::VariantPtr& ptr) const;
147 
148  template <>
150  const std::string&,
151  const armarx::aron::Path& path) const;
152 
153  template <>
156  const std::string&) const;
157 
158  static inline const std::list<type::Descriptor> implementedListDescriptors = {
165  };
166  extern template struct products::VariantHelper<type::Descriptor::INT>;
167  extern template struct products::VariantHelper<type::Descriptor::FLOAT>;
168  extern template struct products::VariantHelper<type::Descriptor::DOUBLE>;
169  extern template struct products::VariantHelper<type::Descriptor::STRING>;
170  extern template struct products::VariantHelper<type::Descriptor::BOOL>;
171  extern template struct products::VariantHelper<type::Descriptor::INT_ENUM>;
172 } // namespace armarx::aron::component_config
armarx::aron::type::Descriptor::FLOAT
@ FLOAT
armarx::aron::type::Descriptor::DOUBLE
@ DOUBLE
Variant.h
armarx::aron::component_config::products::VariantHelper::VariantHelper
VariantHelper()
Definition: VariantHelperFactory.h:61
Descriptor.h
armarx::aron::component_config
Definition: PropertyDefinitionVisitors.cpp:50
armarx::aron::component_config::factories::VariantHelper
Definition: VariantHelperFactory.h:37
armarx::Factory
Definition: SelfRegisteringFactory.h:50
armarx::aron::component_config::products::VariantHelper::from_string
aron::data::VariantPtr from_string(const std::string &, const armarx::aron::Path &path) const override
armarx::aron::component_config::factories::VariantHelper::~VariantHelper
virtual ~VariantHelper()=default
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::data::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::aron::type::Descriptor::BOOL
@ BOOL
armarx::aron::component_config::factories::VariantHelper::from_string
virtual aron::data::VariantPtr from_string(const std::string &, const armarx::aron::Path &path) const =0
armarx::aron::component_config::factories::VariantHelper::to_string
virtual std::string to_string(const armarx::aron::data::VariantPtr &) const =0
armarx::aron::component_config::factories::VariantHelper::set_value_from_string
virtual void set_value_from_string(const armarx::aron::data::VariantPtr &, const std::string &string) const =0
armarx::aron::component_config::factories::VariantHelper::VariantHelper
VariantHelper(Key)
Definition: VariantHelperFactory.h:39
armarx::aron::component_config::products::VariantHelper::set_value_from_string
void set_value_from_string(const armarx::aron::data::VariantPtr &variant, const std::string &string) const override
armarx::aron::component_config::products::VariantHelper::RegistrarT
factories::VariantHelper::Registrar< VariantHelper< DescT > > RegistrarT
Definition: VariantHelperFactory.h:58
armarx::navigation::platform_controller::platform_global_trajectory::Registration
const NJointControllerRegistration< Controller > Registration(common::ControllerTypeNames.to_name(common::ControllerType::PlatformGlobalTrajectory))
SelfRegisteringFactory.h
armarx::aron::type::Descriptor::STRING
@ STRING
armarx::aron::type::Descriptor::INT
@ INT
armarx::aron::component_config::products::VariantHelper
Definition: VariantHelperFactory.h:56
armarx::aron::type::Descriptor::INT_ENUM
@ INT_ENUM
forward_declarations.h
armarx::aron::component_config::products::VariantHelper::to_string
std::string to_string(const data::VariantPtr &ptr) const override
armarx::aron::type::Descriptor
Descriptor
Definition: Descriptor.h:76