From 4ae2225b6df8bd1808101507b8831bb0187dc7b7 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Fri, 16 Sep 2022 06:11:14 +0200 Subject: [PATCH] Sim: Replace all wxStrings with std::strings in SIM_VALUE --- eeschema/sch_sheet_path.cpp | 3 +- eeschema/sim/sim_model.cpp | 5 +-- eeschema/sim/sim_model_source.cpp | 2 +- eeschema/sim/sim_model_spice.cpp | 2 +- eeschema/sim/sim_property.cpp | 2 +- eeschema/sim/sim_value.cpp | 58 ++++++++++++++----------------- eeschema/sim/sim_value.h | 26 +++++++------- 7 files changed, 48 insertions(+), 50 deletions(-) diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 689dd77dc3..dd92a65487 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -1232,7 +1232,8 @@ void SCH_SHEET_LIST::MigrateSimModelNameFields() std::unique_ptr 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. diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index 9e02b120c6..deea812e71 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -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 readLevel = SIM_VALUE::Create( SIM_VALUE::TYPE_INT, aLevel ); + std::unique_ptr readLevel = SIM_VALUE::Create( SIM_VALUE::TYPE_INT, + aLevel.ToStdString() ); for( TYPE type : TYPE_ITERATOR() ) { diff --git a/eeschema/sim/sim_model_source.cpp b/eeschema/sim/sim_model_source.cpp index 5b02603b0c..599659a03c 100644 --- a/eeschema/sim/sim_model_source.cpp +++ b/eeschema/sim/sim_model_source.cpp @@ -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 root; diff --git a/eeschema/sim/sim_model_spice.cpp b/eeschema/sim/sim_model_spice.cpp index 11d2c22cc1..6c8444fd21 100644 --- a/eeschema/sim/sim_model_spice.cpp +++ b/eeschema/sim/sim_model_spice.cpp @@ -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 ); } diff --git a/eeschema/sim/sim_property.cpp b/eeschema/sim/sim_property.cpp index 40dfd9f62e..62c397b011 100644 --- a/eeschema/sim/sim_property.cpp +++ b/eeschema/sim/sim_property.cpp @@ -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 ); } diff --git a/eeschema/sim/sim_value.cpp b/eeschema/sim/sim_value.cpp index d299fff84f..330d8cedb7 100644 --- a/eeschema/sim/sim_value.cpp +++ b/eeschema/sim/sim_value.cpp @@ -107,7 +107,7 @@ namespace SIM_VALUE_PARSER std::optional 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 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::Create( TYPE aType, wxString aString ) +std::unique_ptr SIM_VALUE::Create( TYPE aType, std::string aString ) { std::unique_ptr value = SIM_VALUE::Create( aType ); value->FromString( aString ); @@ -387,7 +387,7 @@ std::unique_ptr 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& aValue ); -template SIM_VALUE_STRING::SIM_VALUE_INST( const wxString& aValue ); +template SIM_VALUE_STRING::SIM_VALUE_INST( const std::string& aValue ); template @@ -419,7 +419,7 @@ bool SIM_VALUE_INST::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 -wxString SIM_VALUE_INST::ToString( NOTATION aNotation ) const +std::string SIM_VALUE_INST::ToString( NOTATION aNotation ) const { static_assert( std::is_same>::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::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 -wxString SIM_VALUE_INST::ToSimpleString() const +std::string SIM_VALUE_INST::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& aOther ) const; -template bool SIM_VALUE_STRING::operator==( const wxString& aOther ) const; +template bool SIM_VALUE_STRING::operator==( const std::string& aOther ) const; template diff --git a/eeschema/sim/sim_value.h b/eeschema/sim/sim_value.h index bdfa016b32..4d9b1132fe 100644 --- a/eeschema/sim/sim_value.h +++ b/eeschema/sim/sim_value.h @@ -65,7 +65,7 @@ public: TYPE_COMPLEX_VECTOR }; - static std::unique_ptr Create( TYPE aType, wxString aString ); + static std::unique_ptr Create( TYPE aType, std::string aString ); static std::unique_ptr 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& aRight ); private: - wxString getMetricSuffix(); + std::string getMetricSuffix(); std::optional m_value = std::nullopt; }; @@ -130,13 +130,13 @@ typedef SIM_VALUE_INST SIM_VALUE_BOOL; typedef SIM_VALUE_INST SIM_VALUE_INT; typedef SIM_VALUE_INST SIM_VALUE_FLOAT; typedef SIM_VALUE_INST> SIM_VALUE_COMPLEX; -typedef SIM_VALUE_INST SIM_VALUE_STRING; +typedef SIM_VALUE_INST SIM_VALUE_STRING; namespace SIM_VALUE_GRAMMAR { template - wxString allowedIntChars; + std::string allowedIntChars; struct digits : plus {}; // For some reason it fails on just "digit". @@ -212,7 +212,7 @@ namespace SIM_VALUE_GRAMMAR struct numberGrammar : must, 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 ); }