Sim: Replace all wxStrings with std::strings in SIM_VALUE

This commit is contained in:
Mikolaj Wielgus 2022-09-16 06:11:14 +02:00
parent d19b2dbfe4
commit 4ae2225b6d
7 changed files with 48 additions and 50 deletions

View File

@ -1232,7 +1232,8 @@ void SCH_SHEET_LIST::MigrateSimModelNameFields()
std::unique_ptr<SIM_VALUE> simValue =
SIM_VALUE::Create( SIM_VALUE::TYPE_FLOAT );
simValue->FromString( prefix + unit + suffix, SIM_VALUE::NOTATION::SPICE );
simValue->FromString( ( prefix + unit + suffix ).ToStdString(),
SIM_VALUE::NOTATION::SPICE );
if( value == simValue->ToString() )
continue; // Can stay the same.

View File

@ -1003,7 +1003,7 @@ bool SIM_MODEL::SetParamValue( unsigned aParamIndex, const wxString& aValue,
if( m_spiceCode != "" )
return false;
return m_params.at( aParamIndex ).value->FromString( aValue, aNotation );
return m_params.at( aParamIndex ).value->FromString( aValue.ToStdString(), aNotation );
}
@ -1350,7 +1350,8 @@ TYPE SIM_MODEL::readTypeFromSpiceStrings( const wxString& aTypeString,
const wxString& aVersion,
bool aSkipDefaultLevel )
{
std::unique_ptr<SIM_VALUE> readLevel = SIM_VALUE::Create( SIM_VALUE::TYPE_INT, aLevel );
std::unique_ptr<SIM_VALUE> readLevel = SIM_VALUE::Create( SIM_VALUE::TYPE_INT,
aLevel.ToStdString() );
for( TYPE type : TYPE_ITERATOR() )
{

View File

@ -67,7 +67,7 @@ wxString SPICE_GENERATOR_SOURCE::ItemLine( const wxString& aRefName,
case SIM_MODEL::TYPE::V_PWL:
case SIM_MODEL::TYPE::I_PWL:
{
tao::pegtl::string_input<> in( m_model.GetParam( 0 ).value->ToString().ToUTF8(),
tao::pegtl::string_input<> in( m_model.GetParam( 0 ).value->ToString(),
"from_content" );
std::unique_ptr<tao::pegtl::parse_tree::node> root;

View File

@ -190,7 +190,7 @@ bool SIM_MODEL_SPICE::SetParamFromSpiceCode( const wxString& aParamName,
AddParam( *m_paramInfos.back() );
}
return GetParam( paramIndex ).value->FromString( wxString( aParamValue ), aNotation );
return GetParam( paramIndex ).value->FromString( aParamValue.ToStdString(), aNotation );
}

View File

@ -237,7 +237,7 @@ bool SIM_STRING_VALIDATOR::TransferFromWindow()
bool SIM_STRING_VALIDATOR::isValid( const wxString& aString )
{
return SIM_VALUE_GRAMMAR::IsValid( aString, m_valueType, m_notation );
return SIM_VALUE_GRAMMAR::IsValid( aString.ToStdString(), m_valueType, m_notation );
}

View File

@ -107,7 +107,7 @@ namespace SIM_VALUE_PARSER
std::optional<long> metricSuffixExponent;
};
PARSE_RESULT Parse( const wxString& aString,
PARSE_RESULT Parse( const std::string& aString,
NOTATION aNotation = NOTATION::SI,
SIM_VALUE::TYPE aValueType = SIM_VALUE::TYPE_FLOAT );
@ -124,11 +124,11 @@ static inline void doIsValid( tao::pegtl::string_input<>& aIn )
}
bool SIM_VALUE_GRAMMAR::IsValid( const wxString& aString,
bool SIM_VALUE_GRAMMAR::IsValid( const std::string& aString,
SIM_VALUE::TYPE aValueType,
NOTATION aNotation )
{
tao::pegtl::string_input<> in( aString.ToUTF8(), "from_content" );
tao::pegtl::string_input<> in( aString, "from_content" );
try
{
@ -186,13 +186,13 @@ static inline void handleNodeForParse( tao::pegtl::parse_tree::node& aNode,
}
SIM_VALUE_PARSER::PARSE_RESULT SIM_VALUE_PARSER::Parse( const wxString& aString,
SIM_VALUE_PARSER::PARSE_RESULT SIM_VALUE_PARSER::Parse( const std::string& aString,
NOTATION aNotation,
SIM_VALUE::TYPE aValueType )
{
LOCALE_IO toggle;
tao::pegtl::string_input<> in( aString.ToUTF8(), "from_content" );
tao::pegtl::string_input<> in( aString, "from_content" );
std::unique_ptr<tao::pegtl::parse_tree::node> root;
PARSE_RESULT result;
@ -217,7 +217,7 @@ SIM_VALUE_PARSER::PARSE_RESULT SIM_VALUE_PARSER::Parse( const wxString& aString,
}
catch( const std::invalid_argument& e )
{
wxFAIL_MSG( wxString::Format( "Parsing simulator value failed: %s", e.what() ) );
wxFAIL_MSG( fmt::format( "Parsing simulator value failed: {:s}", e.what() ) );
result.isOk = false;
}
@ -280,7 +280,7 @@ long SIM_VALUE_PARSER::MetricSuffixToExponent( std::string aMetricSuffix, NOTATI
break;
}
wxFAIL_MSG( wxString::Format( "Unknown simulator value suffix: '%s'", aMetricSuffix ) );
wxFAIL_MSG( fmt::format( "Unknown simulator value suffix: '{:s}'", aMetricSuffix ) );
return 0;
}
@ -359,7 +359,7 @@ std::string SIM_VALUE_PARSER::ExponentToMetricSuffix( double aExponent, long& aR
}
std::unique_ptr<SIM_VALUE> SIM_VALUE::Create( TYPE aType, wxString aString )
std::unique_ptr<SIM_VALUE> SIM_VALUE::Create( TYPE aType, std::string aString )
{
std::unique_ptr<SIM_VALUE> value = SIM_VALUE::Create( aType );
value->FromString( aString );
@ -387,7 +387,7 @@ std::unique_ptr<SIM_VALUE> SIM_VALUE::Create( TYPE aType )
}
void SIM_VALUE::operator=( const wxString& aString )
void SIM_VALUE::operator=( const std::string& aString )
{
FromString( aString );
}
@ -408,7 +408,7 @@ template SIM_VALUE_BOOL::SIM_VALUE_INST( const bool& aValue );
template SIM_VALUE_INT::SIM_VALUE_INST( const long& aValue );
template SIM_VALUE_FLOAT::SIM_VALUE_INST( const double& aValue );
template SIM_VALUE_COMPLEX::SIM_VALUE_INST( const std::complex<double>& aValue );
template SIM_VALUE_STRING::SIM_VALUE_INST( const wxString& aValue );
template SIM_VALUE_STRING::SIM_VALUE_INST( const std::string& aValue );
template <typename T>
@ -419,7 +419,7 @@ bool SIM_VALUE_INST<T>::HasValue() const
template <>
bool SIM_VALUE_BOOL::FromString( const wxString& aString, NOTATION aNotation )
bool SIM_VALUE_BOOL::FromString( const std::string& aString, NOTATION aNotation )
{
SIM_VALUE_PARSER::PARSE_RESULT parseResult = SIM_VALUE_PARSER::Parse( aString, aNotation );
m_value = std::nullopt;
@ -445,7 +445,7 @@ bool SIM_VALUE_BOOL::FromString( const wxString& aString, NOTATION aNotation )
template <>
bool SIM_VALUE_INT::FromString( const wxString& aString, NOTATION aNotation )
bool SIM_VALUE_INT::FromString( const std::string& aString, NOTATION aNotation )
{
SIM_VALUE_PARSER::PARSE_RESULT parseResult = SIM_VALUE_PARSER::Parse( aString, aNotation );
m_value = std::nullopt;
@ -468,7 +468,7 @@ bool SIM_VALUE_INT::FromString( const wxString& aString, NOTATION aNotation )
template <>
bool SIM_VALUE_FLOAT::FromString( const wxString& aString, NOTATION aNotation )
bool SIM_VALUE_FLOAT::FromString( const std::string& aString, NOTATION aNotation )
{
SIM_VALUE_PARSER::PARSE_RESULT parseResult = SIM_VALUE_PARSER::Parse( aString, aNotation );
m_value = std::nullopt;
@ -501,7 +501,7 @@ bool SIM_VALUE_FLOAT::FromString( const wxString& aString, NOTATION aNotation )
template <>
bool SIM_VALUE_COMPLEX::FromString( const wxString& aString,
bool SIM_VALUE_COMPLEX::FromString( const std::string& aString,
NOTATION aNotation )
{
// TODO
@ -519,7 +519,7 @@ bool SIM_VALUE_COMPLEX::FromString( const wxString& aString,
template <>
bool SIM_VALUE_STRING::FromString( const wxString& aString, NOTATION aNotation )
bool SIM_VALUE_STRING::FromString( const std::string& aString, NOTATION aNotation )
{
m_value = aString;
return true;
@ -527,11 +527,11 @@ bool SIM_VALUE_STRING::FromString( const wxString& aString, NOTATION aNotation )
template <typename T>
wxString SIM_VALUE_INST<T>::ToString( NOTATION aNotation ) const
std::string SIM_VALUE_INST<T>::ToString( NOTATION aNotation ) const
{
static_assert( std::is_same<T, std::vector<T>>::value );
wxString string = "";
std::string string = "";
for( auto it = m_value.cbegin(); it != m_value.cend(); it++ )
{
@ -544,7 +544,7 @@ wxString SIM_VALUE_INST<T>::ToString( NOTATION aNotation ) const
template <>
wxString SIM_VALUE_BOOL::ToString( NOTATION aNotation ) const
std::string SIM_VALUE_BOOL::ToString( NOTATION aNotation ) const
{
if( m_value )
return fmt::format( "{:d}", *m_value );
@ -554,7 +554,7 @@ wxString SIM_VALUE_BOOL::ToString( NOTATION aNotation ) const
template <>
wxString SIM_VALUE_INT::ToString( NOTATION aNotation ) const
std::string SIM_VALUE_INT::ToString( NOTATION aNotation ) const
{
if( m_value )
{
@ -578,7 +578,7 @@ wxString SIM_VALUE_INT::ToString( NOTATION aNotation ) const
template <>
wxString SIM_VALUE_FLOAT::ToString( NOTATION aNotation ) const
std::string SIM_VALUE_FLOAT::ToString( NOTATION aNotation ) const
{
if( m_value )
{
@ -597,7 +597,7 @@ wxString SIM_VALUE_FLOAT::ToString( NOTATION aNotation ) const
template <>
wxString SIM_VALUE_COMPLEX::ToString( NOTATION aNotation ) const
std::string SIM_VALUE_COMPLEX::ToString( NOTATION aNotation ) const
{
if( m_value )
return fmt::format( "{:g}+{:g}i", m_value->real(), m_value->imag() );
@ -607,7 +607,7 @@ wxString SIM_VALUE_COMPLEX::ToString( NOTATION aNotation ) const
template <>
wxString SIM_VALUE_STRING::ToString( NOTATION aNotation ) const
std::string SIM_VALUE_STRING::ToString( NOTATION aNotation ) const
{
if( m_value )
return *m_value;
@ -617,25 +617,21 @@ wxString SIM_VALUE_STRING::ToString( NOTATION aNotation ) const
template <typename T>
wxString SIM_VALUE_INST<T>::ToSimpleString() const
std::string SIM_VALUE_INST<T>::ToSimpleString() const
{
if( m_value )
{
wxString result = "";
result << *m_value;
return result;
}
return fmt::format( "{}", *m_value );
return "";
}
template <>
wxString SIM_VALUE_COMPLEX::ToSimpleString() const
std::string SIM_VALUE_COMPLEX::ToSimpleString() const
{
// TODO
/*wxString result = "";
/*std::string result = "";
result << *m_value;
return result;*/
@ -665,7 +661,7 @@ bool SIM_VALUE_BOOL::operator==( const bool& aOther ) const
template bool SIM_VALUE_INT::operator==( const long& aOther ) const;
template bool SIM_VALUE_FLOAT::operator==( const double& aOther ) const;
template bool SIM_VALUE_COMPLEX::operator==( const std::complex<double>& aOther ) const;
template bool SIM_VALUE_STRING::operator==( const wxString& aOther ) const;
template bool SIM_VALUE_STRING::operator==( const std::string& aOther ) const;
template <typename T>

View File

@ -65,7 +65,7 @@ public:
TYPE_COMPLEX_VECTOR
};
static std::unique_ptr<SIM_VALUE> Create( TYPE aType, wxString aString );
static std::unique_ptr<SIM_VALUE> Create( TYPE aType, std::string aString );
static std::unique_ptr<SIM_VALUE> Create( TYPE aType );
virtual ~SIM_VALUE() = default;
@ -73,16 +73,16 @@ public:
virtual bool HasValue() const = 0;
void operator=( const wxString& aString );
void operator=( const std::string& aString );
virtual bool operator==( const SIM_VALUE& aOther ) const = 0;
bool operator!=( const SIM_VALUE& aOther ) const;
virtual bool FromString( const wxString& aString, NOTATION aNotation = NOTATION::SI ) = 0;
virtual wxString ToString( NOTATION aNotation = NOTATION::SI ) const = 0;
wxString ToSpiceString() const { return ToString( NOTATION::SPICE ); }
virtual bool FromString( const std::string& aString, NOTATION aNotation = NOTATION::SI ) = 0;
virtual std::string ToString( NOTATION aNotation = NOTATION::SI ) const = 0;
std::string ToSpiceString() const { return ToString( NOTATION::SPICE ); }
// For parsers that don't accept strings with our suffixes.
virtual wxString ToSimpleString() const = 0;
virtual std::string ToSimpleString() const = 0;
};
@ -96,9 +96,9 @@ public:
bool HasValue() const override;
// TODO: Don't pass aNotation. Make a FromSpiceString() function instead.
bool FromString( const wxString& aString, NOTATION aNotation = NOTATION::SI ) override;
wxString ToString( NOTATION aNotation = NOTATION::SI ) const override;
wxString ToSimpleString() const override;
bool FromString( const std::string& aString, NOTATION aNotation = NOTATION::SI ) override;
std::string ToString( NOTATION aNotation = NOTATION::SI ) const override;
std::string ToSimpleString() const override;
void operator=( const T& aValue );
bool operator==( const T& aOther ) const;
@ -121,7 +121,7 @@ public:
const SIM_VALUE_INST<Type>& aRight );
private:
wxString getMetricSuffix();
std::string getMetricSuffix();
std::optional<T> m_value = std::nullopt;
};
@ -130,13 +130,13 @@ typedef SIM_VALUE_INST<bool> SIM_VALUE_BOOL;
typedef SIM_VALUE_INST<long> SIM_VALUE_INT;
typedef SIM_VALUE_INST<double> SIM_VALUE_FLOAT;
typedef SIM_VALUE_INST<std::complex<double>> SIM_VALUE_COMPLEX;
typedef SIM_VALUE_INST<wxString> SIM_VALUE_STRING;
typedef SIM_VALUE_INST<std::string> SIM_VALUE_STRING;
namespace SIM_VALUE_GRAMMAR
{
template <NOTATION Notation>
wxString allowedIntChars;
std::string allowedIntChars;
struct digits : plus<tao::pegtl::digit> {}; // For some reason it fails on just "digit".
@ -212,7 +212,7 @@ namespace SIM_VALUE_GRAMMAR
struct numberGrammar : must<number<ValueType, Notation>, tao::pegtl::eof> {};
bool IsValid( const wxString& aString,
bool IsValid( const std::string& aString,
SIM_VALUE::TYPE aValueType = SIM_VALUE::TYPE_FLOAT,
NOTATION aNotation = NOTATION::SI );
}