Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GdsDriver.h
Go to the documentation of this file.
1 
15 #ifndef _GDSPARSER_GDSDRIVER_H
16 #define _GDSPARSER_GDSDRIVER_H
17 
18 #include <sstream>
21 
22 using std::ostringstream;
23 
25 namespace GdsParser
26 {
27 
29 typedef int int32_t;
30 typedef unsigned int uint32_t;
32 
34 struct GdsBoundary
35 {
36  int32_t layer;
37  int32_t datatype;
38  vector<vector<int32_t> > vPoint;
39  void reset()
41  {
42  layer = -1;
43  datatype = -1;
44  vPoint.clear();
45  }
46 };
48 struct 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;
57  GdsText()
59  {
60  position.resize(2, 0);
61  }
63  void reset()
64  {
65  layer = texttype = presentation = strans = 0;
66  mag = 0;
67  position.resize(2, 0);
68  content = "";
69  }
70 };
74 struct GdsSref
75 {
76  string sname;
77  vector<int32_t> position;
78  GdsSref()
80  {
81  position.resize(2, 0);
82  }
84  void reset()
85  {
86  sname = "";
87  position.resize(2, 0);
88  }
89 };
91 struct GdsCell
92 {
93  string cell_name;
94  vector<GdsBoundary> vBoundary;
95  vector<GdsText> vText;
96  vector<GdsSref> vSref;
97  void reset()
99  {
100  cell_name = "";
101  vBoundary.clear();
102  vText.clear();
103  vSref.clear();
104  }
105 };
107 struct GdsLib
108 {
109  string lib_name;
110  vector<double> unit;
111  vector<GdsCell> vCell;
112  GdsLib()
114  {
115  unit.resize(2, 0);
116  }
118  void reset()
119  {
120  lib_name = "";
121  unit.resize(2, 0);
122  vCell.clear();
123  }
124 };
127 {
128  public:
130  virtual void add_gds_lib(GdsLib const&) = 0;
131 };
132 
135 class GdsDriver : public GdsDataBase
136 {
137  public:
139  typedef GdsDataBase base_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;
171  string m_current;
173 };
175 
176 template <typename ContainerType>
177 void 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  assert_msg(!m_lib.vCell.empty(), ascii_record_type << " block must be in a BGNSTR block");
209  m_lib.vCell.back().vBoundary.push_back(GdsBoundary());
210  }
211  else if (ascii_record_type == "TEXT")
212  {
213  m_current = "TEXT";
214  assert_msg(!m_lib.vCell.empty(), ascii_record_type << " block must be in a BGNSTR block");
215  m_lib.vCell.back().vText.push_back(GdsText());
216  }
217  else if (ascii_record_type == "SREF")
218  {
219  m_current = "SREF";
220  assert_msg(!m_lib.vCell.empty(), ascii_record_type << " block must be in a BGNSTR block");
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  assert_msg((vData.size() % 2) == 0 && vData.size() > 4, "invalid size of data array: " << 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  assert_msg(vData.size() == 2, "invalid size of data array for "
276  << m_current << ": " << vData.size());
277  m_lib.vCell.back().vText.back().position.assign(vData.begin(), vData.end());
278  }
279  else if (m_current == "SREF")
280  {
281  assert_msg(vData.size() == 2, "invalid size of data array for "
282  << m_current << ": " << vData.size());
283  m_lib.vCell.back().vSref.back().position.assign(vData.begin(), vData.end());
284  }
285  else assert_msg(0, "record XY should only appear in BOUNDARY, BOX, TEXT, SREF");
286  }
287  else if (ascii_record_type == "STRING")
288  {
289  assert_msg(m_current == "TEXT", "record type STRING must appear in TEXT block rather than " << m_current);
290  m_lib.vCell.back().vText.back().content.assign(vData.begin(), vData.end());
291  }
292  else if (ascii_record_type == "ENDEL")
293  {
294  assert_msg(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  assert_msg(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  assert_msg(m_current == "LIBRARY", "BGNLIB and ENDLIB should be in pair");
307  m_current = "HEADER";
308  // call db
310  m_lib.reset();
311  }
312  else assert_msg(0, "unsupported record type: " << ascii_record_type);
313 }
314 
318 bool read(GdsDriverDataBase& db, string const& filename);
319 
320 } // namespace GdsParser
321 
322 #endif
vector< GdsCell > vCell
Definition: GdsDriver.h:111
GdsText()
constructor
Definition: GdsDriver.h:58
vector< GdsSref > vSref
Definition: GdsDriver.h:96
database for the driver
Definition: GdsDriver.h:126
double mag
magnitude
Definition: GdsDriver.h:54
Top GDSII library.
Definition: GdsDriver.h:107
string m_current
it can be HEADER, LIBRARY, CELL, BOUNDARY, BOX, TEXT, SREF
Definition: GdsDriver.h:172
GdsLib m_lib
when parsed a lib, pass it using add_gds_lib function
Definition: GdsDriver.h:170
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
vector< GdsBoundary > vBoundary
array of boundaries
Definition: GdsDriver.h:94
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
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
void reset()
reset all data members
Definition: GdsDriver.h:118
virtual void bit_array_cbk(const char *ascii_record_type, const char *ascii_data_type, vector< int > const &vBitArray)
bit array callback
string cell_name
cell name
Definition: GdsDriver.h:93
GDSII TEXT.
Definition: GdsDriver.h:48
void reset()
reset all data members
Definition: GdsDriver.h:98
int32_t texttype
text type
Definition: GdsDriver.h:51
assertion with message
void reset()
reset all data members
Definition: GdsDriver.h:40
int32_t layer
layer
Definition: GdsDriver.h:36
vector< int32_t > position
Definition: GdsDriver.h:77
virtual void string_cbk(const char *ascii_record_type, const char *ascii_data_type, string const &str)
string callback
GdsDataBase redirects callbacks of GdsDataBaseKernel to ascii callbacks
Definition: GdsReader.h:81
void reset()
reset all data members
Definition: GdsDriver.h:63
virtual void integer_2_cbk(const char *ascii_record_type, const char *ascii_data_type, vector< int > const &vInteger)
2-byte integer callback
string lib_name
library name
Definition: GdsDriver.h:109
string sname
reference name
Definition: GdsDriver.h:76
vector< double > unit
unit
Definition: GdsDriver.h:110
int32_t strans
strans
Definition: GdsDriver.h:53
database_type & m_db
database type
Definition: GdsDriver.h:169
int32_t presentation
presentation
Definition: GdsDriver.h:52
namespace for Limbo.GdsParser
Definition: GdsIO.h:19
GDSII SREF.
Definition: GdsDriver.h:74
vector< vector< int32_t > > vPoint
Definition: GdsDriver.h:38
virtual void integer_4_cbk(const char *ascii_record_type, const char *ascii_data_type, vector< int > const &vInteger)
4-byte integer callback
GDSII cell.
Definition: GdsDriver.h:91
bool operator()(string const &filename)
Top function for GdsDriver.
int32_t layer
layer
Definition: GdsDriver.h:50
int32_t datatype
data type
Definition: GdsDriver.h:37
vector< int32_t > position
position
Definition: GdsDriver.h:55
GdsLib()
constructor
Definition: GdsDriver.h:113
High-level wrapper class for GdsReader. Everything is saved in an internal data structure and users o...
Definition: GdsDriver.h:135
GdsSref()
constructor
Definition: GdsDriver.h:79
read GDSII file
void reset()
reset all data members
Definition: GdsDriver.h:84
virtual void begin_end_cbk(const char *ascii_record_type)
begin or end indicator of a block
internal structure to store gds information
Definition: GdsDriver.h:34
virtual void add_gds_lib(GdsLib const &)=0
required callback function
GdsDriver(database_type &)
constructor
#define assert_msg(condition, message)
assertion with message
Definition: AssertMsg.h:34
bool read(GdsDriverDataBase &db, string const &filename)
API function for GdsDriver.
vector< GdsText > vText
array of texts
Definition: GdsDriver.h:95