Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GdsWriter.h
Go to the documentation of this file.
1 
8 #ifndef _GDSPARSER_GDSWRITER_H
9 #define _GDSPARSER_GDSWRITER_H
10 
11 #include <stdio.h>
12 #include <math.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <sys/stat.h>
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include <time.h>
19 #include <assert.h>
20 #include <vector>
21 #include <iostream>
22 #include <fstream>
23 
26 #define BYTESWAP 1
27 //#define BYTE unsigned char
28 
29 //#define BOOL int
30 //#define TRUE 1
31 //#define FALSE 0
32 
33 //extern BYTE gdsswap;
34 //extern short gdsword;
35 
37 namespace GdsParser
38 {
39 
41 typedef int BOOL;
43 typedef unsigned char BYTE;
44 
47 {
48  int type;
49  int n;
51  int layer;
52  int dt;
54  double mag;
55  double angle;
56  BOOL abs_angle;
57  BOOL abs_mag;
58  BOOL reflect;
59  int cols;
60  int rows;
61  int col_pitch;
62  int row_pitch;
63  int col_pitchy;
64  int row_pitchx;
65  int path_end;
68  int font;
69  int width;
70  int *x;
71  int *y;
72  char *text;
74 };
75 
77 struct gds_celltype
78 {
79  char *name;
80  struct gds_itemtype *item;
82 };
83 
84 // forward declaration of a writer class
85 // which is flexiable to choose std::ofstream or boost::iostreams
86 class GdsStream;
87 
90 struct GdsWriter
91 {
92  public:
95  GdsWriter(const char* filename);
97  ~GdsWriter();
98 
99  /**************** high level interfaces *****************/
102 
111  void write_boundary(int layer, int datatype, std::vector<int> const& vx, std::vector<int> const& vy, bool has_last = true);
116  void write_box(int layer, int datatype, int xl, int yl, int xh, int yh);
122  void create_lib(const char* libname, double dbu_uu, double dbu_m);
123 
125 
126  /**************** low level interfaces *****************/
129 
130  void gds_make_next_item( struct gds_itemtype **ci );
131  /* dump one byte in binary format */
132  void gds_bindump( BYTE x );
133  /* Write 8 bytes after converting back to wacky GDS float format. */
134  void gds_write_float( double x );
137  void gds_swap4bytes( BYTE *four );
140  void gds_swap2bytes( BYTE *two );
142  void gds_write_header( );
144  void gds_write_bgnlib( );
146  void gds_write_bgnstr( );
148  void gds_write_endlib( );
150  void gds_write_endstr( );
153  void gds_write_libname( const char *name );
156  void gds_write_strname( const char *name );
159  void gds_write_string( const char *s );
162  void gds_write_sname( const char *s );
164  void gds_write_boundary( );
166  void gds_write_box( );
169  void gds_write_boxtype( short int dt );
171  void gds_write_path( );
173  void gds_write_sref( );
175  void gds_write_aref( );
177  void gds_write_text( );
179  void gds_write_endel( );
182  void gds_write_layer( short int layer );
185  void gds_write_width( int width );
188  void gds_write_datatype( short int dt );
191  void gds_write_texttype( short int dt );
194  void gds_write_generations( short int gens );
197  void gds_write_pathtype( short int pt );
202  void gds_write_presentation( int font, int vp, int hp );
207  void gds_write_strans( BOOL reflect, BOOL abs_angle, BOOL abs_mag );
215  void gds_write_xy( const int *x, const int *y, int n, bool has_last = true);
219  void gds_write_colrow( int ncols, int nrows );
223  void gds_write_units( double dbu_uu, double dbu_m );
226  void gds_write_mag( double mag );
229  void gds_write_angle( double angle );
233  void gds_create_lib( const char *libname, double dbu_um );
240  void gds_create_text( const char *str, int x, int y, int layer, int size );
241 
243 
244  // add by Yibo Lin
250  char* gds_adjust_string(const char* input, int *output_length);
251 
252  protected:
253 
257  int gds_write(const char* b, std::size_t n);
259  void gds_flush();
260 
261  GdsStream* m_os;
262  //int out; // output gds file descriptor
263  BYTE gdsswap;
264  short gdsword;
265 
266  std::size_t m_capacity;
267  std::size_t m_size;
268  char* m_buffer;
269 };
270 
271 } // namespace GdsParser
272 
273 #endif
GdsWriter(const char *filename)
constructor
void gds_swap4bytes(BYTE *four)
swap bytes
void gds_write_presentation(int font, int vp, int hp)
write PRESENTATION
void gds_write_endlib()
write ENDLIB
struct gds_itemtype * item
Definition: GdsWriter.h:80
void gds_write_endstr()
write ENDSTR
void gds_write_boxtype(short int dt)
write BOXTYPE
void gds_write_mag(double mag)
write MAG
std::size_t m_size
output buffer size
Definition: GdsWriter.h:267
void gds_write_units(double dbu_uu, double dbu_m)
write UNITS
void gds_write_endel()
write ENDEL
void gds_write_box()
write BOX
std::size_t m_capacity
output buffer capacity
Definition: GdsWriter.h:266
void gds_flush()
flush all contents in the buffer
void gds_write_libname(const char *name)
write LIBNAME
void gds_write_bgnstr()
write BGNSTR
void write_box(int layer, int datatype, int xl, int yl, int xh, int yh)
write a box object
~GdsWriter()
destructor
void gds_write_bgnlib()
write BGNLIB
void gds_write_datatype(short int dt)
write DATATYPE
struct gds_itemtype * nextitem
Definition: GdsWriter.h:73
void gds_write_sname(const char *s)
write SNAME
void create_lib(const char *libname, double dbu_uu, double dbu_m)
create GDSII library
void write_boundary(int layer, int datatype, std::vector< int > const &vx, std::vector< int > const &vy, bool has_last=true)
write a boundary object
void gds_write_path()
write PATH
void gds_write_pathtype(short int pt)
write PATHTYPE
void gds_write_width(int width)
write WIDTH
mathematical utilities such as abs
short gdsword
move from global variables
Definition: GdsWriter.h:264
void gds_swap2bytes(BYTE *two)
swap bytes
void gds_write_texttype(short int dt)
write TEXTTYPE
void gds_write_xy(const int *x, const int *y, int n, bool has_last=true)
write XY
void gds_write_text()
write TEXT
void gds_write_aref()
write AREF
namespace for Limbo.GdsParser
Definition: GdsIO.h:19
void gds_write_string(const char *s)
write STRING
void gds_write_layer(short int layer)
write LAYER
char * gds_adjust_string(const char *input, int *output_length)
int BOOL
use integer as bool
Definition: GdsWriter.h:41
char * m_buffer
output buffer
Definition: GdsWriter.h:268
void gds_create_text(const char *str, int x, int y, int layer, int size)
wrapper to create text
void gds_write_boundary()
write BOUNDARY
void gds_write_strname(const char *name)
write STRNAME
void gds_write_generations(short int gens)
write GENERATIONS
struct gds_celltype * nextcell
Definition: GdsWriter.h:81
Check string is integer, floating point, number... Convert string to upper/lower cases.
void gds_write_colrow(int ncols, int nrows)
write COLROW
unsigned char BYTE
use unsigned char as byte
Definition: GdsWriter.h:43
void gds_write_strans(BOOL reflect, BOOL abs_angle, BOOL abs_mag)
write STRANS
void gds_write_sref()
write SREF
GdsStream * m_os
output stream
Definition: GdsWriter.h:261
void gds_create_lib(const char *libname, double dbu_um)
create library with name and unit
void gds_write_header()
write HEADER
GDSII item type.
Definition: GdsWriter.h:46
BYTE gdsswap
moved from global variables
Definition: GdsWriter.h:263
int gds_write(const char *b, std::size_t n)
void gds_write_angle(double angle)
write ANGLE