Sim: Remove vestiges of (de)serialization from SIM_MODEL
This commit is contained in:
parent
490069c5e6
commit
f33cd3e383
|
@ -980,7 +980,7 @@ void SIM_MODEL::WriteInferredDataFields( std::vector<T>& aFields, const std::str
|
|||
std::string value = aValue;
|
||||
|
||||
if( value == "" )
|
||||
value = GenerateValueField( "=" );
|
||||
value = m_serde->GenerateValue();
|
||||
|
||||
SetFieldValue( aFields, VALUE_FIELD, value );
|
||||
SetFieldValue( aFields, DEVICE_TYPE_FIELD, "" );
|
||||
|
@ -990,46 +990,16 @@ void SIM_MODEL::WriteInferredDataFields( std::vector<T>& aFields, const std::str
|
|||
}
|
||||
|
||||
|
||||
std::string SIM_MODEL::GenerateValueField( const std::string& aPairSeparator ) const
|
||||
{
|
||||
return m_serde->GenerateValue();
|
||||
}
|
||||
|
||||
|
||||
std::string SIM_MODEL::GenerateParamsField( const std::string& aPairSeparator ) const
|
||||
{
|
||||
return m_serde->GenerateParams();
|
||||
}
|
||||
|
||||
|
||||
void SIM_MODEL::ParseParamsField( const std::string& aParamsField )
|
||||
{
|
||||
m_serde->ParseParams( aParamsField );
|
||||
}
|
||||
|
||||
|
||||
void SIM_MODEL::ParsePinsField( unsigned aSymbolPinCount, const std::string& aPinsField )
|
||||
{
|
||||
CreatePins( aSymbolPinCount );
|
||||
|
||||
m_serde->ParsePins( aPinsField );
|
||||
}
|
||||
|
||||
|
||||
void SIM_MODEL::ParseEnableField( const std::string& aEnableField )
|
||||
{
|
||||
m_serde->ParseEnable( aEnableField );
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void SIM_MODEL::doReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields )
|
||||
{
|
||||
ParseEnableField( GetFieldValue( aFields, ENABLE_FIELD ) );
|
||||
ParsePinsField( aSymbolPinCount, GetFieldValue( aFields, PINS_FIELD ) );
|
||||
m_serde->ParseEnable( GetFieldValue( aFields, ENABLE_FIELD ) );
|
||||
|
||||
CreatePins( aSymbolPinCount );
|
||||
m_serde->ParsePins( GetFieldValue( aFields, PINS_FIELD ) );
|
||||
|
||||
if( GetFieldValue( aFields, PARAMS_FIELD ) != "" )
|
||||
ParseParamsField( GetFieldValue( aFields, PARAMS_FIELD ) );
|
||||
m_serde->ParseParams( GetFieldValue( aFields, PARAMS_FIELD ) );
|
||||
else
|
||||
InferredReadDataFields( aSymbolPinCount, aFields );
|
||||
}
|
||||
|
@ -1060,51 +1030,11 @@ void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount, const std::vec
|
|||
template <typename T>
|
||||
void SIM_MODEL::doWriteFields( std::vector<T>& aFields ) const
|
||||
{
|
||||
SetFieldValue( aFields, DEVICE_TYPE_FIELD, generateDeviceTypeField() );
|
||||
SetFieldValue( aFields, TYPE_FIELD, generateTypeField() );
|
||||
SetFieldValue( aFields, PINS_FIELD, generatePinsField() );
|
||||
SetFieldValue( aFields, PARAMS_FIELD, GenerateParamsField( " " ) );
|
||||
SetFieldValue( aFields, ENABLE_FIELD, generateEnableField() );
|
||||
}
|
||||
|
||||
|
||||
std::string SIM_MODEL::generateDeviceTypeField() const
|
||||
{
|
||||
return DeviceTypeInfo( TypeInfo( m_type ).deviceType ).fieldValue;
|
||||
}
|
||||
|
||||
|
||||
std::string SIM_MODEL::generateTypeField() const
|
||||
{
|
||||
return TypeInfo( m_type ).fieldValue;
|
||||
}
|
||||
|
||||
|
||||
std::string SIM_MODEL::generatePinsField() const
|
||||
{
|
||||
std::string result = "";
|
||||
bool isFirst = true;
|
||||
|
||||
for( const PIN& pin : GetPins() )
|
||||
{
|
||||
if( isFirst )
|
||||
isFirst = false;
|
||||
else
|
||||
result.append( " " );
|
||||
|
||||
if( pin.symbolPinNumber == "" )
|
||||
result.append( "~" );
|
||||
else
|
||||
result.append( pin.symbolPinNumber ); // Note that it's numbered from 1.
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string SIM_MODEL::generateEnableField() const
|
||||
{
|
||||
return m_isEnabled ? "" : "0";
|
||||
SetFieldValue( aFields, DEVICE_TYPE_FIELD, m_serde->GenerateDevice() );
|
||||
SetFieldValue( aFields, TYPE_FIELD, m_serde->GenerateType() );
|
||||
SetFieldValue( aFields, PINS_FIELD, m_serde->GeneratePins() );
|
||||
SetFieldValue( aFields, PARAMS_FIELD, m_serde->GenerateParams() );
|
||||
SetFieldValue( aFields, ENABLE_FIELD, m_serde->GenerateEnable() );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -531,15 +531,9 @@ protected:
|
|||
template <typename T>
|
||||
void WriteInferredDataFields( std::vector<T>& aFields, const std::string& aValue = "" ) const;
|
||||
|
||||
std::string GenerateValueField( const std::string& aPairSeparator ) const;
|
||||
std::string GenerateParamsField( const std::string& aPairSeparator ) const;
|
||||
void ParseParamsField( const std::string& aParamsField );
|
||||
|
||||
void ParsePinsField( unsigned aSymbolPinCount, const std::string& aPinsField );
|
||||
void ParseEnableField( const std::string& aDisabledField );
|
||||
|
||||
template <typename T>
|
||||
void InferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields );
|
||||
|
||||
std::vector<PARAM> m_params;
|
||||
const SIM_MODEL* m_baseModel;
|
||||
std::unique_ptr<SIM_SERDE> m_serde;
|
||||
|
@ -557,14 +551,6 @@ private:
|
|||
template <typename T>
|
||||
void doWriteFields( std::vector<T>& aFields ) const;
|
||||
|
||||
std::string generateDeviceTypeField() const;
|
||||
std::string generateTypeField() const;
|
||||
|
||||
std::string generatePinsField() const;
|
||||
std::string generateEnableField() const;
|
||||
|
||||
std::string parseFieldFloatValue( std::string aFieldFloatValue );
|
||||
|
||||
virtual bool requiresSpiceModelLine() const;
|
||||
|
||||
virtual std::vector<std::string> getPinNames() const { return {}; }
|
||||
|
|
|
@ -148,7 +148,7 @@ template <typename T>
|
|||
void SIM_MODEL_BEHAVIORAL::inferredReadDataFields( unsigned aSymbolPinCount,
|
||||
const std::vector<T>* aFields )
|
||||
{
|
||||
ParsePinsField( aSymbolPinCount, GetFieldValue( aFields, PINS_FIELD ) );
|
||||
m_serde->ParsePins( GetFieldValue( aFields, PINS_FIELD ) );
|
||||
|
||||
if( ( m_serde->InferTypeFromRefAndValue( GetFieldValue( aFields, REFERENCE_FIELD ),
|
||||
GetFieldValue( aFields, VALUE_FIELD ),
|
||||
|
|
|
@ -208,7 +208,9 @@ std::string SIM_SERDE_SOURCE::GenerateParamValuePair( const SIM_MODEL::PARAM& aP
|
|||
|
||||
|
||||
SIM_MODEL_SOURCE::SIM_MODEL_SOURCE( TYPE aType )
|
||||
: SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_SOURCE>( *this ) )
|
||||
: SIM_MODEL( aType,
|
||||
std::make_unique<SPICE_GENERATOR_SOURCE>( *this ),
|
||||
std::make_unique<SIM_SERDE_SOURCE>( *this ) )
|
||||
{
|
||||
for( const SIM_MODEL::PARAM::INFO& paramInfo : makeParamInfos( aType ) )
|
||||
AddParam( paramInfo );
|
||||
|
@ -268,9 +270,11 @@ void SIM_MODEL_SOURCE::inferredWriteDataFields( std::vector<T>& aFields ) const
|
|||
std::string value;
|
||||
|
||||
if( GetTypeInfo().fieldValue != "" )
|
||||
{
|
||||
value = fmt::format( "{} {}",
|
||||
GetTypeInfo().fieldValue,
|
||||
GetFieldValue( &aFields, PARAMS_FIELD ) );
|
||||
}
|
||||
else
|
||||
value = fmt::format( "{}", GetFieldValue( &aFields, PARAMS_FIELD ) );
|
||||
|
||||
|
|
|
@ -61,6 +61,9 @@ private:
|
|||
|
||||
class SIM_SERDE_SOURCE : public SIM_SERDE
|
||||
{
|
||||
public:
|
||||
using SIM_SERDE::SIM_SERDE;
|
||||
|
||||
protected:
|
||||
std::string GenerateParamValuePair( const SIM_MODEL::PARAM& aParam ) const override;
|
||||
};
|
||||
|
|
|
@ -132,8 +132,6 @@ SIM_MODEL_SWITCH::SIM_MODEL_SWITCH( TYPE aType ) :
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SWITCH::makeSwVParamInfos()
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
|
|
|
@ -81,7 +81,12 @@ std::string SIM_SERDE::GenerateValue() const
|
|||
if( param.value->ToString() == "" )
|
||||
continue;
|
||||
|
||||
result.append( fmt::format( " {}", GenerateParamValuePair( param ) ) );
|
||||
std::string paramValuePair = GenerateParamValuePair( param );
|
||||
|
||||
if( paramValuePair == "" )
|
||||
continue; // Prevent adding empty spaces.
|
||||
|
||||
result.append( fmt::format( " {}", paramValuePair ) );
|
||||
}
|
||||
|
||||
if( result == "" )
|
||||
|
@ -94,6 +99,7 @@ std::string SIM_SERDE::GenerateValue() const
|
|||
std::string SIM_SERDE::GenerateParams() const
|
||||
{
|
||||
std::string result;
|
||||
bool isFirst = true;
|
||||
|
||||
for( int i = 0; i < m_model.GetParamCount(); ++i )
|
||||
{
|
||||
|
@ -102,10 +108,17 @@ std::string SIM_SERDE::GenerateParams() const
|
|||
if( param.value->ToString() == "" )
|
||||
continue;
|
||||
|
||||
if( i != 0 )
|
||||
std::string paramValuePair = GenerateParamValuePair( param );
|
||||
|
||||
if( paramValuePair == "" )
|
||||
continue; // Prevent adding empty spaces.
|
||||
|
||||
if( isFirst ) // Don't add a space at the beginning.
|
||||
isFirst = false;
|
||||
else
|
||||
result.append( " " );
|
||||
|
||||
result.append( GenerateParamValuePair( param ) );
|
||||
result.append( paramValuePair );
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue