Clearer naming.

This commit is contained in:
Jeff Young 2022-12-21 00:38:52 +00:00
parent e7e3f3bced
commit e64852c833
11 changed files with 88 additions and 90 deletions

View File

@ -287,7 +287,7 @@ set( EESCHEMA_SRCS
sim/sim_library_spice.cpp
sim/sim_library_kibis.cpp
sim/sim_lib_mgr.cpp
sim/sim_serde.cpp
sim/sim_model_serializer.cpp
sim/sim_model.cpp
sim/sim_model_behavioral.cpp
sim/sim_model_ideal.cpp

View File

@ -31,7 +31,6 @@
#include <sim/sim_model.h>
#include <sim/sim_model_kibis.h>
#include <sim/sim_model_raw_spice.h>
#include <sim/sim_serde.h>
#include <grid_tricks.h>
#include <widgets/grid_icon_text_helpers.h>
#include <widgets/std_bitmap_button.h>

View File

@ -891,21 +891,22 @@ std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( TYPE aType )
SIM_MODEL::SIM_MODEL( TYPE aType ) :
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ),
std::make_unique<SIM_SERDE>( *this ) )
std::make_unique<SIM_MODEL_SERIALIZER>( *this ) )
{
}
SIM_MODEL::SIM_MODEL( TYPE aType, std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator ) :
SIM_MODEL( aType, std::move( aSpiceGenerator ), std::make_unique<SIM_SERDE>( *this ) )
SIM_MODEL( aType, std::move( aSpiceGenerator ),
std::make_unique<SIM_MODEL_SERIALIZER>( *this ) )
{
}
SIM_MODEL::SIM_MODEL( TYPE aType, std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator,
std::unique_ptr<SIM_SERDE> aSerde ) :
std::unique_ptr<SIM_MODEL_SERIALIZER> aSerializer ) :
m_baseModel( nullptr ),
m_serde( std::move( aSerde ) ),
m_serializer( std::move( aSerializer ) ),
m_spiceGenerator( std::move( aSpiceGenerator ) ),
m_type( aType ),
m_isEnabled( true ),
@ -949,15 +950,15 @@ void SIM_MODEL::doReadDataFields( const std::vector<T>* aFields,
try
{
m_serde->ParseEnable( GetFieldValue( aFields, ENABLE_FIELD ) );
m_serializer->ParseEnable( GetFieldValue( aFields, ENABLE_FIELD ) );
CreatePins( aPins );
m_serde->ParsePins( GetFieldValue( aFields, PINS_FIELD ) );
m_serializer->ParsePins( GetFieldValue( aFields, PINS_FIELD ) );
std::string paramsField = GetFieldValue( aFields, PARAMS_FIELD );
if( !m_serde->ParseParams( paramsField ) )
m_serde->ParseValue( GetFieldValue( aFields, VALUE_FIELD ) );
if( !m_serializer->ParseParams( paramsField ) )
m_serializer->ParseValue( GetFieldValue( aFields, VALUE_FIELD ) );
}
catch( IO_ERROR& err )
{
@ -969,16 +970,16 @@ void SIM_MODEL::doReadDataFields( const std::vector<T>* aFields,
template <typename T>
void SIM_MODEL::doWriteFields( std::vector<T>& aFields ) const
{
SetFieldValue( aFields, DEVICE_TYPE_FIELD, m_serde->GenerateDevice() );
SetFieldValue( aFields, TYPE_FIELD, m_serde->GenerateType() );
SetFieldValue( aFields, DEVICE_TYPE_FIELD, m_serializer->GenerateDevice() );
SetFieldValue( aFields, TYPE_FIELD, m_serializer->GenerateType() );
SetFieldValue( aFields, ENABLE_FIELD, m_serde->GenerateEnable() );
SetFieldValue( aFields, PINS_FIELD, m_serde->GeneratePins() );
SetFieldValue( aFields, ENABLE_FIELD, m_serializer->GenerateEnable() );
SetFieldValue( aFields, PINS_FIELD, m_serializer->GeneratePins() );
SetFieldValue( aFields, PARAMS_FIELD, m_serde->GenerateParams() );
SetFieldValue( aFields, PARAMS_FIELD, m_serializer->GenerateParams() );
if( IsStoredInValue() )
SetFieldValue( aFields, VALUE_FIELD, m_serde->GenerateValue() );
SetFieldValue( aFields, VALUE_FIELD, m_serializer->GenerateValue() );
}
@ -1390,7 +1391,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
SIM_LIBRARY::MODEL model = libMgr.CreateModel( spiceLib, spiceModel.ToStdString(),
emptyFields, sourcePins );
spiceParams = wxString( model.model.GetBaseModel()->Serde().GenerateParams() );
spiceParams = wxString( model.model.GetBaseModel()->Serializer().GenerateParams() );
libraryModel = true;
if( pinMap.IsEmpty() )
@ -1399,7 +1400,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
// generate one from the symbol's pins
model.model.SIM_MODEL::CreatePins( sourcePins );
pinMap = wxString( model.model.Serde().GeneratePins() );
pinMap = wxString( model.model.Serializer().GeneratePins() );
if( pinMap.IsEmpty() )
pinMap = generateDefaultPinMapFromSymbol( sourcePins );
@ -1450,7 +1451,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
SIM_VALUE_GRAMMAR::NOTATION::SPICE );
}
spiceParams = wxString( model->Serde().GenerateParams() );
spiceParams = wxString( model->Serializer().GenerateParams() );
}
internalModel = true;
@ -1459,7 +1460,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
{
// Generate a default pin map from the SIM_MODEL's pins
model->CreatePins( sourcePins );
pinMap = wxString( model->Serde().GeneratePins() );
pinMap = wxString( model->Serializer().GeneratePins() );
}
}
catch( ... )

