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;
86 template <
typename result_type>
87 shared_ptr<result_type>
get(
const std::string& name)
const
90 throw std::runtime_error((
"[Configurable::Registry] Object id \"" + name +
"\" requested, but not found in registry.").c_str());
92 shared_ptr<result_type> result = dynamic_pointer_cast<result_type>(at(name));
94 throw std::runtime_error((
"[Configurable::Registry] Unable to convert object " + name).c_str());
99 template <
typename result_type>
100 shared_ptr<result_type>
get(
const std::string& name, std::nothrow_t)
const
102 if (!count(name))
return shared_ptr<result_type>();
103 return dynamic_pointer_cast<result_type>(at(name));
108 template<> shared_ptr<Locus> Configurable::Registry::get(
const std::string& name)
const;
109 template<> shared_ptr<Locus> Configurable::Registry::get(
const std::string& name, std::nothrow_t)
const;
112 #endif // _CONFIGURABLE_HPP_