If we don't recognize a var then it's an error, not 0.0.

This commit is contained in:
Jeff Young 2022-12-27 13:45:42 +00:00
parent 39a23fa9bc
commit 572c10b2c4
2 changed files with 33 additions and 15 deletions

View File

@ -99,18 +99,21 @@ void NUMERIC_EVALUATOR::LocaleChanged()
}
// NOT UNUSED. Called by LEMON grammar.
void NUMERIC_EVALUATOR::parseError( const char* s )
{
m_parseError = true;
}
// NOT UNUSED. Called by LEMON grammar.
void NUMERIC_EVALUATOR::parseOk()
{
m_parseFinished = true;
}
// NOT UNUSED. Called by LEMON grammar.
void NUMERIC_EVALUATOR::parseSetResult( double val )
{
if( std::isnan( val ) )
@ -474,8 +477,15 @@ void NUMERIC_EVALUATOR::SetVar( const wxString& aString, double aValue )
double NUMERIC_EVALUATOR::GetVar( const wxString& aString )
{
if( m_varMap[ aString ] )
return m_varMap[ aString ];
auto it = m_varMap.find( aString );
if( it != m_varMap.end() )
{
return it->second;
}
else
{
m_parseError = true;
return 0.0;
}
}

View File

@ -47,8 +47,8 @@ void SIM_PROPERTY::Disable()
}
SIM_BOOL_PROPERTY::SIM_BOOL_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_MODEL& aModel,
int aParamIndex ) :
SIM_BOOL_PROPERTY::SIM_BOOL_PROPERTY( const wxString& aLabel, const wxString& aName,
SIM_MODEL& aModel, int aParamIndex ) :
wxBoolProperty( aLabel, aName ),
SIM_PROPERTY( aModel, aParamIndex )
{
@ -84,8 +84,9 @@ void SIM_BOOL_PROPERTY::OnSetValue()
}
SIM_STRING_PROPERTY::SIM_STRING_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_MODEL& aModel,
int aParamIndex, SIM_VALUE::TYPE aValueType,
SIM_STRING_PROPERTY::SIM_STRING_PROPERTY( const wxString& aLabel, const wxString& aName,
SIM_MODEL& aModel, int aParamIndex,
SIM_VALUE::TYPE aValueType,
SIM_VALUE_GRAMMAR::NOTATION aNotation ) :
wxStringProperty( aLabel, aName ),
SIM_PROPERTY( aModel, aParamIndex ),
@ -161,7 +162,8 @@ bool SIM_STRING_PROPERTY::allowEval() const
}
bool SIM_STRING_PROPERTY::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const
bool SIM_STRING_PROPERTY::StringToValue( wxVariant& aVariant, const wxString& aText,
int aArgFlags ) const
{
if( m_disabled )
return false;
@ -191,16 +193,22 @@ static wxArrayString convertStringsToWx( const std::vector<std::string>& aString
}
SIM_ENUM_PROPERTY::SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_MODEL& aModel,
int aParamIndex ) :
wxEnumProperty( aLabel, aName, convertStringsToWx( aModel.GetParam( aParamIndex ).info.enumValues ) ),
SIM_ENUM_PROPERTY::SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aName,
SIM_MODEL& aModel, int aParamIndex ) :
wxEnumProperty( aLabel, aName,
convertStringsToWx( aModel.GetParam( aParamIndex ).info.enumValues ) ),
SIM_PROPERTY( aModel, aParamIndex )
{
auto it = std::find( GetParam().info.enumValues.begin(), GetParam().info.enumValues.end(),
GetParam().value->ToString() );
for( int ii = 0; ii < (int) GetParam().info.enumValues.size(); ++ii )
{
if( GetParam().info.enumValues[ii] == GetParam().value->ToString() )
{
SetValue( ii );
return;
}
}
// we need the force cast for msvc because wxVariant lacks 64-bit methods due to `long`
SetValue( static_cast<int>( std::distance( GetParam().info.enumValues.begin(), it ) ) );
SetValue( -1 );
}