Limbo 3.5.4
Loading...
Searching...
No Matches
GdsDriver.h
Go to the documentation of this file.
1
14
15#ifndef _GDSPARSER_GDSDRIVER_H
16#define _GDSPARSER_GDSDRIVER_H
17
18#include <sstream>
21
22using std::ostringstream;
23
25namespace GdsParser
26{
27
29typedef int int32_t;
30typedef unsigned int uint32_t;
32
35{
36 int32_t layer;
37 int32_t datatype;
38 vector<vector<int32_t> > vPoint;
40 void reset()
41 {
42 layer = -1;
43 datatype = -1;
44 vPoint.clear();
45 }
46};
47
48struct GdsText
49{
50 int32_t layer;
51 int32_t texttype;
52 int32_t presentation;
53 int32_t strans;
54 double mag;
55 vector<int32_t> position;
56 string content;
59 {
60 position.resize(2, 0);
61 }
62
63 void reset()
64 {
66 mag = 0;
67 position.resize(2, 0);
68 content = "";
69 }
70};
71
74struct GdsSref
75{
76 string sname;
77 vector<int32_t> position;
80 {
81 position.resize(2, 0);
82 }
83
84 void reset()
85 {
86 sname = "";
87 position.resize(2, 0);
88 }
89};
90
91struct GdsCell
92{
93 string cell_name;
94 vector<GdsBoundary> vBoundary;
95 vector<GdsText> vText;
96 vector<GdsSref> vSref;
98 void reset()
99 {
100 cell_name = "";
101 vBoundary.clear();
102 vText.clear();
103 vSref.clear();
104 }
105};
106
107struct GdsLib
108{
109 string lib_name;
110 vector<double> unit;
111 vector<GdsCell> vCell;
114 {
115 unit.resize(2, 0);
116 }
117
118 void reset()
119 {
120 lib_name = "";
121 unit.resize(2, 0);
122 vCell.clear();
123 }
124};
125
127{
128 public:
130 virtual void add_gds_lib(GdsLib const&) = 0;
131};
132
135class GdsDriver : public GdsDataBase
136{
137 public:
139 typedef GdsDataBase base_type;
140 typedef GdsDriverDataBase database_type;
142
144 GdsDriver(database_type&);
145
148 bool operator()(string const& filename);
149
150 protected:
153 virtual void bit_array_cbk(const char* ascii_record_type, const char* ascii_data_type, vector<int> const& vBitArray);
154 virtual void integer_2_cbk(const char* ascii_record_type, const char* ascii_data_type, vector<int> const& vInteger);
155 virtual void integer_4_cbk(const char* ascii_record_type, const char* ascii_data_type, vector<int> const& vInteger);
156 virtual void real_4_cbk(const char* ascii_record_type, const char* ascii_data_type, vector<double> const& vFloat);
157 virtual void real_8_cbk(const char* ascii_record_type, const char* ascii_data_type, vector<double> const& vFloat);
158 virtual void string_cbk(const char* ascii_record_type, const char* ascii_data_type, string const& str);
159 virtual void begin_end_cbk(const char* ascii_record_type); // begin or end indicater of a block
166 template <typename ContainerType>
167 void general_cbk(string const& ascii_record_type, string const& ascii_data_type, ContainerType const& vData);
168
169 database_type& m_db;
172 string m_current;
174};
175
176template <typename ContainerType>
177void GdsDriver::general_cbk(string const& ascii_record_type, string const&, ContainerType const& vData)
178{
179 if (ascii_record_type == "HEADER")
180 {
181 m_current = "HEADER";
182 }
183 else if (ascii_record_type == "BGNLIB")
184 {
185 m_current = "LIBRARY";
186 }
187 else if (ascii_record_type == "LIBNAME")
188 {
189 m_lib.lib_name.assign(vData.begin(), vData.end());
190 }
191 else if (ascii_record_type == "UNITS")
192 {
193 m_lib.unit[0] = vData[0];
194 m_lib.unit[1] = vData[1];
195 }
196 else if (ascii_record_type == "BGNSTR")
197 {
198 m_current = "CELL";
199 m_lib.vCell.push_back(GdsCell());
200 }
201 else if (ascii_record_type == "STRNAME")
202 {
203 m_lib.vCell.back().cell_name.assign(vData.begin(), vData.end());
204 }
205 else if (ascii_record_type == "BOUNDARY" || ascii_record_type == "BOX") // BOUNDARY and BOX are generalized to BOUNDARY
206 {
207 m_current = "BOUNDARY";
208 limboAssertMsg(!m_lib.vCell.empty(), "%s block must be in a BGNSTR block", ascii_record_type.c_str());
209 m_lib.vCell.back().vBoundary.push_back(GdsBoundary());
210 }
211 else if (ascii_record_type == "TEXT")
212 {
213 m_current = "TEXT";
214 limboAssertMsg(!m_lib.vCell.empty(), "%s block must be in a BGNSTR block", ascii_record_type.c_str());
215 m_lib.vCell.back().vText.push_back(GdsText());
216 }
217 else if (ascii_record_type == "SREF")
218 {
219 m_current = "SREF";
220 limboAssertMsg(!m_lib.vCell.empty(), "%s block must be in a BGNSTR block", ascii_record_type.c_str());
221 m_lib.vCell.back().vSref.push_back(GdsSref());
222 }
223 else if (ascii_record_type == "LAYER")
224 {
225 if (m_current == "BOUNDARY")
226 m_lib.vCell.back().vBoundary.back().layer = vData[0];
227 else if (m_current == "TEXT")
228 m_lib.vCell.back().vText.back().layer = vData[0];
229 }
230 else if (ascii_record_type == "DATATYPE") // here're some information I don't see any usage
231 {
232 if (m_current == "BOUNDARY")
233 m_lib.vCell.back().vBoundary.back().datatype = vData[0];
234 }
235 else if (ascii_record_type == "TEXTTYPE")
236 {
237 if (m_current == "TEXT")
238 m_lib.vCell.back().vText.back().texttype = vData[0];
239 }
240 else if (ascii_record_type == "PRESENTATION")
241 {
242 if (m_current == "TEXT")
243 m_lib.vCell.back().vText.back().presentation = vData[0];
244 }
245 else if (ascii_record_type == "STRANS")
246 {
247 if (m_current == "TEXT")
248 m_lib.vCell.back().vText.back().strans = vData[0];
249 }
250 else if (ascii_record_type == "MAG")
251 {
252 if (m_current == "TEXT")
253 m_lib.vCell.back().vText.back().mag = vData[0];
254 }
255 else if (ascii_record_type == "SNAME")
256 {
257 if (m_current == "SREF")
258 m_lib.vCell.back().vSref.back().sname.assign(vData.begin(), vData.end());
259 }
260 else if (ascii_record_type == "XY")
261 {
262 if (m_current == "BOUNDARY")
263 {
264 limboAssertMsg((vData.size() % 2) == 0 && vData.size() > 4, "invalid size of data array: %lu", vData.size());
265 for (uint32_t i = 0; i < vData.size(); i += 2)
266 {
267 vector<int32_t> point (2);
268 point[0] = vData[i];
269 point[1] = vData[i+1];
270 m_lib.vCell.back().vBoundary.back().vPoint.push_back(point);
271 }
272 }
273 else if (m_current == "TEXT")
274 {
275 limboAssertMsg(vData.size() == 2, "invalid size of data array for %s: %lu",
276 m_current.c_str(), vData.size());
277 m_lib.vCell.back().vText.back().position.assign(vData.begin(), vData.end());
278 }
279 else if (m_current == "SREF")
280 {
281 limboAssertMsg(vData.size() == 2, "invalid size of data array for %s: %lu",
282 m_current.c_str(), vData.size());
283 m_lib.vCell.back().vSref.back().position.assign(vData.begin(), vData.end());
284 }
285 else limboAssertMsg(0, "record XY should only appear in BOUNDARY, BOX, TEXT, SREF");
286 }
287 else if (ascii_record_type == "STRING")
288 {
289 limboAssertMsg(m_current == "TEXT", "record type STRING must appear in TEXT block rather than %s", m_current.c_str());
290 m_lib.vCell.back().vText.back().content.assign(vData.begin(), vData.end());
291 }
292 else if (ascii_record_type == "ENDEL")
293 {
294 limboAssertMsg(m_current == "BOUNDARY" || m_current == "TEXT"
295 || m_current == "SREF",
296 "currently only support BOUNDARY, BOX, and TEXT");
297 m_current = "CELL"; // go back to upper
298 }
299 else if (ascii_record_type == "ENDSTR")
300 {
301 limboAssertMsg(m_current == "CELL", "BGNSTR and ENDSTR should be in pair");
302 m_current = "LIBRARY"; // go back to upper
303 }
304 else if (ascii_record_type == "ENDLIB")
305 {
306 limboAssertMsg(m_current == "LIBRARY", "BGNLIB and ENDLIB should be in pair");
307 m_current = "HEADER";
308 // call db
309 m_db.add_gds_lib(m_lib);
310 m_lib.reset();
311 }
312 else limboAssertMsg(0, "unsupported record type: %s", ascii_record_type.c_str());
313}
314
318bool read(GdsDriverDataBase& db, string const& filename);
319
320} // namespace GdsParser
321
322#endif
assertion with message
#define limboAssertMsg(condition, args...)
custom assertion with message
Definition AssertMsg.h:24
read GDSII file
GdsDataBase redirects callbacks of GdsDataBaseKernel to ascii callbacks.
Definition GdsReader.h:82
database for the driver
Definition GdsDriver.h:127
virtual void add_gds_lib(GdsLib const &)=0
required callback function
virtual void real_8_cbk(const char *ascii_record_type, const char *ascii_data_type, vector< double > const &vFloat)
8-byte floating point number callback
bool operator()(string const &filename)
Top function for GdsDriver.
string m_current
it can be HEADER, LIBRARY, CELL, BOUNDARY, BOX, TEXT, SREF
Definition GdsDriver.h:172
virtual void begin_end_cbk(const char *ascii_record_type)
begin or end indicator of a block
virtual void bit_array_cbk(const char *ascii_record_type, const char *ascii_data_type, vector< int > const &vBitArray)
bit array callback
GdsLib m_lib
when parsed a lib, pass it using add_gds_lib function
Definition GdsDriver.h:170
virtual void real_4_cbk(const char *ascii_record_type, const char *ascii_data_type, vector< double > const &vFloat)
4-byte floating point number callback
virtual void integer_4_cbk(const char *ascii_record_type, const char *ascii_data_type, vector< int > const &vInteger)
4-byte integer callback
virtual void string_cbk(const char *ascii_record_type, const char *ascii_data_type, string const &str)
string callback
GdsDriver(database_type &)
constructor
database_type & m_db
database type
Definition GdsDriver.h:169
void general_cbk(string const &ascii_record_type, string const &ascii_data_type, ContainerType const &vData)
Generalized callback for all cases.
Definition GdsDriver.h:177
virtual void integer_2_cbk(const char *ascii_record_type, const char *ascii_data_type, vector< int > const &vInteger)
2-byte integer callback
namespace for Limbo.GdsParser
Definition GdsIO.h:20
bool read(GdsDriverDataBase &db, string const &filename)
API function for GdsDriver.
internal structure to store gds information
Definition GdsDriver.h:35
int32_t datatype
data type
Definition GdsDriver.h:37
vector< vector< int32_t > > vPoint
Definition GdsDriver.h:38
void reset()
reset all data members
Definition GdsDriver.h:40
int32_t layer
layer
Definition GdsDriver.h:36
GDSII cell.
Definition GdsDriver.h:92
vector< GdsSref > vSref
Definition GdsDriver.h:96
vector< GdsText > vText
array of texts
Definition GdsDriver.h:95
string cell_name
cell name
Definition GdsDriver.h:93
vector< GdsBoundary > vBoundary
array of boundaries
Definition GdsDriver.h:94
void reset()
reset all data members
Definition GdsDriver.h:98
Top GDSII library.
Definition GdsDriver.h:108
vector< double > unit
unit
Definition GdsDriver.h:110
void reset()
reset all data members
Definition GdsDriver.h:118
string lib_name
library name
Definition GdsDriver.h:109
vector< GdsCell > vCell
Definition GdsDriver.h:111
GdsLib()
constructor
Definition GdsDriver.h:113
GDSII SREF.
Definition GdsDriver.h:75
void reset()
reset all data members
Definition GdsDriver.h:84
GdsSref()
constructor
Definition GdsDriver.h:79
string sname
reference name
Definition GdsDriver.h:76
vector< int32_t > position
Definition GdsDriver.h:77
GDSII TEXT.
Definition GdsDriver.h:49
int32_t presentation
presentation
Definition GdsDriver.h:52
void reset()
reset all data members
Definition GdsDriver.h:63
GdsText()
constructor
Definition GdsDriver.h:58
int32_t layer
layer
Definition GdsDriver.h:50
int32_t texttype
text type
Definition GdsDriver.h:51
vector< int32_t > position
position
Definition GdsDriver.h:55
double mag
magnitude
Definition GdsDriver.h:54
int32_t strans
strans
Definition GdsDriver.h:53