32#include <wx/strconv.h>
35#include <pegtl/contrib/parse_tree.hpp>
62 std::vector<std::pair<std::string, std::string>>* aQueue )
66 std::string fileContents =
SafeReadFile( aFilePath, wxS(
"r" ) ).ToStdString( wxConvUTF8 );
67 std::string filePath = aFilePath.ToStdString( wxConvUTF8 );
69 tao::pegtl::string_input<> in( fileContents, filePath );
75 for(
const auto& node : root->children )
79 aQueue->emplace_back( node->children.at( 0 )->string(), node->string() );
83 wxString lib =
m_library.m_pathResolver( node->children.at( 0 )->string(), aFilePath );
100 wxFAIL_MSG(
"Unhandled parse tree node" );
108 catch(
const tao::pegtl::parse_error& e )
112 catch(
const std::out_of_range& e )
114 aReporter.
Report( wxString::Format(
_(
"Error parsing SPICE library '%s': %s" ),
115 aFilePath, e.
what() ),
126 std::vector<std::pair<std::string, std::string>> modelQueue;
128 parseFile( aFilePath, aReporter, &modelQueue );
130 m_library.m_models.reserve( modelQueue.size() );
131 m_library.m_modelNames.reserve( modelQueue.size() );
133 for(
const auto& [
name, source] : modelQueue )
135 m_library.m_models.emplace_back(
nullptr );
140 [&](
int ii,
bool firstPass )
143 firstPass, aReporter );
149 auto results =
tp.submit_loop( 0, modelQueue.size(),
152 createModel( ii, true );
157 for(
int ii = 0; ii < (int) modelQueue.size(); ++ii )
160 createModel( ii,
false );
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual const char * what() const override
std::exception interface, returned as UTF-8
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
static std::unique_ptr< SIM_MODEL_SPICE > Create(const SIM_LIBRARY_SPICE &aLibrary, const std::string &aSpiceCode, bool aFirstPass, REPORTER &aReporter)
SIM_LIBRARY_SPICE & m_library
virtual void ReadFile(const wxString &aFilePath, REPORTER &firstPass)
void parseFile(const wxString &aFilePath, REPORTER &aReporter, std::vector< std::pair< std::string, std::string > > *aModelQueue)
must_if< error >::control< Rule > control
wxString SafeReadFile(const wxString &aFilePath, const wxString &aReadType)
Nominally opens a file and reads it into a string.
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
BS::priority_thread_pool thread_pool