22 #define HUMOTO_CONFIG_DEFINE_ACCESSORS "humoto/config/define_accessors.h" 24 #ifdef HUMOTO_USE_CONFIG 25 #define HUMOTO_CONFIG_WRITE_PARENT_CLASS(parent_class) parent_class::writeConfigEntries(writer); 26 #define HUMOTO_CONFIG_WRITE_MEMBER_CLASS(member, name) member.writeNestedConfig(writer, name); 28 #define HUMOTO_CONFIG_WRITE_COMPOUND_(entry) writer.writeCompound(entry##_, #entry); 29 #define HUMOTO_CONFIG_WRITE_COMPOUND(entry) writer.writeCompound(entry, #entry); 31 #define HUMOTO_CONFIG_WRITE_SCALAR_(entry) writer.writeScalar(entry##_, #entry); 32 #define HUMOTO_CONFIG_WRITE_SCALAR(entry) writer.writeScalar(entry, #entry); 34 #define HUMOTO_CONFIG_WRITE_ENUM_(entry) writer.writeEnum(entry##_, #entry); 35 #define HUMOTO_CONFIG_WRITE_ENUM(entry) writer.writeEnum(entry, #entry); 38 #define HUMOTO_CONFIG_READ_PARENT_CLASS(parent_class) parent_class::readConfigEntries(reader, crash_on_missing_entry); 39 #define HUMOTO_CONFIG_READ_MEMBER_CLASS(member, name) member.readNestedConfig(reader, name, crash_on_missing_entry); 41 #define HUMOTO_CONFIG_READ_COMPOUND_(entry) reader.readCompound(entry##_, #entry, crash_on_missing_entry); 42 #define HUMOTO_CONFIG_READ_COMPOUND(entry) reader.readCompound(entry, #entry, crash_on_missing_entry); 44 #define HUMOTO_CONFIG_READ_SCALAR_(entry) reader.readScalar(entry##_, #entry, crash_on_missing_entry); 45 #define HUMOTO_CONFIG_READ_SCALAR(entry) reader.readScalar(entry, #entry, crash_on_missing_entry); 47 #define HUMOTO_CONFIG_READ_ENUM_(entry) reader.readEnum(entry##_, #entry, crash_on_missing_entry); 48 #define HUMOTO_CONFIG_READ_ENUM(entry) reader.readEnum(entry, #entry, crash_on_missing_entry); 52 #ifndef HUMOTO_CONFIG_CONFIGURABLE_BASE_PARENT 53 #error "Header inclusion error: configuration is enabled, but no configuration bridges included." 63 template <
bool t_crash_on_missing_entry>
67 static const bool default_crash_on_missing_entry_ = t_crash_on_missing_entry;
82 virtual void setDefaults() = 0;
95 virtual const std::string & getConfigSectionID()
const = 0;
111 virtual std::size_t getNumberOfEntries()
const = 0;
118 using HUMOTO_CONFIG_CONFIGURABLE_BASE_PARENT::writeConfigEntries;
119 using HUMOTO_CONFIG_CONFIGURABLE_BASE_PARENT::readConfigEntries;
131 template <
class t_Reader>
133 const std::string & node_name,
134 const bool crash_on_missing_entry = default_crash_on_missing_entry_)
139 if (reader.descend(node_name))
141 readConfigEntries(reader, crash_on_missing_entry);
146 if (crash_on_missing_entry)
148 HUMOTO_THROW_MSG(std::string(
"Configuration file does not contain entry '") + node_name +
"'.");
152 catch(
const std::exception &e)
154 HUMOTO_THROW_MSG(std::string(
"Failed to parse node <") + node_name +
"> in the configuration file: " + e.what());
166 template <
class t_Reader>
168 const bool crash_on_missing_entry = default_crash_on_missing_entry_)
170 readNestedConfig(reader, getConfigSectionID(), crash_on_missing_entry);
182 template <
class t_Reader>
184 const std::string & node_name,
185 const bool crash_on_missing_entry = default_crash_on_missing_entry_)
187 readNestedConfig(reader, node_name, crash_on_missing_entry);
201 template <
class t_Reader>
203 const char * node_name,
204 const bool crash_on_missing_entry = default_crash_on_missing_entry_)
206 readNestedConfig(reader, node_name, crash_on_missing_entry);
217 template <
class t_Reader>
219 const bool crash_on_missing_entry = default_crash_on_missing_entry_)
221 t_Reader reader(file_name);
222 readNestedConfig(reader, getConfigSectionID(), crash_on_missing_entry);
234 template <
class t_Reader>
236 const std::string &node_name,
237 const bool crash_on_missing_entry = default_crash_on_missing_entry_)
239 t_Reader reader(file_name);
240 readNestedConfig(reader, node_name, crash_on_missing_entry);
254 template <
class t_Reader>
256 const char *node_name,
257 const bool crash_on_missing_entry = default_crash_on_missing_entry_)
259 t_Reader reader(file_name);
260 readNestedConfig(reader, node_name, crash_on_missing_entry);
271 template <
class t_Writer>
274 writeNestedConfig(writer, getConfigSectionID());
284 template <
class t_Writer>
286 const std::string &node_name)
const 288 writer.descend(node_name, getNumberOfEntries());
289 writeConfigEntries(writer);
299 template <
class t_Writer>
302 writeConfig(writer, getConfigSectionID());
312 template <
class t_Writer>
314 const std::string &node_name)
const 317 writeNestedConfig(writer, node_name);
327 template <
class t_Writer>
330 t_Writer writer(file_name);
341 template <
class t_Writer>
343 const std::string &node_name)
const 345 t_Writer writer(file_name);
346 writeConfig(writer, node_name);
404 ~ConfigurableBase() {}
416 ~StrictConfigurableBase() {}
428 ~RelaxedConfigurableBase() {}
433 #define HUMOTO_CONFIG_DISABLED 435 #endif //HUMOTO_USE_CONFIG void readConfig(const std::string &file_name, const bool crash_on_missing_entry=default_crash_on_missing_entry_)
Read configuration (assuming the configuration node to be in the root).
void writeNestedConfig(t_Writer &writer, const std::string &node_name) const
Write nested configuration node.
~RelaxedConfigurableBase()
Protected destructor: prevent destruction of the child classes through a base pointer.
void readNestedConfig(t_Reader &reader, const std::string &node_name, const bool crash_on_missing_entry=default_crash_on_missing_entry_)
Read nested configuration node.
void readConfig(const std::string &file_name, const char *node_name, const bool crash_on_missing_entry=default_crash_on_missing_entry_)
Read configuration (assuming the configuration node to be in the root).
void writeConfig(const std::string &file_name, const std::string &node_name) const
Write configuration.
Default configurable base is strict.
virtual void finalize()
This function is called automaticaly after reading a configuration file. Does nothing by default...
#define HUMOTO_THROW_MSG(s)
HUMOTO_THROW_MSG throws an error message concatenated with the name of the function (if supported)...
void readConfig(t_Reader &reader, const char *node_name, const bool crash_on_missing_entry=default_crash_on_missing_entry_)
Read configuration (assuming the configuration node to be in the root).
~CommonConfigurableBase()
Protected destructor: prevent destruction of the child classes through a base pointer.
~StrictConfigurableBase()
Protected destructor: prevent destruction of the child classes through a base pointer.
~ConfigurableBase()
Protected destructor: prevent destruction of the child classes through a base pointer.
RelaxedConfigurableBase()
void readConfig(const std::string &file_name, const std::string &node_name, const bool crash_on_missing_entry=default_crash_on_missing_entry_)
Read configuration (assuming the configuration node to be in the root).
void writeNestedConfig(t_Writer &writer) const
Write nested configuration node.
void writeConfig(const std::string &file_name) const
Write configuration.
void readConfig(t_Reader &reader, const bool crash_on_missing_entry=default_crash_on_missing_entry_)
Read configuration (assuming the configuration node to be in the root).
The root namespace of HuMoTo.
#define HUMOTO_CONFIG_CONFIGURABLE_BASE_PARENT
void writeConfig(t_Writer &writer) const
Write configuration.
void readConfig(t_Reader &reader, const std::string &node_name, const bool crash_on_missing_entry=default_crash_on_missing_entry_)
Read configuration (assuming the configuration node to be in the root).
void writeConfig(t_Writer &writer, const std::string &node_name) const
Write configuration.