summaryrefslogtreecommitdiff
path: root/i/marvin/src/config/config_data.tcc
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src/config/config_data.tcc')
-rw-r--r--i/marvin/src/config/config_data.tcc20
1 files changed, 20 insertions, 0 deletions
diff --git a/i/marvin/src/config/config_data.tcc b/i/marvin/src/config/config_data.tcc
index 31b62bc..7e5b905 100644
--- a/i/marvin/src/config/config_data.tcc
+++ b/i/marvin/src/config/config_data.tcc
@@ -37,6 +37,26 @@ ConfigData::get (const std::string &id) const
return *v;
}
+/// Récupère une valeur de configuration, fonction générique avec valeur
+/// par défaut. Cette fonction ne renvoie d'exception que si il y a un
+/// problème de type et non de valeur non existante.
+template<typename T>
+const T &
+ConfigData::get (const std::string &id, const T &defaut) const
+{
+ // Construct an empty any
+ any empty;
+ // Get the value with an empty one by default
+ const any &a = get (id, empty);
+ // Empty value returned, not found
+ if (a.empty ())
+ return defaut;
+ const T *v = any_cast<T> (&a);
+ if (!v)
+ throw std::runtime_error (id + ": config item with bad type");
+ return *v;
+}
+
/// Ajoute une valeur de configuration, fonction générique. Attention,
/// cette fonction est plus couteuse car elle fait une copie de
/// la valeur.