-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathSTEPaggrSelect.cc
More file actions
224 lines (185 loc) · 6.78 KB
/
STEPaggrSelect.cc
File metadata and controls
224 lines (185 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include "clstepcore/STEPaggrSelect.h"
#include "clstepcore/typeDescriptor.h"
#include <sstream>
/** \file STEPaggrSelect.cc
* implement classes SelectAggregate, SelectNode
*/
SelectAggregate::SelectAggregate() {
}
SelectAggregate::~SelectAggregate() {
}
/// if exchangeFileFormat == 1 then delims are required.
Severity SelectAggregate::ReadValue( istream & in, ErrorDescriptor * err,
const TypeDescriptor * elem_type, InstMgrBase * insts,
int addFileId, int assignVal,
int exchangeFileFormat, const char * currSch ) {
ErrorDescriptor errdesc;
char errmsg[BUFSIZ+1];
int value_cnt = 0;
std::string buf;
if( assignVal ) {
Empty(); // read new values and discard existing ones
}
char c;
in >> ws; // skip white space
c = in.peek(); // does not advance input
if( in.eof() || ( c == '$' ) ) {
_null = 1;
err->GreaterSeverity( SEVERITY_INCOMPLETE );
return SEVERITY_INCOMPLETE;
}
if( c == '(' ) {
in.get( c );
} else if( exchangeFileFormat ) {
// error did not find opening delim
// give up because you do not know where to stop reading.
err->GreaterSeverity( SEVERITY_INPUT_ERROR );
return SEVERITY_INPUT_ERROR;
} else if( !in.good() ) {
// this should actually have been caught by skipping white space above
err->GreaterSeverity( SEVERITY_INCOMPLETE );
return SEVERITY_INCOMPLETE;
}
SelectNode * item = 0;
in >> ws;
// take a peek to see if there are any elements before committing to an
// element
c = in.peek(); // does not advance input
if( c == ')' ) {
in.get( c );
}
// if not assigning values only need one node. So only one node is created.
// It is used to read the values
else if( !assignVal ) {
item = ( SelectNode * ) NewNode();
}
while( in.good() && ( c != ')' ) ) {
value_cnt++;
if( assignVal ) { // create a new node each time through the loop
item = ( SelectNode * ) NewNode();
}
errdesc.ClearErrorMsg();
if( exchangeFileFormat ) {
item->STEPread( in, &errdesc, elem_type, insts, addFileId, currSch );
} else {
item->StrToVal( in, &errdesc, elem_type, insts, addFileId, currSch );
}
elem_type->AttrTypeName( buf );
// read up to the next delimiter and set errors if garbage is
// found before specified delims (i.e. comma and quote)
CheckRemainingInput( in, &errdesc, buf, ",)" );
if( errdesc.severity() < SEVERITY_INCOMPLETE ) {
snprintf( errmsg, sizeof(errmsg), " index: %d\n", value_cnt );
errdesc.PrependToDetailMsg( errmsg );
err->AppendFromErrorArg( &errdesc );
}
if( assignVal ) {
AddNode( item );
}
in >> ws; // skip white space (although should already be skipped)
in.get( c ); // read delim
// CheckRemainingInput should have left the input right at the delim
// so that it would be read in in.get() above. Since it did not find
// the delim this does not know how to find it either!
if( ( c != ',' ) && ( c != ')' ) ) {
// cannot recover so give up and let STEPattribute recover
err->GreaterSeverity( SEVERITY_INPUT_ERROR );
return SEVERITY_INPUT_ERROR;
}
}
if( c == ')' ) {
_null = 0;
} else { // expectation for end paren delim has not been met
err->GreaterSeverity( SEVERITY_INPUT_ERROR );
err->AppendToUserMsg( "Missing close paren for aggregate value" );
return SEVERITY_INPUT_ERROR;
}
return err->severity();
}
STEPaggregate & SelectAggregate::ShallowCopy( const STEPaggregate & a ) {
const SelectNode * tmp = ( const SelectNode * ) a.GetHead();
while( tmp ) {
AddNode( new SelectNode( tmp -> node ) );
tmp = ( const SelectNode * ) tmp -> NextNode();
}
if( head ) {
_null = 0;
} else {
_null = 1;
}
return *this;
}
SingleLinkNode * SelectAggregate::NewNode() {
return new SelectNode();
}
SelectNode::SelectNode( SDAI_Select * s ) : node( s ) {
}
SelectNode::SelectNode() {
}
SelectNode::~SelectNode() {
delete node;
}
SingleLinkNode * SelectNode::NewNode() {
return new SelectNode();
}
Severity SelectNode::StrToVal( const char * s, ErrorDescriptor * err,
const TypeDescriptor * elem_type,
InstMgrBase * insts, int addFileId ) {
(void) elem_type; //unused
(void) addFileId; //unused
istringstream in( ( char * )s );
if( err->severity( node->STEPread( in, err, insts ) ) != SEVERITY_NULL ) {
err->AppendToDetailMsg( node ->Error() );
}
return err->severity();
}
Severity SelectNode::StrToVal( istream & in, ErrorDescriptor * err,
const TypeDescriptor * elem_type,
InstMgrBase * insts, int addFileId, const char * currSch ) {
return STEPread( in, err, elem_type, insts, addFileId, currSch );
}
Severity SelectNode::STEPread( const char * s, ErrorDescriptor * err,
const TypeDescriptor * elem_type,
InstMgrBase * insts, int addFileId ) {
istringstream in( ( char * )s );
return STEPread( in, err, elem_type, insts, addFileId );
}
Severity SelectNode::STEPread( istream & in, ErrorDescriptor * err,
const TypeDescriptor * elem_type,
InstMgrBase * insts, int addFileId, const char * currSch ) {
(void) elem_type; //unused
if( !node ) {
cerr << "Internal error: " << __FILE__ << ": " << __LINE__ << "\n"
<< _POC_ "\n";
cerr << "function: SelectNode::STEPread \n" << "\n";
return SEVERITY_BUG;
}
err->severity( node->STEPread( in, err, insts, 0, addFileId, currSch ) );
CheckRemainingInput( in, err, "select", ",)" );
return err->severity();
}
const char * SelectNode::asStr( std::string & s ) {
s.clear();
if( !node || ( node->is_null() ) ) { // nothing
return "";
} else { // otherwise return entity id
node -> STEPwrite( s );
return const_cast<char *>( s.c_str() );
}
}
const char * SelectNode::STEPwrite( std::string & s, const char * currSch ) {
s.clear();
if( !node || ( node->is_null() ) ) { // nothing
s = "$";
return "$";
}
node -> STEPwrite( s, currSch );
return const_cast<char *>( s.c_str() );
}
void SelectNode::STEPwrite( ostream & out ) {
if( !node || ( node->is_null() ) ) { // nothing
out << "$";
}
std::string s;
out << asStr( s );
}