36 #ifndef _CONFIGURABLE_HPP_
37 #define _CONFIGURABLE_HPP_
40 #include "Parameters.hpp"
41 #include "shared_ptr.hpp"
57 const std::string& object_id()
const {
return id_;}
59 virtual std::string class_name()
const = 0;
60 virtual Parameters parameters()
const = 0;
61 virtual void configure(
const Parameters& parameters,
const Registry& registry) = 0;
64 void write_configuration(std::ostream& os, std::set<std::string>& ids_written)
const;
65 virtual void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written)
const {}
75 typedef shared_ptr<Configurable> ConfigurablePtr;
76 typedef std::vector<ConfigurablePtr> ConfigurablePtrs;
83 template <
typename result_type>
84 shared_ptr<result_type>
get(
const std::string& name)
const
87 throw std::runtime_error((
"[Configurable::Registry] Object id \"" + name +
"\" requested, but not found in registry.").c_str());
89 shared_ptr<result_type> result = dynamic_pointer_cast<result_type>(at(name));
91 throw std::runtime_error((
"[Configurable::Registry] Unable to convert object " + name).c_str());
96 template <
typename result_type>
97 shared_ptr<result_type>
get(
const std::string& name, std::nothrow_t)
const
99 if (!count(name))
return shared_ptr<result_type>();
100 return dynamic_pointer_cast<result_type>(at(name));
105 #endif // _CONFIGURABLE_HPP_