KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_library.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022 Mikolaj Wielgus
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <sim/sim_library.h>
24#include <boost/algorithm/string/case_conv.hpp>
26#include <macros.h>
27
28
29std::unique_ptr<SIM_LIBRARY>
30SIM_LIBRARY::Create( const wxString& aFilePath, bool aForceFullParse, REPORTER& aReporter,
31 const std::function<wxString( const wxString&, const wxString& )>& aResolver )
32{
33 std::unique_ptr<SIM_LIBRARY> library;
34
35 if( aFilePath.EndsWith( FILEEXT::IbisFileExtension ) )
36 library = std::make_unique<SIM_LIBRARY_IBIS>();
37 else
38 library = std::make_unique<SIM_LIBRARY_SPICE>( aForceFullParse );
39
40 library->m_pathResolver = aResolver;
41 library->ReadFile( aFilePath, aReporter );
42
43 return library;
44}
45
46
47void SIM_LIBRARY::ReadFile( const wxString& aFilePath, REPORTER& aReporter )
48{
49 m_filePath = aFilePath;
50}
51
52
53SIM_MODEL* SIM_LIBRARY::FindModel( const std::string& aModelName ) const
54{
55 std::string lowerName = boost::to_lower_copy( aModelName );
56
57 for( int i = 0; i < static_cast<int>( m_modelNames.size() ); ++i )
58 {
59 if( boost::to_lower_copy( m_modelNames.at( i ) ) == lowerName )
60 return m_models.at( i ).get();
61 }
62
63 return nullptr;
64}
65
66
67std::vector<SIM_LIBRARY::MODEL> SIM_LIBRARY::GetModels() const
68{
69 std::vector<MODEL> result;
70
71 for( int i = 0; i < static_cast<int>( m_modelNames.size() ); ++i )
72 result.push_back( { m_modelNames.at( i ), *m_models.at( i ) } );
73
74 return result;
75}
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:71
std::vector< MODEL > GetModels() const
static std::unique_ptr< SIM_LIBRARY > Create(const wxString &aFilePath, bool aForceFullParse, REPORTER &aReporter, const std::function< wxString(const wxString &, const wxString &)> &aResolver)
Read library from a source file (e.g.
virtual void ReadFile(const wxString &aFilePath, REPORTER &aReporter)=0
Read library from a source file.
std::vector< std::string > m_modelNames
Definition sim_library.h:73
SIM_MODEL * FindModel(const std::string &aModelName) const
std::vector< std::unique_ptr< SIM_MODEL > > m_models
Definition sim_library.h:74
std::string m_filePath
Definition sim_library.h:78
static const std::string IbisFileExtension
This file contains miscellaneous commonly used macros and functions.
wxString result
Test unit parsing edge cases and error handling.
Definition of file extensions used in Kicad.