summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/config
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/config')
-rw-r--r--2005/i/robert/src/config/Makefile.defs5
-rw-r--r--2005/i/robert/src/config/config.hh24
-rw-r--r--2005/i/robert/src/config/parser.yy47
-rw-r--r--2005/i/robert/src/config/test_config_data.cc3
4 files changed, 71 insertions, 8 deletions
diff --git a/2005/i/robert/src/config/Makefile.defs b/2005/i/robert/src/config/Makefile.defs
index 816946f..7683a6c 100644
--- a/2005/i/robert/src/config/Makefile.defs
+++ b/2005/i/robert/src/config/Makefile.defs
@@ -4,8 +4,13 @@ config_OBJECTS = lexer.o parser.o config_data.o
test_config_data_OBJECTS = $(config_OBJECTS) test_config_data.o
+EXTRA_CLEAN += parser.hh parser.cc lexer.hh lexer.cc
+
test_config_data: $(test_config_data_OBJECTS)
parser.hh: parser.cc
+lexer.o: parser.hh
lexer.hh: lexer.cc
+parser.o: lexer.hh
+config_data.o: lexer.hh
diff --git a/2005/i/robert/src/config/config.hh b/2005/i/robert/src/config/config.hh
index 766a70f..c88ec98 100644
--- a/2005/i/robert/src/config/config.hh
+++ b/2005/i/robert/src/config/config.hh
@@ -24,17 +24,39 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// }}}
+#include "config_data.hh"
#include <list>
#include <string>
-/// Class to access config.
+/// Classe d'accés à la configuration.
class Config
{
+ ConfigData configData_;
public:
typedef std::list<int> IntList;
typedef std::list<double> FloatList;
typedef std::list<std::string> StringList;
+ public:
+ /// Boa constricteur, voir ConfigData.
+ Config (int &argc, char **&argv)
+ : configData_ (argc, argv)
+ { }
+ /// Boa constricteur, voir ConfigData.
+ Config (int &argc, char **&argv, const std::string &file)
+ : configData_ (argc, argv, file)
+ { }
+ /// Récupère une valeur de configuration, fonction générique.
+ template<typename T>
+ const T &get (const std::string &id) const
+ {
+ return configData_.get<T> (id);
+ }
+ /// Récupère une valeur de configuration.
+ const any &get (const std::string &id) const
+ {
+ return configData_.get (id);
+ }
};
#endif // config_hh
diff --git a/2005/i/robert/src/config/parser.yy b/2005/i/robert/src/config/parser.yy
index 4bd744f..3397c57 100644
--- a/2005/i/robert/src/config/parser.yy
+++ b/2005/i/robert/src/config/parser.yy
@@ -67,18 +67,19 @@ void yyerror (const char *);
%token IMG DATA
%type<a> int_list
-//%type<a> float_list
-//%type<a> string_list
+%type<a> float_list
+%type<a> string_list
%destructor { delete $$; } ID STRING
%destructor { delete $$.a; } int_list
-//%destructor { delete $$.a; } float_list
-//%destructor { delete $$.a; } string_list
+%destructor { delete $$.a; } float_list
+%destructor { delete $$.a; } string_list
%%
input:
- confitem
+ /* Nothing. */
+ | confitem
| input '\n' confitem
| input '\n'
;
@@ -102,6 +103,16 @@ confitem:
delete $1;
delete $4.a;
}
+ | ID '=' '(' float_list ')' {
+ yyextra->configData.add (*$1, *$4.a);
+ delete $1;
+ delete $4.a;
+ }
+ | ID '=' '(' string_list ')' {
+ yyextra->configData.add (*$1, *$4.a);
+ delete $1;
+ delete $4.a;
+ }
;
int_list:
@@ -116,6 +127,32 @@ int_list:
}
;
+float_list:
+ FLOAT {
+ $$.a = new any (Config::FloatList ());
+ $$.fl = any_cast<Config::FloatList> ($$.a);
+ $$.fl->push_back ($1);
+ }
+ | float_list FLOAT {
+ $1.fl->push_back ($2);
+ $$ = $1;
+ }
+;
+
+string_list:
+ STRING {
+ $$.a = new any (Config::StringList ());
+ $$.sl = any_cast<Config::StringList> ($$.a);
+ $$.sl->push_back (*$1);
+ delete $1;
+ }
+ | string_list STRING {
+ $1.sl->push_back (*$2);
+ $$ = $1;
+ delete $2;
+ }
+;
+
%%
void yyerror (const char *e)
diff --git a/2005/i/robert/src/config/test_config_data.cc b/2005/i/robert/src/config/test_config_data.cc
index d214d4f..052a4c8 100644
--- a/2005/i/robert/src/config/test_config_data.cc
+++ b/2005/i/robert/src/config/test_config_data.cc
@@ -22,7 +22,6 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// }}}
-#include "config_data.hh"
#include "config.hh"
#include <iterator>
@@ -33,7 +32,7 @@ main (int argc, char **argv)
{
try
{
- ConfigData cd (argc, argv);
+ Config cd (argc, argv);
for (int i = 1; i < argc; ++i)
std::cout << cd.get (argv[i]) << std::endl;
}