From 56977b8749a53ed66240653f3b5b09fab5ce29a6 Mon Sep 17 00:00:00 2001 From: Andre Sailer Date: Fri, 23 Jun 2017 17:34:25 +0200 Subject: [PATCH] Processor: check also for registerOptionalProcessor move logic for check to separate function --- source/include/marlin/Processor.h | 33 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/source/include/marlin/Processor.h b/source/include/marlin/Processor.h index 60ab8ae5..d142a1b6 100644 --- a/source/include/marlin/Processor.h +++ b/source/include/marlin/Processor.h @@ -249,18 +249,7 @@ namespace marlin{ T& parameter, const T& defaultVal, int setSize=0 ) { - - auto paraIt = _map.find( name ); - - if (paraIt != _map.end() ) { - std::stringstream errorMessage; - errorMessage << "Parameter " << name - << " already defined for processor " - << this->type() - << std::endl; - throw std::logic_error( errorMessage.str() ); - } - + checkForExistingParameter( name ); _map[ name ] = new ProcessorParameter_t( name , description, parameter, defaultVal, false , setSize) ; @@ -320,7 +309,8 @@ namespace marlin{ T& parameter, const T& defaultVal, int setSize=0 ) { - + + checkForExistingParameter( name ); _map[ name ] = new ProcessorParameter_t( name , description, parameter, defaultVal, true , setSize) ; @@ -330,7 +320,22 @@ namespace marlin{ */ bool parameterSet( const std::string& name ) ; - + /** Tests whether the parameter has been registered before + * + * @param name name of the parameter to check + * @throw logic_error if parameter has been registered before + */ + void checkForExistingParameter( const std::string& name ) { + auto paraIt = _map.find( name ); + if (paraIt != _map.end() ) { + std::stringstream errorMessage; + errorMessage << "Parameter " << name + << " already defined for processor " + << this->type() + << std::endl; + throw std::logic_error( errorMessage.str() ); + } + } /** Print message according to verbosity level of the templated parameter (one of * DEBUG, MESSAGE, WARNING, ERROR ) and the global parameter "Verbosity".