8#ifndef ROBOTSIO_PARAMETERS_H
9#define ROBOTSIO_PARAMETERS_H
11#include <RobotsIO/Utils/ParametersExtractor.h>
12#include <RobotsIO/Utils/ParametersFiller.h>
16#include <unordered_map>
25#define robots_io_field_storage(type) \
26 std::unordered_map<std::string, type > type##_data_; \
28#define robots_io_std_field_storage(type) \
29 std::unordered_map<std::string, std::type > type##_data_; \
31#define robots_io_field_getter(type) \
32 type get_##type(const std::string& name) const; \
34#define robots_io_std_field_getter(type) \
35 std::type get_##type(const std::string& name) const; \
37#define robots_io_field_setter(type) \
38 void set_##type(const std::string& name, const type& value); \
40#define robots_io_std_field_setter(type) \
41 void set_##type(const std::string& name, const std::type& value); \
43#define robots_io_declare_field(class_name, type, name) \
46 void name(const type& value); \
48 class Field_##name : public Field \
51 void extract_field(const class_name ¶meters, RobotsIO::Utils::ParametersExtractor& extractor) const override; \
53 bool fill_field(class_name ¶meters, const RobotsIO::Utils::ParametersFiller& extractor) override; \
57 friend class Field_##name;
59#define robots_io_declare_std_field(class_name, type, name) \
60 std::type name() const; \
62 void name(const std::type& value); \
64 class Field_##name : public Field \
67 void extract_field(const class_name ¶meters, RobotsIO::Utils::ParametersExtractor& extractor) const override; \
69 bool fill_field(class_name ¶meters, const RobotsIO::Utils::ParametersFiller& extractor) override; \
73 friend class Field_##name;
75#define robots_io_accessor(class_name) \
76 class_name(const RobotsIO::Utils::ParametersFiller& filler); \
81 virtual void extract_field(const class_name& parameters, RobotsIO::Utils::ParametersExtractor& extractor) const = 0; \
83 virtual bool fill_field(class_name& parameters, const RobotsIO::Utils::ParametersFiller& filler) = 0; \
86 std::unordered_map<std::string, Field*> fields_; \
88 void extract_field(const std::string& key, RobotsIO::Utils::ParametersExtractor& extractor) const override; \
90 bool fill_field(const std::string& key, const RobotsIO::Utils::ParametersFiller& filler) override; \
92 std::vector<std::string> keys() const override;
94#define robots_io_declare_field_impl(class_name, type, name) \
95 type class_name::name() const \
97 return get_##type(#name); \
100 void class_name::name(const type& value) \
102 if (fields_.find(#name) == fields_.end()) \
103 fields_[#name] = new Field_##name(); \
104 set_##type(#name, value); \
107 void class_name::Field_##name::extract_field(const class_name& parameters, RobotsIO::Utils::ParametersExtractor& extractor) const \
109 extractor.extract_field(#name, parameters.name()); \
112 bool class_name::Field_##name::fill_field(class_name& parameters, const RobotsIO::Utils::ParametersFiller& filler) \
114 bool is_value = false; \
116 std::tie(is_value, value) = filler.fill_##type(#name); \
120 parameters.name(value); \
125#define robots_io_declare_std_field_impl(class_name, type, name) \
126 std::type class_name::name() const \
128 return get_##type(#name); \
131 void class_name::name(const std::type& value) \
133 if (fields_.find(#name) == fields_.end()) \
134 fields_[#name] = new Field_##name(); \
135 set_##type(#name, value); \
138 void class_name::Field_##name::extract_field(const class_name& parameters, RobotsIO::Utils::ParametersExtractor& extractor) const \
140 extractor.extract_field(#name, parameters.name()); \
143 bool class_name::Field_##name::fill_field(class_name& parameters, const RobotsIO::Utils::ParametersFiller& filler) \
145 bool is_value = false; \
147 std::tie(is_value, value) = filler.fill_##type(#name); \
151 parameters.name(value); \
156#define robots_io_accessor_impl(class_name) \
157 class_name::class_name(const RobotsIO::Utils::ParametersFiller& filler) \
160 for (const std::string& key : keys()) \
161 if (!fill_field(key, filler)) \
163 throw(std::runtime_error(std::string(#class_name) + "::ctor. Field " + key + " not available in provided filler.")); \
167 void class_name::extract_field(const std::string& key, RobotsIO::Utils::ParametersExtractor& extractor) const \
169 fields_.at(key)->extract_field(*this, extractor); \
172 bool class_name::fill_field(const std::string& key, const RobotsIO::Utils::ParametersFiller& filler) \
174 return fields_.at(key)->fill_field(*this, filler); \
177 std::vector<std::string> class_name::keys() const\
179 std::vector<std::string> keys; \
180 for (const auto& field : fields_) \
181 keys.push_back(field.first); \
201 virtual std::vector<std::string>
keys()
const = 0;
216 robots_io_field_getter(
double);
218 robots_io_field_getter(
int);
220 robots_io_field_getter(
bool);
229 robots_io_field_setter(
double);
231 robots_io_field_setter(
int);
233 robots_io_field_setter(
bool);
239 robots_io_std_field_storage(
string);
241 robots_io_std_field_storage(
size_t);
243 robots_io_field_storage(
double);
245 robots_io_field_storage(
int);
247 robots_io_field_storage(
bool);
virtual std::vector< std::string > keys() const =0
robots_io_std_field_setter(string)
const Parameters * parameters() const
virtual void extract_field(const std::string &key, RobotsIO::Utils::ParametersExtractor &extractor) const =0
robots_io_std_field_getter(string)
virtual bool fill_field(const std::string &key, const RobotsIO::Utils::ParametersFiller &filler)=0