libsurf
Programmer's Documentation

igesline.h (r6227/r5847)
1 
2 /* Copyright (C) 2015 David Eller <david@larosterna.com>
3  *
4  * Commercial License Usage
5  * Licensees holding valid commercial licenses may use this file in accordance
6  * with the terms contained in their respective non-exclusive license agreement.
7  * For further information contact david@larosterna.com .
8  *
9  * GNU General Public License Usage
10  * Alternatively, this file may be used under the terms of the GNU General
11  * Public License version 3.0 as published by the Free Software Foundation and
12  * appearing in the file gpl.txt included in the packaging of this file.
13  */
14 
15 #ifndef SURF_IGESLINE_H
16 #define SURF_IGESLINE_H
17 
18 #include <genua/defines.h>
19 
20 #include <cstring>
21 #include <iostream>
22 #include <cstdio>
23 #include <cassert>
24 
25 inline void iges_insert(char a[], int len, int x)
26 {
27  int neg = 0;
28  if (x == 0) {
29  a[len-1] = '0';
30  return;
31  } else if (x < 0) {
32  neg = 1;
33  x = -x;
34  }
35 
36  int i = len-1;
37  while (x != 0 and i >= 0) {
38  int d = x%10;
39  a[i] = '0' + d;
40  x /= 10;
41  --i;
42  }
43 
44  if (neg and i >= 0)
45  a[i] = '-';
46 }
47 
59 inline void iges_insert(char a[], int len, int x, char pad)
60 {
61  for (int k=0; k<len; ++k)
62  a[k] = pad;
63  iges_insert(a, len, x);
64 }
65 
75 class IgesLine
76 {
77  public:
78 
80  IgesLine() {erase();}
81 
83  void erase() {
84  memset(ms, ' ', 80);
85  ms[80] = '\0';
86  }
87 
89  const char *content() const {return ms;}
90 
92  char *content() {return ms;}
93 
95  uint copyContent(uint n, const char *src) {
96  int nc = std::min(72u, n);
97  memcpy(ms, src, nc);
98  return nc;
99  }
100 
102  void fixedNumber(int i, int v) {
103  assert(i < 9);
104  iges_insert(&ms[8*i], 8, v, ' ');
105  }
106 
108  int fixedInteger(int i) const {
109  assert(i < 9);
110  const char *pos = &ms[8*i];
111  if (pos[7] == ' ')
112  return 0;
113  char *tail;
114  int v;
115  v = strtol(pos, &tail, 10);
116  assert(pos != tail);
117  return v;
118  }
119 
121  void statusCode(uint blank, uint subswitch, uint useflag, uint hierarchy) {
122  assert(blank < 100);
123  assert(subswitch < 100);
124  assert(useflag < 100);
125  assert(hierarchy < 100);
126  iges_insert(&ms[64], 4, 100*blank + subswitch, '0');
127  iges_insert(&ms[68], 4, 100*useflag + hierarchy, '0');
128  }
129 
131  void section(char sl) {
132  assert(sl == 'S' or sl == 'G' or sl == 'D' or sl == 'P' or sl == 'T');
133  ms[72] = sl;
134  }
135 
137  char section() const {return ms[72];}
138 
140  void number(uint ln) {
141  assert(ln < 9999999);
142  iges_insert(&ms[73], 7, ln, ' ');
143  }
144 
146  uint number() const {
147  return atoi(&ms[73]);
148  }
149 
151  void write(std::ostream & os) const {
152  // make sure that the the string is terminated
153  char *pms = const_cast<char*>(ms);
154  pms[80] = '\0';
155  os << pms << std::endl;
156  }
157 
159  void read(std::istream & is) {
160  std::string line;
161  std::getline(is, line);
162  int n = std::min(line.length(), size_t(80));
163  memcpy(ms, line.c_str(), n);
164  ms[80] = '\0';
165  }
166 
167  private:
168 
170  char ms[81];
171 };
172 
173 typedef std::vector<IgesLine> IgesLineArray;
174 
175 #endif
void read(std::istream &is)
read from stream
Definition: igesline.h:159
char section() const
retrieve section letter
Definition: igesline.h:137
void statusCode(uint blank, uint subswitch, uint useflag, uint hierarchy)
assemble a status code for the directory section
Definition: igesline.h:121
IgesLine()
create an undefined line
Definition: igesline.h:80
char ms[81]
line string
Definition: igesline.h:170
char * content()
pointer to start of data block (72 chars long)
Definition: igesline.h:92
void fixedNumber(int i, int v)
put an integer v in position i of a fixed format line
Definition: igesline.h:102
void section(char sl)
set section letter
Definition: igesline.h:131
void write(std::ostream &os) const
write line to stream
Definition: igesline.h:151
Line in IGES file.
Definition: igesline.h:75
void number(uint ln)
set line number
Definition: igesline.h:140
uint number() const
retrieve line number
Definition: igesline.h:146
const char * content() const
pointer to start of data block (72 chars long)
Definition: igesline.h:89
int fixedInteger(int i) const
convert fixed-format field i to integer
Definition: igesline.h:108
uint copyContent(uint n, const char *src)
copy character data into data block (max 72 bytes)
Definition: igesline.h:95
void erase()
erase line, fill with blanks
Definition: igesline.h:83
Generated on Sat Jun 25 2022 03:03:16 for libsurf by   doxygen 1.8.5