BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_NetlistParser.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_CL_NETLISTPARSER_HPP
13#define BELFEM_CL_NETLISTPARSER_HPP
14
15#include "typedefs.hpp"
16#include "cl_Cell.hpp"
17#include "cl_Map.hpp"
18
19namespace belfem
20{
21 namespace electronics
22 {
23//-----------------------------------------------------------------------------
24
56
57//-----------------------------------------------------------------------------
58
63 {
64 string mName; // case-folded model name
65 string mType; // case-folded type token ( "d" )
68 string mCard;
69 };
70
71//-----------------------------------------------------------------------------
72
78 {
79 string mKeyword; // without the dot ( "tran" )
82 string mCard;
83 };
84
85//-----------------------------------------------------------------------------
86
92 {
93 string mKind; // case-folded ( "order" )
94 Cell< string > mArgs; // positional tokens
97 string mCard;
98 };
99
100//-----------------------------------------------------------------------------
101
144 {
145 string mSource; // path or "<memory>", for errors
146 string mTitle;
147 Cell< NetlistElement > mElements;
148 Cell< NetlistModel > mModels;
149 Cell< NetlistControl > mControls;
150 Cell< NetlistDirective > mDirectives;
151 Cell< string > mNodeNames; // first appearance, folded
152 bool mHasEnd = false;
153
154//-----------------------------------------------------------------------------
155 public:
156//-----------------------------------------------------------------------------
157
161 NetlistParser( const string & aPath );
162
167 NetlistParser( const Cell< string > & aLines,
168 const string & aSource = "<memory>" );
169
170 ~NetlistParser() = default;
171
172//-----------------------------------------------------------------------------
173
174 const string &
175 title() const
176 {
177 return mTitle;
178 }
179
183 const string &
184 source() const
185 {
186 return mSource;
187 }
188
190 elements() const
191 {
192 return mElements;
193 }
194
196 models() const
197 {
198 return mModels;
199 }
200
202 controls() const
203 {
204 return mControls;
205 }
206
209 {
210 return mDirectives;
211 }
212
218 const Cell< string > &
220 {
221 return mNodeNames;
222 }
223
227 bool
228 has_end() const
229 {
230 return mHasEnd;
231 }
232
233//-----------------------------------------------------------------------------
234 private:
235//-----------------------------------------------------------------------------
236
237 void
238 parse( const Cell< string > & aLines );
239
241 string
242 strip_eol_comment( const string & aLine ) const;
243
245 void
246 classify_card( const string & aCard,
247 const index_t aLine );
248
249 void
250 classify_control_card( const Cell< string > & aTokens,
251 const string & aCard,
252 const index_t aLine );
253
254 void
255 classify_element_card( const Cell< string > & aTokens,
256 const string & aCard,
257 const index_t aLine );
258
259 void
260 parse_directive( const string & aPayload,
261 const index_t aLine );
262
265 void
266 tokenize( const string & aCard,
267 Cell< string > & aTokens ) const;
268
272 void
273 store_kwarg( const string & aToken,
274 const string & aCard,
275 const index_t aLine,
276 Map< string, string > & aKwargs ) const;
277
279 void
280 collect_node( const string & aName );
281
282//-----------------------------------------------------------------------------
283 };
284
285//-----------------------------------------------------------------------------
286 }
287}
288
289#endif //BELFEM_CL_NETLISTPARSER_HPP
const string & title() const
Definition cl_NetlistParser.hpp:175
const Cell< NetlistModel > & models() const
Definition cl_NetlistParser.hpp:196
const Cell< NetlistDirective > & directives() const
Definition cl_NetlistParser.hpp:208
const string & source() const
the path or "<memory>" label errors are reported under
Definition cl_NetlistParser.hpp:184
const Cell< string > & node_names() const
distinct node names in order of first appearance – the factory's packing order ( ground moves to the ...
Definition cl_NetlistParser.hpp:219
const Cell< NetlistElement > & elements() const
Definition cl_NetlistParser.hpp:190
bool has_end() const
true if the deck carried an explicit .end
Definition cl_NetlistParser.hpp:228
const Cell< NetlistControl > & controls() const
Definition cl_NetlistParser.hpp:202
NetlistParser(const string &aPath)
lex a netlist file from disk
Definition cl_NetlistParser.cpp:100
Definition cl_Capacitor.cpp:18
USER GUIDES:
Definition cl_Capacitor.cpp:16
uint32_t index_t
Definition typedefs.hpp:52
one supported control card ( only ".tran" today; ".end" sets a flag instead of a record )
Definition cl_NetlistParser.hpp:78
string mKeyword
Definition cl_NetlistParser.hpp:79
index_t mLine
Definition cl_NetlistParser.hpp:81
Cell< string > mArgs
Definition cl_NetlistParser.hpp:80
string mCard
Definition cl_NetlistParser.hpp:82
one "* belfem:" extension directive ( plan §5, Option A ): superconductor, timed switch,...
Definition cl_NetlistParser.hpp:92
Map< string, string > mKwargs
Definition cl_NetlistParser.hpp:95
string mKind
Definition cl_NetlistParser.hpp:93
index_t mLine
Definition cl_NetlistParser.hpp:96
string mCard
Definition cl_NetlistParser.hpp:97
Cell< string > mArgs
Definition cl_NetlistParser.hpp:94
one element card ( R/C/L/V/I/D ), lexed but not interpreted: all payloads stay strings; numeric conve...
Definition cl_NetlistParser.hpp:31
Cell< string > mValues
Definition cl_NetlistParser.hpp:45
char mType
element letter, case-folded: 'r' 'c' 'l' 'v' 'i' 'd'
Definition cl_NetlistParser.hpp:33
index_t mLine
1-based physical line of the card's first line
Definition cl_NetlistParser.hpp:51
Cell< string > mNodes
Definition cl_NetlistParser.hpp:41
string mName
Definition cl_NetlistParser.hpp:37
string mCard
the joined logical card as written, for error reporting
Definition cl_NetlistParser.hpp:54
Map< string, string > mKwargs
key=value tokens ( "r" -> "5k", "ic" -> "0" ), case-folded
Definition cl_NetlistParser.hpp:48
one .model card ( ".model dmod d( is=1e-14 )" )
Definition cl_NetlistParser.hpp:63
string mType
Definition cl_NetlistParser.hpp:65
string mCard
Definition cl_NetlistParser.hpp:68
Map< string, string > mKwargs
Definition cl_NetlistParser.hpp:66
index_t mLine
Definition cl_NetlistParser.hpp:67
string mName
Definition cl_NetlistParser.hpp:64