View File

@ -40,7 +40,7 @@
class SIM_LIBRARY;
class SPICE_GENERATOR;
class SIM_SERDE;
class SIM_MODEL_SERIALIZER;
class PROJECT;
@ -423,7 +423,7 @@ public:
const std::string& aValue );
const SPICE_GENERATOR& SpiceGenerator() const { return *m_spiceGenerator; }
const SIM_SERDE& Serde() const { return *m_serde; }
const SIM_MODEL_SERIALIZER& Serializer() const { return *m_serializer; }
// Move semantics.
@ -532,7 +532,7 @@ protected:
SIM_MODEL( TYPE aType );
SIM_MODEL( TYPE aType, std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator );
SIM_MODEL( TYPE aType, std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator,
std::unique_ptr<SIM_SERDE> aSerde );
std::unique_ptr<SIM_MODEL_SERIALIZER> aSerializer );
virtual void CreatePins( const std::vector<LIB_PIN*>& aSymbolPins );
@ -550,17 +550,17 @@ private:
virtual std::vector<std::string> getPinNames() const { return {}; }
protected:
std::vector<PARAM> m_params;
const SIM_MODEL* m_baseModel;
std::unique_ptr<SIM_SERDE> m_serde;
std::vector<PARAM> m_params;
const SIM_MODEL* m_baseModel;
std::unique_ptr<SIM_MODEL_SERIALIZER> m_serializer;
private:
std::unique_ptr<SPICE_GENERATOR> m_spiceGenerator;
std::unique_ptr<SPICE_GENERATOR> m_spiceGenerator;
const TYPE m_type;
std::vector<PIN> m_pins;
bool m_isEnabled;
bool m_isStoredInValue;
const TYPE m_type;
std::vector<PIN> m_pins;
bool m_isEnabled;
bool m_isStoredInValue;
};
#endif // SIM_MODEL_H

View File

@ -23,7 +23,6 @@
*/
#include <sim/sim_model_behavioral.h>
#include <sim/sim_serde.h>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/trim.hpp>

View File

