-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathSTEPaggrEntity.cc
More file actions
241 lines (202 loc) · 7.28 KB
/
STEPaggrEntity.cc
File metadata and controls
241 lines (202 loc) · 7.28 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#include "STEPaggrEntity.h"
#include "STEPattribute.h"
#include "typeDescriptor.h"
#include <sstream>
/** \file STEPaggrEntity.cc
* implement classes EntityAggregate, EntityNode
*/
EntityAggregate::EntityAggregate() {
}
EntityAggregate::~EntityAggregate() {
}
/// if exchangeFileFormat == 1 then delims are required.
Severity EntityAggregate::ReadValue( istream & in, ErrorDescriptor * err,
const TypeDescriptor * elem_type, InstMgrBase * insts,
int addFileId, int assignVal,
int exchangeFileFormat, const char * ) {
ErrorDescriptor errdesc;
char errmsg[BUFSIZ];
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;
}
EntityNode * 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 = new EntityNode();
}
while( in.good() && ( c != ')' ) ) {
value_cnt++;
if( assignVal ) { // create a new node each time through the loop
item = new EntityNode();
}
errdesc.ClearErrorMsg();
if( exchangeFileFormat ) {
item->STEPread( in, &errdesc, elem_type, insts, addFileId );
} else {
item->StrToVal( in, &errdesc, elem_type, insts, addFileId );
}
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 ) {
sprintf( 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 & EntityAggregate::ShallowCopy( const STEPaggregate & a ) {
const EntityNode * tmp = ( const EntityNode * ) a.GetHead();
while( tmp ) {
AddNode( new EntityNode( tmp -> node ) );
tmp = ( const EntityNode * ) tmp -> NextNode();
}
if( head ) {
_null = 0;
} else {
_null = 1;
}
return *this;
}
SingleLinkNode * EntityAggregate::NewNode() {
return new EntityNode();
}
EntityNode::EntityNode() {
}
EntityNode::~EntityNode() {
}
EntityNode::EntityNode( SDAI_Application_instance * e ) : node( e ) {
}
SingleLinkNode * EntityNode::NewNode() {
return new EntityNode();
}
///////////////////////////////////////////////////////////////////////////////
Severity EntityNode::StrToVal( const char * s, ErrorDescriptor * err,
const TypeDescriptor * elem_type,
InstMgrBase * insts, int addFileId ) {
SDAI_Application_instance * se = ReadEntityRef( s, err, ",)", insts,
addFileId );
if( se != S_ENTITY_NULL ) {
ErrorDescriptor error;
if( EntityValidLevel( se, elem_type, &error ) == SEVERITY_NULL ) {
node = se;
} else {
node = S_ENTITY_NULL;
err->AppendToDetailMsg( error.DetailMsg() );
err->AppendToUserMsg( error.UserMsg() );
err->GreaterSeverity( error.severity() );
}
} else {
node = S_ENTITY_NULL;
}
return err->severity();
}
Severity EntityNode::StrToVal( istream & in, ErrorDescriptor * err,
const TypeDescriptor * elem_type,
InstMgrBase * insts, int addFileId ) {
return STEPread( in, err, elem_type, insts, addFileId );
}
Severity EntityNode::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 EntityNode::STEPread( istream & in, ErrorDescriptor * err,
const TypeDescriptor * elem_type,
InstMgrBase * insts, int addFileId ) {
SDAI_Application_instance * se = ReadEntityRef( in, err, ",)", insts,
addFileId );
if( se != S_ENTITY_NULL ) {
ErrorDescriptor error;
if( EntityValidLevel( se, elem_type, &error ) == SEVERITY_NULL ) {
node = se;
} else {
node = S_ENTITY_NULL;
err->AppendToDetailMsg( error.DetailMsg() );
err->AppendToUserMsg( error.UserMsg() );
err->GreaterSeverity( error.severity() );
}
} else {
node = S_ENTITY_NULL;
}
return err->severity();
}
const char * EntityNode::asStr( std::string & s ) {
s.clear();
if( !node || ( node == S_ENTITY_NULL ) ) { // nothing
return "";
} else { // otherwise return entity id
char tmp [64];
sprintf( tmp, "#%d", node->STEPfile_id );
s = tmp;
}
return const_cast<char *>( s.c_str() );
}
const char * EntityNode::STEPwrite( std::string & s, const char * ) {
if( !node || ( node == S_ENTITY_NULL ) ) { // nothing
s = "$";
return const_cast<char *>( s.c_str() );
}
asStr( s );
return const_cast<char *>( s.c_str() );
}
void EntityNode::STEPwrite( ostream & out ) {
if( !node || ( node == S_ENTITY_NULL ) ) { // nothing
out << "$";
}
std::string s;
out << asStr( s );
}