From 728bc6e8978430f6eb78da5b8cedf7aea094d38b Mon Sep 17 00:00:00 2001 From: nojhan Date: Tue, 10 Dec 2019 11:26:09 +0100 Subject: [PATCH] feat: get a param handle from its name Useful for introspection and dynamic parameter management. --- eo/src/utils/eoParser.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/eo/src/utils/eoParser.h b/eo/src/utils/eoParser.h index 793da622c..8e1df04f5 100644 --- a/eo/src/utils/eoParser.h +++ b/eo/src/utils/eoParser.h @@ -29,10 +29,10 @@ Authors: #include #include -#include "eoParam.h" #include "../eoObject.h" #include "../eoPersistent.h" #include "../eoExceptions.h" +#include "eoParam.h" /** Parameter saving and loading @@ -195,13 +195,28 @@ public: */ eoParam * getParam(const std::string& _name) const; + /** + * Get a eoValueParam handle on a param from its long name + * If not found, raise an eoMissingParamException + */ + template + eoValueParam& getValueParam(const std::string& _name) + { + eoParam* p = getParamWithLongName( _name ); + if( p == NULL ) { + throw eoMissingParamException(_name ); + } else { + return dynamic_cast< eoValueParam& >(*p); + } + } + /** * 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"); + * unsigned int popSize = eoparser.valueOf("popSize"); * * If the template type is not the good one, an eoWrongParamTypeException is raised. */