+// **** TypedConfigurationElement<T> ****
+
+// TODO, could we use boost::any with some Type* reference?
+template<class T>
+class TypedConfigurationElement : public ConfigurationElement {
+private:
+ T content;
+ std::function<void(T&)> callback;
+
+public:
+ TypedConfigurationElement(const char* key, const char* desc, T value = T())
+ : ConfigurationElement(key, desc), content(std::move(value))
+ {}
+ TypedConfigurationElement(const char* key, const char* desc, T value, xbt_cfg_cb_t cb)
+ : ConfigurationElement(key, desc, cb), content(std::move(value))
+ {}
+ TypedConfigurationElement(const char* key, const char* desc, T value, std::function<void(T&)> callback)
+ : ConfigurationElement(key, desc), content(std::move(value)), callback(std::move(callback))
+ {}
+ ~TypedConfigurationElement() = default;
+
+ std::string get_string_value() override;
+ const char* get_type_name() override;
+ void set_string_value(const char* value) override;
+
+ void update()
+ {
+ if (old_callback)
+ this->old_callback(get_key().c_str());
+ if (this->callback)
+ this->callback(this->content);
+ }
+
+ T const& get_value() const { return content; }
+
+ void set_value(T value)
+ {
+ this->content = std::move(value);
+ this->update();
+ this->unset_default();
+ }
+
+ void set_default_value(T value)
+ {
+ if (this->is_default()) {
+ this->content = std::move(value);
+ this->update();
+ } else {
+ XBT_DEBUG("Do not override configuration variable '%s' with value '%s' because it was already set.",
+ get_key().c_str(), to_string(value).c_str());
+ }
+ }
+};
+
+template <class T> std::string TypedConfigurationElement<T>::get_string_value() // override
+{
+ return to_string(content);
+}
+
+template <class T> void TypedConfigurationElement<T>::set_string_value(const char* value) // override
+{
+ this->content = ConfigType<T>::parse(value);
+ this->unset_default();
+ this->update();
+}
+
+template <class T> const char* TypedConfigurationElement<T>::get_type_name() // override
+{
+ return ConfigType<T>::type_name;
+}
+
+} // end of anonymous namespace
+
+// **** Config ****
+