summaryrefslogtreecommitdiff
path: root/2004/i/nono/src/config
diff options
context:
space:
mode:
authorschodet2004-02-28 19:25:28 +0000
committerschodet2004-02-28 19:25:28 +0000
commit62440d5c986e06cbdd1cca6809c152da72d85855 (patch)
tree7344a8571185b2fc236bee7b04fbd6b3f0a658b1 /2004/i/nono/src/config
parentebe2b388763be16621a8277948fbbd380a5de573 (diff)
Add: Config::get<T>, pour simplifier la configuration des modules.
Diffstat (limited to '2004/i/nono/src/config')
-rw-r--r--2004/i/nono/src/config/config.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/2004/i/nono/src/config/config.h b/2004/i/nono/src/config/config.h
index a958844..f56d558 100644
--- a/2004/i/nono/src/config/config.h
+++ b/2004/i/nono/src/config/config.h
@@ -41,7 +41,6 @@ class Config
int getNum (void);
Config &operator>> (int &num) { num = getNum (); return *this; }
const char *getId (void);
- Config &operator>> (const char *&s) { s = getId (); return *this; }
bool getBool (void);
Config &operator>> (bool &b) { b = getBool (); return *this; }
double getFloat (void);
@@ -51,6 +50,11 @@ class Config
void getEof (void);
// Vérifie si le prochain token est...
bool isId (const char *s);
+ /// Récupère la valeur associée à un identificateur \a id. Retourne \c
+ /// false si l'identificateur ne correspond pas, lance une exception si il
+ /// n'y a pas d'identificateur.
+ template<typename T>
+ bool get (const char *id, T &v);
// Retourne true si à la fin du fichier.
bool eof (void);
// Lance une erreur, on a pas trouvé ce qu'on voulais.
@@ -61,4 +65,20 @@ class Config
bool wrap (void);
};
+/// Récupère la valeur associée à un identificateur \a id. Retourne \c
+/// false si l'identificateur ne correspond pas, lance une exception si il
+/// n'y a pas d'identificateur.
+template<typename T>
+bool
+Config::get (const char *id, T &v)
+{
+ if (isId (id))
+ {
+ getId ();
+ *this >> v;
+ return true;
+ }
+ return false;
+}
+
#endif // config_h