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:
parent
47447c4765
commit
1bc2c5cc46
2 changed files with 36 additions and 8 deletions
|
|
@ -18,9 +18,12 @@
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
Contact: http://eodev.sourceforge.net
|
||||||
Marc.Schoenauer@inria.fr
|
Authors:
|
||||||
|
todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
|
Marc.Schoenauer@polytechnique.fr
|
||||||
mkeijzer@dhi.dk
|
mkeijzer@dhi.dk
|
||||||
|
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -37,6 +40,8 @@
|
||||||
#include <utils/compatibility.h>
|
#include <utils/compatibility.h>
|
||||||
#include <utils/eoParser.h>
|
#include <utils/eoParser.h>
|
||||||
#include <utils/eoLogger.h>
|
#include <utils/eoLogger.h>
|
||||||
|
#include <eoExceptions.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
@ -129,7 +134,7 @@ eoParam * eoParser::getParamWithLongName(const std::string& _name) const
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
eoParam * getParam(const std::string& _name) const
|
eoParam * eoParser::getParam(const std::string& _name) const
|
||||||
{
|
{
|
||||||
eoParam * p = getParamWithLongName( _name );
|
eoParam * p = getParamWithLongName( _name );
|
||||||
if( p == NULL ) {
|
if( p == NULL ) {
|
||||||
|
|
|
||||||
|
|
@ -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
|
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
|
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
|
Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
Contact: http://eodev.sourceforge.net
|
Contact: http://eodev.sourceforge.net
|
||||||
|
Authors:
|
||||||
todos@geneura.ugr.es, http://geneura.ugr.es
|
todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
Marc.Schoenauer@polytechnique.fr
|
Marc.Schoenauer@polytechnique.fr
|
||||||
mkeijzer@dhi.dk
|
mkeijzer@dhi.dk
|
||||||
|
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -183,6 +185,27 @@ public:
|
||||||
eoParam * getParam(const std::string& _name) const;
|
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
|
/** Get or create parameter
|
||||||
|
|
||||||
It seems finally that the easiest use of the above method is
|
It seems finally that the easiest use of the above method is
|
||||||
|
|
|
||||||
Reference in a new issue