+ConfigurationElement::~ConfigurationElement() {}
+
+// **** 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() override;
+
+ std::string getStringValue() override;
+ const char* getTypeName() override;
+ void setStringValue(const char* value) override;
+
+ void update()
+ {
+ if (old_callback)
+ this->old_callback(key.c_str());
+ if (this->callback)
+ this->callback(this->content);
+ }
+
+ T const& getValue() const { return content; }
+
+ void setValue(T value)
+ {
+ this->content = std::move(value);
+ this->update();
+ }
+
+ void setDefaultValue(T value)
+ {
+ if (this->isdefault) {
+ this->content = std::move(value);
+ this->update();
+ } else {
+ XBT_DEBUG("Do not override configuration variable '%s' with value '%s'"
+ " because it was already set.", key.c_str(), to_string(value).c_str());
+ }
+ }
+};
+
+template<class T>
+std::string TypedConfigurationElement<T>::getStringValue() // override
+{
+ return to_string(content);
+}
+
+template<class T>
+void TypedConfigurationElement<T>::setStringValue(const char* value) // override
+{
+ this->content = ConfigType<T>::parse(value);
+ this->isdefault = false;
+ this->update();
+}
+
+template<class T>
+const char* TypedConfigurationElement<T>::getTypeName() // override
+{
+ return ConfigType<T>::type_name;
+}
+
+template<class T>
+TypedConfigurationElement<T>::~TypedConfigurationElement()
+{}
+
+} // end of anonymous namespace
+
+// **** Config ****
+