summaryrefslogtreecommitdiff
path: root/i/marvin/src/config/config.hh
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src/config/config.hh')
-rw-r--r--i/marvin/src/config/config.hh28
1 files changed, 26 insertions, 2 deletions
diff --git a/i/marvin/src/config/config.hh b/i/marvin/src/config/config.hh
index bcec7d8..ab9cfb7 100644
--- a/i/marvin/src/config/config.hh
+++ b/i/marvin/src/config/config.hh
@@ -25,10 +25,12 @@
//
// }}}
#include "config_data.hh"
+#include <stdexcept>
#include <list>
/// Classe d'accés à la configuration.
+/// Singleton, created by hand.
class Config
{
ConfigData configData_;
@@ -36,15 +38,29 @@ class Config
typedef std::list<int> IntList;
typedef std::list<double> FloatList;
typedef std::list<std::string> StringList;
+ private:
+ static Config *instance_;
public:
/// Boa constricteur, voir ConfigData.
Config (int &argc, char **&argv)
: configData_ (argc, argv)
- { }
+ {
+ create ();
+ }
/// Boa constricteur, voir ConfigData.
Config (int &argc, char **&argv, const std::string &file)
: configData_ (argc, argv, file)
- { }
+ {
+ create ();
+ }
+ /// Check and fill the private instance_ variables for singleton
+ void create ()
+ {
+ if (instance_)
+ throw std::runtime_error ("Config already created");
+ instance_ = this;
+ }
+
/// Récupère une valeur de configuration, fonction générique.
template<typename T>
const T &get (const std::string &id) const
@@ -56,6 +72,14 @@ class Config
{
return configData_.get (id);
}
+ /// Get the unique instance of the class
+ static inline Config &
+ getInstance ()
+ {
+ if (!instance_)
+ throw std::runtime_error ("Config not created");
+ return *instance_;
+ }
};
#endif // config_hh