31#include <boost/algorithm/string/case_conv.hpp>
32#include <boost/algorithm/string/predicate.hpp>
34#include <pegtl/contrib/parse_tree.hpp>
55 const std::string& aSpiceCode )
57 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
58 std::unique_ptr<tao::pegtl::parse_tree::node> root;
68 catch(
const tao::pegtl::parse_error& e )
70 wxLogDebug(
"%s", e.what() );
71 return SIM_MODEL::TYPE::NONE;
74 for(
const auto& node : root->children )
78 std::string
modelName = node->children.at( 0 )->string();
79 std::string akoName = node->children.at( 1 )->string();
85 _(
"Could not find model '%s' to copy for \"A Kind Of\" model '%s'" ),
94 std::string paramName;
95 std::string typeString;
99 for(
const auto& subnode : node->children )
107 typeString = subnode->string();
110 if( type != SIM_MODEL::TYPE::RAWSPICE )
115 paramName = subnode->string();
119 wxASSERT( paramName !=
"" );
121 if( paramName ==
"level" )
122 level = subnode->string();
123 else if( paramName ==
"version" )
124 version = subnode->string();
128 wxFAIL_MSG(
"Unhandled parse tree subnode" );
129 return SIM_MODEL::TYPE::NONE;
140 return SIM_MODEL::TYPE::SUBCKT;
143 wxFAIL_MSG(
"Unhandled parse tree node" );
144 return SIM_MODEL::TYPE::NONE;
148 wxFAIL_MSG(
"Could not derive type from Spice code" );
149 return SIM_MODEL::TYPE::NONE;
154 const std::string& aSpiceCode )
159 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
160 std::unique_ptr<tao::pegtl::parse_tree::node> root;
170 catch( tao::pegtl::parse_error& e )
175 for(
const auto& node : root->children )
179 std::string
modelName = node->children.at( 0 )->string();
180 std::string akoName = node->children.at( 1 )->string();
187 _(
"Could not find model '%s' to copy for \"A Kind Of\" model '%s'" ),
192 for(
int i = 0; i < static_cast<int>( sourceModel->
GetParamCount() ); ++i )
195 std::string paramName;
197 for(
const auto& subnode : node->children )
209 paramName = subnode->string();
213 wxASSERT( paramName !=
"" );
219 wxFAIL_MSG(
"Unhandled parse tree subnode" );
226 std::string paramName;
228 for(
const auto& subnode : node->children )
240 paramName = subnode->string();
244 wxASSERT( paramName !=
"" );
250 wxFAIL_MSG(
"Unhandled parse tree subnode" );
256 wxFAIL_MSG(
"Unhandled parse tree node" );
265 const std::string& aLevel,
266 const std::string& aVersion,
267 bool aSkipDefaultLevel )
269 wxString input_level = wxString( aLevel ).BeforeFirst(
'.' );
270 wxString input_type( aTypeString );
274 input_type.UpperCase();
276 if( input_type.StartsWith( wxS(
"VDMOS" ) ) )
279 pchan = input_type.Contains( wxS(
"PCHAN" ) );
282 for( SIM_MODEL::TYPE candidate : SIM_MODEL::TYPE_ITERATOR() )
289 if( candidate_type.IsEmpty() )
292 if( candidate_type.StartsWith( wxS(
"VDMOS" ) ) && vdmos )
294 if( vdmos && pchan && candidate_type.EndsWith( wxS(
"PCHAN" ) ) )
296 else if( vdmos && !pchan && candidate_type.EndsWith( wxS(
"NCHAN" ) ) )
299 else if( input_type.StartsWith( candidate_type ) )
301 if( candidate_version != aVersion )
304 if( candidate_level == input_level )
307 if( aSkipDefaultLevel )
310 if( candidate_isDefaultLevel && aLevel ==
"" )
317 return SIM_MODEL::TYPE::RAWSPICE;
SIM_MODEL * FindModel(const std::string &aModelName) const
virtual void SetParamFromSpiceCode(const std::string &aParamName, const std::string &aParamValue, SIM_VALUE_GRAMMAR::NOTATION aNotation=SIM_VALUE_GRAMMAR::NOTATION::SPICE)
static SPICE_INFO SpiceInfo(TYPE aType)
virtual const PARAM & GetParam(unsigned aParamIndex) const
int GetParamCount() const
void SetParamValue(int aParamIndex, const std::string &aValue, SIM_VALUE::NOTATION aNotation=SIM_VALUE::NOTATION::SI)
virtual void ReadModel(const SIM_LIBRARY_SPICE &aLibrary, const std::string &aSpiceCode)
static SIM_MODEL::TYPE ReadTypeFromSpiceStrings(const std::string &aTypeString, const std::string &aLevel="", const std::string &aVersion="", bool aSkipDefaultLevel=true)
SIM_MODEL_SPICE & m_model
static SIM_MODEL::TYPE ReadType(const SIM_LIBRARY_SPICE &aLibrary, const std::string &aSpiceCode)
#define THROW_IO_ERROR(msg)
must_if< error >::control< Rule > control