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

This commit is contained in:
nojhan 2012-03-26 18:18:45 +02:00
commit 1bc2c5cc46
2 changed files with 36 additions and 8 deletions

View file

@ -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 <johann.dreo@thalesgroup.com>
*/
//-----------------------------------------------------------------------------
@ -37,6 +40,8 @@
#include <utils/compatibility.h>
#include <utils/eoParser.h>
#include <utils/eoLogger.h>
#include <eoExceptions.h>
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 ) {

View file

@ -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 <johann.dreo@thalesgroup.com>
*/
@ -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<unsigned int>("popSize");
*/
template<class ValueType>
ValueType value(const std::string& _name) const
{
eoParam* param = getParam(_name);
eoValueParam<ValueType>* vparam(
dynamic_cast< eoValueParam<ValueType>* >(param)
);
return vparam->value();
}
/** Get or create parameter
It seems finally that the easiest use of the above method is