From 1bc2c5cc461127995e444463179fcf211db3f085 Mon Sep 17 00:00:00 2001 From: nojhan Date: Mon, 26 Mar 2012 18:18:45 +0200 Subject: [PATCH] added the 'value' method to eoParser, so as to permits a direct access to the value stored within the eovalueParam corresponding to a given param name --- eo/src/utils/eoParser.cpp | 13 +++++++++---- eo/src/utils/eoParser.h | 31 +++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/eo/src/utils/eoParser.cpp b/eo/src/utils/eoParser.cpp index 6ddcdb63..7489cf65 100644 --- a/eo/src/utils/eoParser.cpp +++ b/eo/src/utils/eoParser.cpp @@ -18,9 +18,12 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Contact: todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@inria.fr - mkeijzer@dhi.dk +Contact: http://eodev.sourceforge.net +Authors: + todos@geneura.ugr.es, http://geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + mkeijzer@dhi.dk + Johann Dréo */ //----------------------------------------------------------------------------- @@ -37,6 +40,8 @@ #include #include #include +#include + using namespace std; @@ -129,7 +134,7 @@ eoParam * eoParser::getParamWithLongName(const std::string& _name) const return 0; } -eoParam * getParam(const std::string& _name) const +eoParam * eoParser::getParam(const std::string& _name) const { eoParam * p = getParamWithLongName( _name ); if( p == NULL ) { diff --git a/eo/src/utils/eoParser.h b/eo/src/utils/eoParser.h index b0f4c888..b33f956e 100644 --- a/eo/src/utils/eoParser.h +++ b/eo/src/utils/eoParser.h @@ -1,4 +1,4 @@ -/* (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000 +/* (c) Marc Schoenauer, Maarten Keijzer, GeNeura Team, Thales group This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free @@ -14,9 +14,11 @@ with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: http://eodev.sourceforge.net - todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@polytechnique.fr - mkeijzer@dhi.dk +Authors: + todos@geneura.ugr.es, http://geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + mkeijzer@dhi.dk + Johann Dréo */ @@ -183,6 +185,27 @@ public: eoParam * getParam(const std::string& _name) const; + /** + * Get the value of a param from its long name + * If not found, raise an eoMissingParamException + * + * Remember to specify the expected return type with a templated call: + * unsigned int popSize = eoparser.value("popSize"); + */ + template + ValueType value(const std::string& _name) const + { + eoParam* param = getParam(_name); + + eoValueParam* vparam( + dynamic_cast< eoValueParam* >(param) + ); + + return vparam->value(); + } + + + /** Get or create parameter It seems finally that the easiest use of the above method is