-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathsdaiSelect.cc
More file actions
602 lines (540 loc) · 20.8 KB
/
sdaiSelect.cc
File metadata and controls
602 lines (540 loc) · 20.8 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
/*
* NIST STEP Core Class Library
* clstepcore/sdaiSelect.cc
* April 1997
* Dave Helfrick
* KC Morris
* Development of this software was funded by the United States Government,
* and is not subject to copyright.
*/
#include <stdio.h> // to get the BUFSIZ #define
#include "clstepcore/ExpDict.h"
#include <sstream>
#include <string>
#include "clstepcore/sdai.h"
#include "clstepcore/STEPattribute.h"
#ifdef SC_LOGGING
#include <fstream.h>
extern ofstream * logStream;
#endif
/**********
(member) functions for the select class SDAI_Select
**********/
SDAI_Select::SDAI_Select( const SelectTypeDescriptor * s,
const TypeDescriptor * td )
: _type( s ), underlying_type( td ) {
#ifdef SC_LOGGING
*logStream << "Exiting SDAI_Select constructor." << endl;
#endif
}
SDAI_Select::SDAI_Select( const SDAI_Select & other ) {
underlying_type = other.underlying_type;
base_type = other.base_type;
_type = other._type;
#ifdef SC_LOGGING
*logStream << "Exiting SDAI_Select constructor." << endl;
#endif
}
SDAI_Select::~SDAI_Select() {
}
SDAI_Select & SDAI_Select::operator=( const SDAI_Select & other ) {
if( &other != this ) {
_error = other._error;
_type = other._type;
base_type = other.base_type;
underlying_type = other.underlying_type;
val = other.val;
}
return *this;
}
Severity SDAI_Select::severity() const {
return _error.severity();
}
Severity SDAI_Select::severity( Severity s ) {
return _error.severity( s );
}
std::string SDAI_Select::Error() {
return _error.DetailMsg();
}
void SDAI_Select::Error( const char * e ) {
_error.DetailMsg( e );
}
void SDAI_Select::ClearError() {
_error.ClearErrorMsg();
}
const TypeDescriptor *
SDAI_Select::CanBe( const char * n ) const {
return _type -> CanBe( n );
}
const TypeDescriptor *
SDAI_Select::CanBe( BASE_TYPE bt ) const {
const TypeDescLinkNode * tdn =
( const TypeDescLinkNode * ) _type -> GetElements().GetHead();
const TypeDescriptor * td = tdn -> TypeDesc();
BASE_TYPE bt_thisnode;
while( tdn ) {
td = tdn -> TypeDesc();
if( ( ( bt_thisnode = td -> NonRefType() ) == bt ) ||
( bt == AGGREGATE_TYPE && ( ( bt_thisnode == ARRAY_TYPE ) ||
( bt_thisnode == LIST_TYPE ) ||
( bt_thisnode == SET_TYPE ) ||
( bt_thisnode == BAG_TYPE ) ) ) ) {
return td; // they are the same
}
tdn = ( TypeDescLinkNode * )( tdn -> NextNode() );
}
return 0;
}
const TypeDescriptor *
SDAI_Select::CanBe( const TypeDescriptor * td ) const {
return _type -> CanBe( td );
}
const TypeDescriptor *
SDAI_Select::CanBeSet( const char * n, const char * schnm ) const {
return _type -> CanBeSet( n, schnm );
}
int
SDAI_Select::IsUnique( const BASE_TYPE bt ) const {
if( bt == ARRAY_TYPE ||
bt == LIST_TYPE ||
bt == BAG_TYPE ||
bt == SET_TYPE ) {
return ( ( _type->UniqueElements() ) & AGGREGATE_TYPE );
} else {
return ( ( _type->UniqueElements() ) & bt );
}
}
SDAI_String SDAI_Select::UnderlyingTypeName() const {
return underlying_type -> Name();
}
const TypeDescriptor * SDAI_Select::CurrentUnderlyingType() const {
return underlying_type;
}
const TypeDescriptor *
SDAI_Select::SetUnderlyingType( const TypeDescriptor * td ) {
// don\'t do anything if the descriptor is bad
if( !td || !( _type -> CanBe( td ) ) ) {
return 0;
}
base_type = td -> NonRefType();
return underlying_type = td;
}
bool SDAI_Select::exists() const {
return underlying_type != NULL;
}
void SDAI_Select::nullify() {
underlying_type = 0;
}
Severity SDAI_Select::SelectValidLevel( const char * attrValue, ErrorDescriptor * err,
InstMgrBase * im ) {
SDAI_Select * tmp = NewSelect();
Severity s = SEVERITY_NULL;
istringstream strtmp( attrValue );
s = tmp -> STEPread( strtmp, err, im );
delete tmp;
return s;
}
Severity SDAI_Select::StrToVal( const char * Val, const char * selectType,
ErrorDescriptor * err, InstMgrBase * instances ) {
severity( SEVERITY_NULL );
if( SetUnderlyingType( CanBe( selectType ) ) )
// the underlying type is set to a valid type
// call read on underlying type in subclass
switch( base_type ) {
case ENTITY_TYPE: {
STEPentity * tmp =
ReadEntityRef( Val, err, ",)", instances, 0 );
if( tmp && ( tmp != ENTITY_NULL ) ) {
AssignEntity( tmp );
return severity();
} else {
err->AppendToDetailMsg(
"Reference to entity that is not a valid type for SELECT.\n" );
nullify();
err->GreaterSeverity( SEVERITY_WARNING );
return SEVERITY_WARNING;
}
}
// call StrToVal on the contents
case STRING_TYPE:
case AGGREGATE_TYPE:
case ARRAY_TYPE: // DAS
case BAG_TYPE: // DAS
case SET_TYPE: // DAS
case LIST_TYPE: // DAS
case ENUM_TYPE:
case SELECT_TYPE:
case BOOLEAN_TYPE:
case LOGICAL_TYPE: {
err->GreaterSeverity( StrToVal_content( Val, instances ) );
if( _error.severity() != SEVERITY_NULL ) {
err->AppendFromErrorArg( &_error );
}
return err->severity();
}
// do the same as STEPread_content
case BINARY_TYPE:
case NUMBER_TYPE:
case REAL_TYPE:
case INTEGER_TYPE:
default: {
istringstream strtmp( Val );
err->GreaterSeverity( STEPread_content( strtmp ) );
if( _error.severity() != SEVERITY_NULL ) {
err->AppendFromErrorArg( &_error );
}
return err->severity();
}
}
return SEVERITY_INPUT_ERROR;
}
/** updated to Technical Corrigendum. DAS 2/4/97
* This function does the following:
*/
Severity SDAI_Select::STEPread( istream & in, ErrorDescriptor * err,
InstMgrBase * instances, const char * utype,
int addFileId, const char * currSch ) {
char c = '\0';
std::string tmp;
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Entering SDAI_Select::STEPread." << endl;
#endif
// find out what case we have
// NOTE case C falls out of recursive calls in cases A and B
/**
** This section of code is used to read a value belonging to a select
** contained in another select. If you have read the text part of the
** TYPED_PARAMETER and it needs to fall down through some levels of contained
** select types, then the text is passed down to each select in the utype
** parameter as STEPread is called on each contained select type.DAS 2/4/97
*/
if( utype ) {
if( SetUnderlyingType( CanBeSet( utype, currSch ) ) ) {
// assign the value to the underlying type
in >> ws; // skip white space
if( ( underlying_type->Type() == REFERENCE_TYPE ) &&
( underlying_type->NonRefType() == sdaiSELECT ) ) {
// See comments below for a similar code segment.
STEPread_content( in, instances, 0, addFileId, currSch );
} else {
STEPread_content( in, instances, utype, addFileId, currSch );
}
err->AppendToDetailMsg( Error() );
err->GreaterSeverity( severity() );
}
return err->severity();
}
in >> ws;
in >> c;
/**
** the if part of this code reads a value according to the Technical
** Corrigendum for Part 21 (except for Entity instance refs which are read
** in the else part - everything else in the else stmt is invalid). The
** idea here is to read text and find out if it is specifying the final
** type or is a simple defined type which is typed to be a select some
** number of levels down. The first case will cause the value to be read
** directly by STEPread_content() or will cause STEPread_content() to pass
** the text naming the type to the underlying Select containing it. When
** the latter is the case, STEPread_content calls STEPread for the
** contained select and passes in the text. The convoluted case is when
** the text describes a simple defined type that translates directly into
** a select some number of levels down. In this case there will be more
** text inside the containing parens to indicate the type. Since the text
** specifying the type still needs to be read utype is passed as null which
** will cause the contained Select STEPread function to read it. DAS 2/4/97
*/
if( isalpha( c ) ) { // case B
int eot = 0; // end of token flag
// token is a type name - get the type
while( ( c != '(' ) && in.good() ) {
if( !eot && !( eot = isspace( c ) ) )
// as long as eot hasn\'t been reached keep appending
{
tmp += c;
}
in >> c;
}
// check for valid type and set the underlying type
if( SetUnderlyingType( CanBeSet( tmp.c_str(), currSch ) ) ) {
/**
** Assign the value to the underlying type. CanBeSet() is a
** slightly modified CanBe(). It ensures that a renamed select
** type (see big comment below) "CantBe" one of its member items.
** This is because such a select type requires its own name to
** appear first ("selX("), so even if we read a valid element of
** selX, selX can't be the underlying type. That can only be the
** case if "selX" appears first and is what we just read.
*/
in >> ws; // skip white space
if( ( underlying_type->Type() == REFERENCE_TYPE ) &&
( underlying_type->NonRefType() == sdaiSELECT ) ) {
/**
* This means (1) that the underlying type is itself a select
** (cond 2), and (2) it's not defined in the EXPRESS as a
** select, but as a renamed select. (E.g., TYPE sel2 = sel1.)
** In such a case, according to the TC, "sel2(" must appear in
** the text. (We must have found one for SetUnderlyingType()
** above to set underlying_type to sel2.) If all of the above
** is true, we read "sel2" but not the value of sel2. We
** therefore do not pass down what we read to STEPread_content
** below, so that we can still read the value of sel2. If,
** however, under_type was a non-renamed select, no "sel1"
** would appear (according to TC) and we already read the value
** of sel1. If so, we pass the already-read value down.
*/
STEPread_content( in, instances, 0, addFileId, currSch );
} else {
/**
** In most cases (see above note), we've already read the value
** we're interested in.
** This also handles all other cases? other than the if part
** above and elements of type entity ref?
*/
STEPread_content( in, instances, tmp.c_str(), addFileId,
currSch );
// STEPread_content uses the ErrorDesc data member from the
// SDAI_Select class
}
err->AppendToDetailMsg( Error() );
err->GreaterSeverity( severity() );
in >> ws >> c;
if( c != ')' ) {
err->AppendToDetailMsg(
"Bad data or missing closing ')' for SELECT type.\n" );
err->GreaterSeverity( SEVERITY_WARNING );
in.putback( c );
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Exiting SDAI_Select::STEPread for " << _type->Name() << endl;
#endif
return SEVERITY_WARNING;
}
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Exiting SDAI_Select::STEPread for " << _type->Name() << endl;
#endif
return err->severity();
} else { // ERROR -- the type wasn't one of the choices
if( !in.good() ) {
err->GreaterSeverity( SEVERITY_INPUT_ERROR );
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Exiting SDAI_Select::STEPread for " << _type->Name() << endl;
#endif
return SEVERITY_INPUT_ERROR;
} else {
err->AppendToDetailMsg(
"The type name for the SELECT type is not valid.\n" );
err->GreaterSeverity( SEVERITY_WARNING );
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Exiting SDAI_Select::STEPread for " << _type->Name() << endl;
#endif
return SEVERITY_WARNING;
}
}
}
/**
** NOTE **** anything that gets read below here is invalid according to the
** Technical Corrigendum for Part 21 (except for reading an entity instance
** where below is the only place they get read). I am leaving all of this
** here since it is valuable to 'read what you can' and flag an error which
** is what it does (for every type but entity instance refs). DAS 2/4/97
*/
else { /// case A
switch( c ) {
case '$':
nullify();
err->GreaterSeverity( SEVERITY_INCOMPLETE );
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Exiting SDAI_Select::STEPread for " << _type->Name() << endl;
#endif
return SEVERITY_INCOMPLETE;
case ',':
case '\0':
// ERROR IN INPUT
in.putback( c );
err->AppendToDetailMsg( "No value found for SELECT type.\n" );
err->GreaterSeverity( SEVERITY_WARNING );
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Exiting SDAI_Select::STEPread for " << _type->Name() << endl;
#endif
return SEVERITY_WARNING;
case '.': // assign enum
base_type = ENUM_TYPE;
err->AppendToDetailMsg( "Invalid Enumeration, Logical, or Boolean value in SELECT type.\n" );
err->GreaterSeverity( SEVERITY_WARNING );
break;
// set the underlying type
// call STEPread
// return
case '\'': // assign string
base_type = STRING_TYPE;
err->AppendToDetailMsg( "Invalid String value in SELECT type.\n" );
err->GreaterSeverity( SEVERITY_WARNING );
break;
case '"': // assign string
base_type = BINARY_TYPE;
err->AppendToDetailMsg( "Invalid Binary value in SELECT type.\n" );
err->GreaterSeverity( SEVERITY_WARNING );
break;
case '#':
base_type = ENTITY_TYPE;
break;
// call STEPread_reference
// set the underlying type
// assign entity
// read the reference
// match type to underlying type
// assign the value
// set the underlying type
case '(': {
err->AppendToDetailMsg( "Invalid aggregate value in SELECT type.\n" );
err->GreaterSeverity( SEVERITY_WARNING );
char n;
in >> n;
in.putback( n );
if( isalpha( n ) ) {
base_type = SELECT_TYPE;
} else {
base_type = AGGREGATE_TYPE;
}
break;
}
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
err->AppendToDetailMsg( "Invalid Integer or Real value in SELECT type.\n" );
err->GreaterSeverity( SEVERITY_WARNING );
if( CanBe( REAL_TYPE ) ) {
base_type = REAL_TYPE;
} else {
base_type = INTEGER_TYPE;
}
break;
default:
// ambiguous - ERROR: underlying type should have been set
err->AppendToDetailMsg(
"type for SELECT could not be determined from value.\n" );
nullify();
in.putback( c );
err->GreaterSeverity( SEVERITY_WARNING );
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Exiting SDAI_Select::STEPread for " << _type->Name() << endl;
#endif
return SEVERITY_WARNING;
}
in.putback( c );
// now the type descriptor should be derivable from the base_type
// if it's not issue a warning
if( _type && !( IsUnique( base_type ) ) ) {
err->AppendToDetailMsg( "Value for SELECT will be assigned to first possible choice.\n" );
err->GreaterSeverity( SEVERITY_USERMSG );
}
if( base_type == ENTITY_TYPE ) {
// you don't know if this is an ENTITY or a SELECT
// have to do this here - not in STEPread_content
STEPentity * temp =
ReadEntityRef( in, err, ",)", instances, addFileId );
if( temp && ( temp != ENTITY_NULL ) && AssignEntity( temp ) ) {
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Exiting SDAI_Select::STEPread for " << _type->Name() << endl;
#endif
return SEVERITY_NULL;
} else {
err->AppendToDetailMsg(
"Reference to entity that is not a valid type for SELECT.\n" );
nullify();
err->GreaterSeverity( SEVERITY_WARNING );
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Exiting SDAI_Select::STEPread for " << _type->Name() << endl;
#endif
return SEVERITY_WARNING;
}
} else if( SetUnderlyingType( CanBe( base_type ) ) ) {
STEPread_content( in, instances, 0, addFileId );
}
else { // ERROR -- the type wasn't one of the choices
err->AppendToDetailMsg(
"The type of the SELECT type is not valid.\n" );
err->GreaterSeverity( SEVERITY_WARNING );
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Exiting SDAI_Select::STEPread for " << _type->Name() << endl;
#endif
return SEVERITY_WARNING;
}
}
// if (!in.good()) severity (SEVERITY_INPUT_ERROR);
#ifdef SC_LOGGING
// *logStream << "DAVE ERR Exiting SDAI_Select::STEPread for " << _type->Name() << endl;
#endif
return err->severity();
}
/// updated to Technical Corrigendum DAS Feb 4, 1997
void SDAI_Select::STEPwrite( ostream & out, const char * currSch ) const {
if( !exists() ) {
out << "$";
return;
}
switch( underlying_type->NonRefType() ) {
case sdaiINSTANCE: {
STEPwrite_content( out );
break;
}
case sdaiSELECT: { // The name of a select is never written DAS 1/31/97
if( underlying_type->Type() == REFERENCE_TYPE ) {
std::string s;
out << StrToUpper( underlying_type->Name( currSch ), s ) << "(";
STEPwrite_content( out, currSch );
out << ")";
} else {
STEPwrite_content( out, currSch );
}
break;
}
case sdaiNUMBER:
case sdaiREAL:
case sdaiINTEGER:
case sdaiSTRING:
case sdaiBOOLEAN:
case sdaiLOGICAL:
case sdaiBINARY:
case sdaiENUMERATION:
case sdaiAGGR:
case ARRAY_TYPE:
case BAG_TYPE:
case SET_TYPE:
case LIST_TYPE: {
STEPwrite_verbose( out, currSch );
break;
}
case REFERENCE_TYPE: // this should never happen? DAS
default:
out << "ERROR Should not have gone here in SDAI_Select::STEPwrite()"
<< endl;
}
}
void SDAI_Select::STEPwrite_verbose( ostream & out, const char * currSch ) const {
std::string tmp;
out << StrToUpper( CurrentUnderlyingType()->Name( currSch ), tmp ) << "(";
STEPwrite_content( out );
out << ")";
}
const char * SDAI_Select::STEPwrite( std::string & s, const char * currSch ) const {
ostringstream buf;
STEPwrite( buf, currSch );
buf << ends; // add the terminating \0 char
s = buf.str();
return const_cast<char *>( s.c_str() );
}
bool SDAI_Select::set_null() {
nullify();
return true;
}
bool SDAI_Select::is_null() {
return ( !exists() );
}