@ -23,17 +23,16 @@
*/
#include <sim/sim_model_raw_spice.h>
#include <sim/sim_serde.h>
#include <sim/sim_model_serializer.h>
#include <boost/algorithm/string/predicate.hpp>
#include <fmt/core.h>
#include <pegtl.hpp>
#include <pegtl/contrib/parse_tree.hpp>
namespace SIM_MODEL_RAW_SPICE_PARSER
{
using namespace SIM_SERDE_GRAMMAR;
using namespace SIM_MODEL_SERIALIZER_GRAMMAR;
template <typename Rule> struct legacyPinSequenceSelector : std::false_type {};
template <> struct legacyPinSequenceSelector<legacyPinNumber> : std::true_type {};

View File

@ -22,7 +22,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <sim/sim_serde.h>
#include <sim/sim_model_serializer.h>
#include <fmt/core.h>
#include <pegtl.hpp>
#include <pegtl/contrib/parse_tree.hpp>
@ -32,9 +32,9 @@
#include <string_utils.h>
namespace SIM_SERDE_PARSER
namespace SIM_MODEL_SERIALIZER_PARSER
{
using namespace SIM_SERDE_GRAMMAR;
using namespace SIM_MODEL_SERIALIZER_GRAMMAR;
template <typename Rule> struct fieldParamValuePairsSelector : std::false_type {};
template <> struct fieldParamValuePairsSelector<param> : std::true_type {};
@ -52,19 +52,19 @@ namespace SIM_SERDE_PARSER
}
std::string SIM_SERDE::GenerateDevice() const
std::string SIM_MODEL_SERIALIZER::GenerateDevice() const
{
return m_model.GetDeviceInfo().fieldValue;
}
std::string SIM_SERDE::GenerateType() const
std::string SIM_MODEL_SERIALIZER::GenerateType() const
{
return m_model.GetTypeInfo().fieldValue;
}
std::string SIM_SERDE::GenerateValue() const
std::string SIM_MODEL_SERIALIZER::GenerateValue() const
{
const SIM_MODEL::PARAM& param = m_model.GetParamOverride( 0 );
std::string result = param.value->ToString();
@ -76,7 +76,7 @@ std::string SIM_SERDE::GenerateValue() const
}
std::string SIM_SERDE::GenerateParams() const
std::string SIM_MODEL_SERIALIZER::GenerateParams() const
{
std::string result;
bool isFirst = true;
@ -115,7 +115,7 @@ std::string SIM_SERDE::GenerateParams() const
}
std::string SIM_SERDE::GeneratePins() const
std::string SIM_MODEL_SERIALIZER::GeneratePins() const
{
std::string result;
@ -149,14 +149,14 @@ std::string SIM_SERDE::GeneratePins() const
}
std::string SIM_SERDE::GenerateEnable() const
std::string SIM_MODEL_SERIALIZER::GenerateEnable() const
{
return m_model.IsEnabled() ? "" : "0";
}
SIM_MODEL::TYPE SIM_SERDE::ParseDeviceAndType( const std::string& aDevice,
const std::string& aType )
SIM_MODEL::TYPE SIM_MODEL_SERIALIZER::ParseDeviceAndType( const std::string& aDevice,
const std::string& aType )
{
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
{
@ -171,20 +171,22 @@ SIM_MODEL::TYPE SIM_SERDE::ParseDeviceAndType( const std::string& aDevice,
}
void SIM_SERDE::ParseValue( const std::string& aValue )
void SIM_MODEL_SERIALIZER::ParseValue( const std::string& aValue )
{
try
{
tao::pegtl::string_input<> in( aValue, SIM_MODEL::VALUE_FIELD );
auto root = tao::pegtl::parse_tree::parse<SIM_SERDE_PARSER::fieldInferValueGrammar,
SIM_SERDE_PARSER::fieldInferValueSelector,
tao::pegtl::nothing,
SIM_SERDE_PARSER::control>( in );
auto root =
tao::pegtl::parse_tree::parse<SIM_MODEL_SERIALIZER_PARSER::fieldInferValueGrammar,
SIM_MODEL_SERIALIZER_PARSER::fieldInferValueSelector,
tao::pegtl::nothing,
SIM_MODEL_SERIALIZER_PARSER::control>
( in );
for( const auto& node : root->children )
{
if( node->is_type<SIM_SERDE_PARSER::number<SIM_VALUE::TYPE_FLOAT,
SIM_VALUE::NOTATION::SI>>()
if( node->is_type<SIM_MODEL_SERIALIZER_PARSER::number<SIM_VALUE::TYPE_FLOAT,
SIM_VALUE::NOTATION::SI>>()
&& node->string() != "" )
{
m_model.SetParamValue( 0, node->string() );
@ -202,7 +204,7 @@ void SIM_SERDE::ParseValue( const std::string& aValue )
}
bool SIM_SERDE::ParseParams( const std::string& aParams )
bool SIM_MODEL_SERIALIZER::ParseParams( const std::string& aParams )
{
tao::pegtl::string_input<> in( aParams, SIM_MODEL::PARAMS_FIELD );
std::unique_ptr<tao::pegtl::parse_tree::node> root;
@ -211,11 +213,10 @@ bool SIM_SERDE::ParseParams( const std::string& aParams )
{
// Using parse tree instead of actions because we don't care about performance that much,
// and having a tree greatly simplifies things.
root = tao::pegtl::parse_tree::parse<
SIM_SERDE_PARSER::fieldParamValuePairsGrammar,
SIM_SERDE_PARSER::fieldParamValuePairsSelector,
tao::pegtl::nothing,
SIM_SERDE_PARSER::control>
root = tao::pegtl::parse_tree::parse<SIM_MODEL_SERIALIZER_PARSER::fieldParamValuePairsGrammar,
SIM_MODEL_SERIALIZER_PARSER::fieldParamValuePairsSelector,
tao::pegtl::nothing,
SIM_MODEL_SERIALIZER_PARSER::control>
( in );
}
catch( const tao::pegtl::parse_error& e )
@ -230,12 +231,12 @@ bool SIM_SERDE::ParseParams( const std::string& aParams )
for( const auto& node : root->children )
{
if( node->is_type<SIM_SERDE_PARSER::param>() )
if( node->is_type<SIM_MODEL_SERIALIZER_PARSER::param>() )
paramName = node->string();
// TODO: Do something with number<SIM_VALUE::TYPE_INT, ...>.
// It doesn't seem too useful?
else if( node->is_type<SIM_SERDE_PARSER::quotedStringContent>()
|| node->is_type<SIM_SERDE_PARSER::unquotedString>() )
else if( node->is_type<SIM_MODEL_SERIALIZER_PARSER::quotedStringContent>()
|| node->is_type<SIM_MODEL_SERIALIZER_PARSER::unquotedString>() )
{
wxASSERT( paramName != "" );
// TODO: Shouldn't be named "...fromSpiceCode" here...
@ -245,7 +246,7 @@ bool SIM_SERDE::ParseParams( const std::string& aParams )
if( paramName == m_model.GetParam( 0 ).info.name )
isPrimaryValueSet = true;
}
else if( node->is_type<SIM_SERDE_PARSER::quotedString>() )
else if( node->is_type<SIM_MODEL_SERIALIZER_PARSER::quotedString>() )
{
std::string str = node->string();
@ -264,7 +265,7 @@ bool SIM_SERDE::ParseParams( const std::string& aParams )
}
void SIM_SERDE::ParsePins( const std::string& aPins )
void SIM_MODEL_SERIALIZER::ParsePins( const std::string& aPins )
{
if( aPins == "" )
return;
@ -274,10 +275,11 @@ void SIM_SERDE::ParsePins( const std::string& aPins )
try
{
root = tao::pegtl::parse_tree::parse<SIM_SERDE_PARSER::pinSequenceGrammar,
SIM_SERDE_PARSER::pinSequenceSelector,
root = tao::pegtl::parse_tree::parse<SIM_MODEL_SERIALIZER_PARSER::pinSequenceGrammar,
SIM_MODEL_SERIALIZER_PARSER::pinSequenceSelector,
tao::pegtl::nothing,
SIM_SERDE_PARSER::control>( in );
SIM_MODEL_SERIALIZER_PARSER::control>
( in );
for( const auto& node : root->children )
{
@ -296,7 +298,7 @@ void SIM_SERDE::ParsePins( const std::string& aPins )
}
void SIM_SERDE::ParseEnable( const std::string& aEnable )
void SIM_MODEL_SERIALIZER::ParseEnable( const std::string& aEnable )
{
if( aEnable == "" )
return;
@ -308,7 +310,7 @@ void SIM_SERDE::ParseEnable( const std::string& aEnable )
}
std::string SIM_SERDE::GenerateParamValuePair( const SIM_MODEL::PARAM& aParam ) const
std::string SIM_MODEL_SERIALIZER::GenerateParamValuePair( const SIM_MODEL::PARAM& aParam ) const
{
std::string name = aParam.info.name;
@ -317,8 +319,8 @@ std::string SIM_SERDE::GenerateParamValuePair( const SIM_MODEL::PARAM& aParam )
name = aParam.info.name.substr( 0, aParam.info.name.length() - 1 );
std::string value = aParam.value->ToString();
if( value == "" || value.find( " " ) != std::string::npos )
if( value == "" || value.find( ' ' ) != std::string::npos )
value = fmt::format( "\"{}\"", value );
return fmt::format( "{}={}", name, value );

View File

@ -22,13 +22,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef SIM_SERDE_H
#define SIM_SERDE_H
#ifndef SIM_MODEL_SERIALIZER_H
#define SIM_MODEL_SERIALIZER_H
#include <sim/sim_model.h>
namespace SIM_SERDE_GRAMMAR
namespace SIM_MODEL_SERIALIZER_GRAMMAR
{
using namespace SIM_VALUE_GRAMMAR;
@ -109,9 +109,9 @@ namespace SIM_SERDE_GRAMMAR
/**
* SerDe = Serializer-Deserializer
* Serializes/deserializes a SIM_MODEL for storage in LIB_FIELDs/SCH_FIELDs.
*/
class SIM_SERDE
class SIM_MODEL_SERIALIZER
{
public:
static constexpr auto REFERENCE_FIELD = "Reference";
@ -123,8 +123,8 @@ public:
static constexpr auto PARAMS_FIELD = "Sim.Params";
static constexpr auto ENABLE_FIELD = "Sim.Enable";
virtual ~SIM_SERDE() = default;
SIM_SERDE( SIM_MODEL& aModel ) : m_model( aModel ) {}
virtual ~SIM_MODEL_SERIALIZER() = default;
SIM_MODEL_SERIALIZER( SIM_MODEL& aModel ) : m_model( aModel ) {}
std::string GenerateDevice() const;
std::string GenerateType() const;
@ -147,4 +147,4 @@ private:
SIM_MODEL& m_model;
};
#endif // SIM_SERDE_H
#endif // SIM_MODEL_SERIALIZER_H

View File

@ -212,19 +212,18 @@ std::string SPICE_GENERATOR_SOURCE::getParamValueString( const std::string& aPar
}
std::string SIM_SERDE_SOURCE::GenerateParamValuePair( const SIM_MODEL::PARAM& aParam ) const
std::string SIM_MODEL_SOURCE_SERIALIZER::GenerateParamValuePair( const SIM_MODEL::PARAM& aParam ) const
{
if( aParam.value->ToString() == "0" )
return "";
return SIM_SERDE::GenerateParamValuePair( aParam );
return SIM_MODEL_SERIALIZER::GenerateParamValuePair( aParam );
}
SIM_MODEL_SOURCE::SIM_MODEL_SOURCE( TYPE aType )
: SIM_MODEL( aType,
std::make_unique<SPICE_GENERATOR_SOURCE>( *this ),
std::make_unique<SIM_SERDE_SOURCE>( *this ) )
SIM_MODEL_SOURCE::SIM_MODEL_SOURCE( TYPE aType ) :
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_SOURCE>( *this ),
std::make_unique<SIM_MODEL_SOURCE_SERIALIZER>( *this ) )
{
for( const SIM_MODEL::PARAM::INFO& paramInfo : makeParamInfos( aType ) )
AddParam( paramInfo );

View File

@ -26,13 +26,13 @@
#define SIM_MODEL_SOURCE_H
#include <sim/sim_model.h>
#include <sim/sim_serde.h>
#include <sim/sim_model_serializer.h>
#include <sim/spice_generator.h>
namespace SIM_MODEL_SOURCE_GRAMMAR
{
using namespace SIM_SERDE_GRAMMAR;
using namespace SIM_MODEL_SERIALIZER_GRAMMAR;
struct pwlSep : plus<space> {};
struct pwlValues : seq<opt<number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>>,
@ -59,10 +59,10 @@ private:
};
class SIM_SERDE_SOURCE : public SIM_SERDE
class SIM_MODEL_SOURCE_SERIALIZER : public SIM_MODEL_SERIALIZER
{
public:
using SIM_SERDE::SIM_SERDE;
using SIM_MODEL_SERIALIZER::SIM_MODEL_SERIALIZER;
protected:
std::string GenerateParamValuePair( const SIM_MODEL::PARAM& aParam ) const override;

View File

@ -27,7 +27,6 @@
#include <sim/sim_model.h>
#include <sim/spice_generator.h>
#include <sim/sim_serde.h>
class SPICE_GENERATOR_SWITCH : public SPICE_GENERATOR