mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 06:59:18 +02:00
fix for loading boolean settings from .fiz files
This commit is contained in:
@@ -1150,6 +1150,23 @@ private:
|
|||||||
|
|
||||||
extern double Distance(TLocation Loc1, TLocation Loc2, TDimension Dim1, TDimension Dim2);
|
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 <typename _Type>
|
template <typename _Type>
|
||||||
bool
|
bool
|
||||||
extract_value( _Type &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) {
|
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 << Default;
|
||||||
converter >> Variable;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
bool
|
||||||
|
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default );
|
||||||
@@ -7912,3 +7912,23 @@ double TMoverParameters::ShowCurrentP(int AmpN)
|
|||||||
return current;
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user