From b5b282f06e71c59f2c0787def4035c5ddba50b37 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Sat, 1 Apr 2017 14:56:26 +0200 Subject: [PATCH] fix for loading boolean settings from .fiz files --- McZapkie/MOVER.h | 40 ++++++++++++++++++++++------------------ McZapkie/Mover.cpp | 20 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index aa11d20b..bd5683a7 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -1150,6 +1150,23 @@ private: extern double Distance(TLocation Loc1, TLocation Loc2, TDimension Dim1, TDimension Dim2); +inline +std::string +extract_value( std::string const &Key, std::string const &Input ) { + + std::string value; + auto lookup = Input.find( Key + "=" ); + if( lookup != std::string::npos ) { + value = Input.substr( Input.find_first_not_of( ' ', lookup + Key.size() + 1 ) ); + lookup = value.find( ' ' ); + if( lookup != std::string::npos ) { + // trim everything past the value + value.erase( lookup ); + } + } + return value; +} + template bool extract_value( _Type &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) { @@ -1169,23 +1186,10 @@ extract_value( _Type &Variable, std::string const &Key, std::string const &Input converter << Default; converter >> Variable; } - return false; // supplied the default - } + return false; // couldn't locate the variable in provided input + } } -inline -std::string -extract_value( std::string const &Key, std::string const &Input ) { - - std::string value; - auto lookup = Input.find( Key + "=" ); - if( lookup != std::string::npos ) { - value = Input.substr( Input.find_first_not_of( ' ', lookup + Key.size() + 1 ) ); - lookup = value.find( ' ' ); - if( lookup != std::string::npos ) { - // trim everything past the value - value.erase( lookup ); - } - } - return value; -} \ No newline at end of file +template <> +bool +extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default ); \ No newline at end of file diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index eed06456..725754ab 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -7912,3 +7912,23 @@ double TMoverParameters::ShowCurrentP(int AmpN) return current; } } + +template <> +bool +extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) { + + auto value = extract_value( Key, Input ); + if( false == value.empty() ) { + // set the specified variable to retrieved value + Variable = ( value == "Yes" ); + return true; // located the variable + } + else { + // set the variable to provided default value + if( false == Default.empty() ) { + // (provided there's one) + Variable = ( Default == "Yes" ); + } + return false; // couldn't locate the variable in provided input + } +}