From affc465467f55b37cbde63b1c60aa5298a14da4f Mon Sep 17 00:00:00 2001 From: schodet Date: Wed, 13 Apr 2005 21:08:01 +0000 Subject: Finition de config. --- 2005/i/robert/src/config/Makefile.defs | 5 +++ 2005/i/robert/src/config/config.hh | 24 +++++++++++++- 2005/i/robert/src/config/parser.yy | 47 +++++++++++++++++++++++++--- 2005/i/robert/src/config/test_config_data.cc | 3 +- 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 #include -/// Class to access config. +/// Classe d'accés à la configuration. class Config { + ConfigData configData_; public: typedef std::list IntList; typedef std::list FloatList; typedef std::list 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 + const T &get (const std::string &id) const + { + return configData_.get (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 int_list -//%type float_list -//%type string_list +%type float_list +%type 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 ($$.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 ($$.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 @@ -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; } -- cgit v1.2.3