forked from stepcode/stepcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTEPattribute.cc
More file actions
1509 lines (1335 loc) · 46.3 KB
/
STEPattribute.cc
File metadata and controls
1509 lines (1335 loc) · 46.3 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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* NIST STEP Core Class Library
* clstepcore/STEPattribute.cc
* April 1997
* K. C. Morris
* David Sauder
* Development of this software was funded by the United States Government,
* and is not subject to copyright.
*/
#include <iomanip>
#include <string>
#include "clstepcore/read_func.h"
#include "clstepcore/STEPattribute.h"
#include "clstepcore/instmgr.h"
#include "clstepcore/STEPundefined.h"
#include "clstepcore/STEPaggregate.h"
#include "clstepcore/ExpDict.h"
#include "clstepcore/sdai.h"
// REAL_NUM_PRECISION is defined in STEPattribute.h, and is also used
// in aggregate real handling (STEPaggregate.cc) -- IMS 6 Jun 95
const int Real_Num_Precision = REAL_NUM_PRECISION;
/**
** \class STEPattribute
** Functions for manipulating attribute
**
** FIXME KNOWN BUGS:
** -- error reporting does not include line number information
** -- null attributes are only handled through the attribute pointer class
** direct access of a null attribute will not indicate whether the
** attribute is null in all cases (although a null value is available
** for entities and enumerations.)
**/
/// the value of the attribute is assigned from the supplied string
Severity STEPattribute::StrToVal( const char * s, InstMgrBase * instances, int addFileId ) {
if( _redefAttr ) {
return _redefAttr->StrToVal( s, instances, addFileId );
}
_error.ClearErrorMsg(); // also sets Severity to SEVERITY_NULL
// set the value to be null (reinitialize the attribute value)
set_null();
int nullable = ( aDesc->Optional().asInt() == BTrue );
// an empty str gets assigned NULL
if( !s ) {
if( nullable || IsDerived() ) { // if it is derived it doesn't
return SEVERITY_NULL; // matter if it is null DAS
} else {
_error.severity( SEVERITY_INCOMPLETE );
return SEVERITY_INCOMPLETE;
}
}
if( s[0] == '\0' ) {
if( NonRefType() == STRING_TYPE ) {
// this is interpreted as a string with no value i.e. "".
*( ptr.S ) = s; // using string class - don't need to declare space
return SEVERITY_NULL;
}
if( nullable || IsDerived() ) { // if it is derived it doesn't
return SEVERITY_NULL; // matter if it is null DAS
} else {
_error.severity( SEVERITY_INCOMPLETE );
return SEVERITY_INCOMPLETE;
}
}
// an overridden attribute always has a \'*\' value
if( IsDerived() ) { // check to see if value contains: optional space,
// followed by *, followed by optional space
const char * tmpSptr = s;
while( isspace( *tmpSptr ) ) {
tmpSptr++;
}
if( *tmpSptr == '*' ) {
tmpSptr++;
char tmpC;
int charsFound = sscanf( tmpSptr, "%c", &tmpC );
if( charsFound == EOF ) { // no non-white chars followed the *
return SEVERITY_NULL;
}
}
_error.AppendToDetailMsg(
"Derived attribute must have \'*\' for its value.\n" );
return _error.severity( SEVERITY_INPUT_ERROR );
}
istringstream in( ( char * )s ); // sz defaults to length of s
// read in value for attribute
switch( NonRefType() ) {
case INTEGER_TYPE: {
ReadInteger( *( ptr.i ), s, &_error, 0 );
break;
}
case REAL_TYPE: {
ReadReal( *( ptr.r ), s, &_error, 0 );
break;
}
case NUMBER_TYPE: {
ReadNumber( *( ptr.r ), s, &_error, 0 );
break;
}
case ENTITY_TYPE: {
STEPentity * se = ReadEntityRef( s, &_error, 0, instances, addFileId );
if( se != S_ENTITY_NULL ) {
if( EntityValidLevel( se, aDesc->NonRefTypeDescriptor(),
&_error )
== SEVERITY_NULL ) {
*( ptr.c ) = se;
} else {
*( ptr.c ) = S_ENTITY_NULL;
}
} else {
*( ptr.c ) = S_ENTITY_NULL;
}
break;
}
case BINARY_TYPE: {
ptr.b->StrToVal( s, &_error ); // call class SDAI_Binary::StrToVal()
break;
}
case STRING_TYPE: {
*( ptr.S ) = s; // using string class - don't need to declare space
break;
}
case BOOLEAN_TYPE:
case LOGICAL_TYPE:
case ENUM_TYPE: {
ptr.e->StrToVal( s, &_error, nullable );
break;
}
case AGGREGATE_TYPE:
case ARRAY_TYPE: // DAS
case BAG_TYPE: // DAS
case SET_TYPE: // DAS
case LIST_TYPE: // DAS
ptr.a -> StrToVal( s, &_error,
aDesc -> AggrElemTypeDescriptor(),
instances, addFileId );
break;
case SELECT_TYPE:
if( _error.severity( ptr.sh->STEPread( in, &_error, instances, 0 ) )
!= SEVERITY_NULL ) {
_error.AppendToDetailMsg( ptr.sh ->Error() );
}
break;
// case UNKNOWN_TYPE: // should never have this case
case GENERIC_TYPE:
default:
// other cases are the same for StrToVal and file
return STEPread( in, instances, addFileId );
}
return _error.severity();
}
/**************************************************************//**
** \fn STEPread
** \brief Reads attribute value from in, formatted as P21 file.
** The value of the attribute is read from istream. The format
** expected is STEP exchange file.
**
** Accepts '$' or nothing as value for OPTIONAL ATTRIBUTE, since
** this function is used for reading files in both old an new
** formats.
**
** Does not read the delimiter separating individual attributes (i.e. ',') or
** the delim separating the last attribute from the end of the entity (')').
**
** \returns Severity, which indicates success or failure
** value >= SEVERITY_WARNING means program can continue parsing input,
** value <= SEVERITY_INPUT_ERROR is fatal read error
******************************************************************/
Severity STEPattribute::STEPread( istream & in, InstMgrBase * instances, int addFileId,
const char * currSch, bool strict ) {
// The attribute has been redefined by the attribute pointed
// to by _redefAttr so write the redefined value.
if( _redefAttr ) {
return _redefAttr->STEPread( in, instances, addFileId, currSch );
}
_error.ClearErrorMsg(); // also sets Severity to SEVERITY_NULL
// set the value to be null (reinitialize the attribute value)
set_null();
in >> ws; // skip whitespace
char c = in.peek();
if( IsDerived() ) {
if( c == '*' ) {
in.get( c ); // take * off the istream
_error.severity( SEVERITY_NULL );
} else {
_error.severity( SEVERITY_WARNING );
_error.AppendToDetailMsg( " WARNING: attribute '" );
_error.AppendToDetailMsg( aDesc->Name() );
_error.AppendToDetailMsg( "' of type '" );
_error.AppendToDetailMsg( aDesc->TypeName() );
_error.AppendToDetailMsg( "' - missing asterisk for derived attribute.\n" );
}
CheckRemainingInput( in, &_error, aDesc->TypeName(), ",)" );
return _error.severity();
}
PrimitiveType attrBaseType = NonRefType();
// check for NULL or derived attribute value, return if either
switch( c ) {
case '$':
case ',':
case ')':
if( c == '$' ) {
in.ignore();
CheckRemainingInput( in, &_error, aDesc->TypeName(), ",)" );
}
if( Nullable() ) {
_error.severity( SEVERITY_NULL );
} else if( !strict ) {
std::string fillerValue;
// we aren't in strict mode, so find out the type of the missing attribute and insert a suitable value.
ErrorDescriptor err; //this will be discarded
switch( attrBaseType ) {
case INTEGER_TYPE: {
fillerValue = "'0',";
ReadInteger( *( ptr.i ), fillerValue.c_str(), &err, ",)" );
break;
}
case REAL_TYPE: {
fillerValue = "'0.0',";
ReadReal( *( ptr.r ), fillerValue.c_str(), &err, ",)" );
break;
}
case NUMBER_TYPE: {
fillerValue = "'0',";
ReadNumber( *( ptr.r ), fillerValue.c_str(), &err, ",)" );
break;
}
case STRING_TYPE: {
fillerValue = "'',";
*( ptr.S ) = "''";
break;
}
default: { //do not know what a good value would be for other types
_error.severity( SEVERITY_INCOMPLETE );
_error.AppendToDetailMsg( " missing and required\n" );
return _error.severity();
}
}
if( err.severity() <= SEVERITY_INCOMPLETE ) {
_error.severity( SEVERITY_BUG );
_error.AppendToDetailMsg( " Error in STEPattribute::STEPread()\n" );
return _error.severity();
}
//create a warning. SEVERITY_WARNING makes more sense to me, but is considered more severe than SEVERITY_INCOMPLETE
_error.severity( SEVERITY_USERMSG );
_error.AppendToDetailMsg( " missing and required. For compatibility, replacing with " );
_error.AppendToDetailMsg( fillerValue.substr( 0, fillerValue.length() - 1 ) );
_error.AppendToDetailMsg( ".\n" );
} else {
_error.severity( SEVERITY_INCOMPLETE );
_error.AppendToDetailMsg( " missing and required\n" );
}
return _error.severity();
}
switch( attrBaseType ) {
case INTEGER_TYPE: {
ReadInteger( *( ptr.i ), in, &_error, ",)" );
return _error.severity();
}
case REAL_TYPE: {
ReadReal( *( ptr.r ), in, &_error, ",)" );
return _error.severity();
}
case NUMBER_TYPE: {
ReadNumber( *( ptr.r ), in, &_error, ",)" );
return _error.severity();
}
case STRING_TYPE: {
ptr.S->STEPread( in, &_error );
CheckRemainingInput( in, &_error, "string", ",)" );
return _error.severity();
}
case BINARY_TYPE: {
// call class SDAI_Binary::STEPread()
ptr.b->STEPread( in, &_error );
CheckRemainingInput( in, &_error, "binary", ",)" );
return _error.severity();
}
case BOOLEAN_TYPE: {
ptr.e->STEPread( in, &_error, Nullable() );
CheckRemainingInput( in, &_error, "boolean", ",)" );
return _error.severity();
}
case LOGICAL_TYPE: {
ptr.e->STEPread( in, &_error, Nullable() );
CheckRemainingInput( in, &_error, "logical", ",)" );
return _error.severity();
}
case ENUM_TYPE: {
ptr.e->STEPread( in, &_error, Nullable() );
CheckRemainingInput( in, &_error, "enumeration", ",)" );
return _error.severity();
}
case AGGREGATE_TYPE:
case ARRAY_TYPE: // DAS
case BAG_TYPE: // DAS
case SET_TYPE: // DAS
case LIST_TYPE: { // DAS
ptr.a->STEPread( in, &_error,
aDesc->AggrElemTypeDescriptor(),
instances, addFileId, currSch );
// cannot recover so give up and let STEPentity recover
if( _error.severity() < SEVERITY_WARNING ) {
return _error.severity();
}
// check for garbage following the aggregate
CheckRemainingInput( in, &_error, "aggregate", ",)" );
return _error.severity();
}
case ENTITY_TYPE: {
STEPentity * se = ReadEntityRef( in, &_error, ",)", instances,
addFileId );
if( se != S_ENTITY_NULL ) {
if( EntityValidLevel( se,
aDesc->NonRefTypeDescriptor(),
&_error ) == SEVERITY_NULL ) {
*( ptr.c ) = se;
} else {
*( ptr.c ) = S_ENTITY_NULL;
}
} else {
*( ptr.c ) = S_ENTITY_NULL;
}
return _error.severity();
}
case SELECT_TYPE:
if( _error.severity( ptr.sh->STEPread( in, &_error, instances, 0,
addFileId, currSch ) )
!= SEVERITY_NULL ) {
_error.AppendToDetailMsg( ptr.sh ->Error() );
}
CheckRemainingInput( in, &_error, "select", ",)" );
return _error.severity();
case GENERIC_TYPE: {
cerr << "Internal error: " << __FILE__ << __LINE__
<< "\n" << _POC_ "\n";
_error.GreaterSeverity( SEVERITY_BUG );
return _error.severity();
}
case UNKNOWN_TYPE:
case REFERENCE_TYPE:
default: {
// bug
cerr << "Internal error: " << __FILE__ << __LINE__
<< "\n" << _POC_ "\n";
_error.GreaterSeverity( SEVERITY_BUG );
return _error.severity();
}
}
}
/*****************************************************************//**
** \fn asStr
** \param currSch - used for select type writes. See commenting in SDAI_Select::STEPwrite().
** \returns the value of the attribute
** Status: complete 3/91
*********************************************************************/
const char * STEPattribute::asStr( std::string & str, const char * currSch ) const {
ostringstream ss;
str.clear();
// The attribute has been derived by a subtype's attribute
if( IsDerived() ) {
str = "*";
return const_cast<char *>( str.c_str() );
}
// The attribute has been redefined by the attribute pointed
// to by _redefAttr so write the redefined value.
if( _redefAttr ) {
return _redefAttr->asStr( str, currSch );
}
if( is_null() ) {
str = "";
return const_cast<char *>( str.c_str() );
}
switch( NonRefType() ) {
case INTEGER_TYPE:
ss << *( ptr.i );
str += ss.str();
break;
case NUMBER_TYPE:
case REAL_TYPE:
ss.precision( ( int ) Real_Num_Precision );
ss << *( ptr.r );
str += ss.str();
break;
case ENTITY_TYPE:
// print instance id only if not empty pointer
// and has value assigned
if( ( *( ptr.c ) == S_ENTITY_NULL ) || ( *( ptr.c ) == 0 ) ) {
break;
} else {
( *( ptr.c ) )->STEPwrite_reference( str );
}
break;
case BINARY_TYPE:
if( !( ( ptr.b )->empty() ) ) {
( ptr.b ) -> STEPwrite( str );
}
break;
case STRING_TYPE:
if( !( ( ptr.S )->empty() ) ) {
return ( ptr.S ) -> asStr( str );
}
break;
case AGGREGATE_TYPE:
case ARRAY_TYPE: // DAS
case BAG_TYPE: // DAS
case SET_TYPE: // DAS
case LIST_TYPE: // DAS
return ptr.a->asStr( str ) ;
case ENUM_TYPE:
case BOOLEAN_TYPE:
case LOGICAL_TYPE:
return ptr.e -> asStr( str );
case SELECT_TYPE:
ptr.sh -> STEPwrite( str, currSch );
return const_cast<char *>( str.c_str() );
case REFERENCE_TYPE:
case GENERIC_TYPE:
cerr << "Internal error: " << __FILE__ << __LINE__
<< "\n" << _POC_ "\n";
return 0;
case UNKNOWN_TYPE:
default:
return ( ptr.u -> asStr( str ) );
}
return const_cast<char *>( str.c_str() );
}
/*****************************************************************//**
** \fn asStr
** \param currSch - used for select type writes. See commenting in SDAI_Select::STEPwrite().
** \returns the value of the attribute
** Status: complete 3/91
*********************************************************************/
std::string STEPattribute::asStr( const char * currSch ) const {
ostringstream ss;
std::string str;
// The attribute has been derived by a subtype's attribute
if( IsDerived() ) {
str = "*";
return str;
}
// The attribute has been redefined by the attribute pointed
// to by _redefAttr so write the redefined value.
if( _redefAttr ) {
return _redefAttr->asStr( currSch );
}
if( is_null() ) {
return str;
}
switch( NonRefType() ) {
case INTEGER_TYPE:
ss << *( ptr.i );
str += ss.str();
break;
case NUMBER_TYPE:
case REAL_TYPE:
ss.precision( ( int ) Real_Num_Precision );
ss << *( ptr.r );
str += ss.str();
break;
case ENTITY_TYPE:
// print instance id only if not empty pointer
// and has value assigned
if( ( *( ptr.c ) == S_ENTITY_NULL ) || ( *( ptr.c ) == 0 ) ) {
break;
} else {
( *( ptr.c ) )->STEPwrite_reference( str );
}
break;
case BINARY_TYPE:
if( !( ptr.b->empty() ) ) {
ptr.b->STEPwrite( str );
}
break;
case STRING_TYPE:
if( !( ( ptr.S )->empty() ) ) {
ptr.S->asStr( str );
}
break;
case AGGREGATE_TYPE:
case ARRAY_TYPE: // DAS
case BAG_TYPE: // DAS
case SET_TYPE: // DAS
case LIST_TYPE: // DAS
ptr.a->asStr( str );
break;
case ENUM_TYPE:
case BOOLEAN_TYPE:
case LOGICAL_TYPE:
ptr.e->asStr( str );
break;
case SELECT_TYPE:
ptr.sh->STEPwrite( str, currSch );
break;
case REFERENCE_TYPE:
case GENERIC_TYPE:
cerr << "Internal error: " << __FILE__ << __LINE__
<< "\n" << _POC_ "\n";
str.clear();
break;
case UNKNOWN_TYPE:
default:
ptr.u->asStr( str );
}
return str;
}
/// write '$' to out, put message in error, write brief error to stderr
void STEPattribute::STEPwriteError( ostream & out, unsigned int line, const char* desc ) {
out << "$";
cerr << "Internal error: " << __FILE__ << ":" << line << "\n" << _POC_ "\n";
_error.GreaterSeverity( SEVERITY_BUG );
std::stringstream ss;
ss << " Warning: attribute '" << Name() << " : " << TypeName() << "' " << desc << std::endl;
_error.AppendToUserMsg( ss.str() );
_error.AppendToDetailMsg( ss.str() );
}
/**
* The value of the attribute is printed to the output stream specified by out.
* The output is in physical file format.
*
*/
void STEPattribute::STEPwrite( ostream & out, const char * currSch ) {
// The attribute has been derived by a subtype's attribute
if( IsDerived() ) {
out << "*";
return;
}
// The attribute has been redefined by the attribute pointed
// to by _redefAttr so write the redefined value.
if( _redefAttr ) {
_redefAttr->STEPwrite( out );
return;
}
if( is_null() ) {
out << "$";
return;
}
switch( NonRefType() ) {
case INTEGER_TYPE:
out << *( ptr.i );
break;
case NUMBER_TYPE:
case REAL_TYPE: {
WriteReal( *( ptr.r ), out );
break;
}
case ENTITY_TYPE:
// print instance id only if not empty pointer
if( ( ptr.c == 0 ) || ( *( ptr.c ) == 0 ) ||
// no value was assigned <-- this would be a BUG
( *( ptr.c ) == S_ENTITY_NULL ) ) {
STEPwriteError( out, __LINE__, "is null and shouldn't be." );
} else {
( *( ptr.c ) ) -> STEPwrite_reference( out );
}
break;
case STRING_TYPE:
// if null pointer or pointer to a string of length zero
if( ptr.S ) {
( ptr.S ) -> STEPwrite( out );
} else {
STEPwriteError( out, __LINE__, "should be pointing at an SDAI_String." );
}
break;
case BINARY_TYPE:
// if null pointer or pointer to a string of length zero
if( ptr.b ) {
( ptr.b ) -> STEPwrite( out );
} else {
STEPwriteError( out, __LINE__, "should be pointing at an SDAI_Binary." );
}
break;
case AGGREGATE_TYPE:
case ARRAY_TYPE: // DAS
case BAG_TYPE: // DAS
case SET_TYPE: // DAS
case LIST_TYPE: // DAS
ptr.a -> STEPwrite( out, currSch );
break;
case ENUM_TYPE:
case BOOLEAN_TYPE:
case LOGICAL_TYPE:
if( ptr.e ) {
ptr.e -> STEPwrite( out );
} else {
STEPwriteError( out, __LINE__, "should be pointing at a SDAI_Enum class." );
}
break;
case SELECT_TYPE:
if( ptr.sh ) {
ptr.sh -> STEPwrite( out, currSch );
} else {
STEPwriteError( out, __LINE__, "should be pointing at a SDAI_Select class." );
}
break;
case REFERENCE_TYPE:
case GENERIC_TYPE:
cerr << "Internal error: " << __FILE__ << ":" << __LINE__ << "\n" << _POC_ "\n";
_error.GreaterSeverity( SEVERITY_BUG );
return;
case UNKNOWN_TYPE:
default:
ptr.u -> STEPwrite( out );
break;
}
}
void STEPattribute::ShallowCopy( const STEPattribute * sa ) {
_mustDeletePtr = false;
aDesc = sa->aDesc;
refCount = 0;
_derive = sa->_derive;
_redefAttr = sa->_redefAttr;
if( _redefAttr ) {
_redefAttr->ShallowCopy( sa );
}
//Should we just use memcpy()? That would be a true shallowCopy
switch( sa->NonRefType() ) {
case INTEGER_TYPE:
ptr.i = sa->ptr.i;
break;
case BINARY_TYPE:
ptr.b = sa->ptr.b;
break;
case STRING_TYPE:
ptr.S = sa->ptr.S;
break;
case REAL_TYPE:
case NUMBER_TYPE:
ptr.r = sa->ptr.r;
break;
case ENTITY_TYPE:
ptr.c = sa->ptr.c;
break;
case ARRAY_TYPE: // DAS
case BAG_TYPE: // DAS
case SET_TYPE: // DAS
case LIST_TYPE: // DAS
switch( sa->BaseType() ) {
case sdaiAGGR:
ptr.a = new GenericAggregate;
break;
case sdaiINSTANCE:
ptr.a = new EntityAggregate;
break;
case sdaiSELECT:
ptr.a = new SelectAggregate;
break;
case sdaiSTRING:
ptr.a = new StringAggregate;
break;
case sdaiBINARY:
ptr.a = new BinaryAggregate;
break;
case sdaiENUMERATION:
ptr.a = new EnumAggregate;
break;
case sdaiBOOLEAN:
ptr.a = new BOOLEANS;
break;
case sdaiLOGICAL:
ptr.a = new LOGICALS;
break;
case sdaiREAL:
case sdaiNUMBER:
ptr.a = new RealAggregate;
break;
case sdaiINTEGER:
ptr.a = new IntAggregate;
break;
default:
std::cerr << "WARNING: Reached default case for BaseType() in STEPattribute::"
<< "ShallowCopy(). New attribute may be invalid." << std::endl;
ptr.a = new STEPaggregate;
break;
}
ptr.a->ShallowCopy( *( sa->ptr.a ) );
_mustDeletePtr = true;
break;
case SELECT_TYPE:
ptr.sh = sa->ptr.sh;
break;
case BOOLEAN_TYPE:
ptr.e = new SDAI_BOOLEAN;
ptr.e->put( sa->ptr.e->asInt() );
_mustDeletePtr = true;
break;
case LOGICAL_TYPE:
ptr.e = new SDAI_LOGICAL;
ptr.e->put( sa->ptr.e->asInt() );
_mustDeletePtr = true;
break;
case AGGREGATE_TYPE:
case ENUM_TYPE:
default:
std::cerr << "WARNING: Reached default case for NonRefType() in STEPattribute::"
<< "ShallowCopy(). New attribute may be invalid." << std::endl;
memcpy( & ptr, & ( sa->ptr ), sizeof( sa->ptr ) );
break;
}
}
/**
* for a string attribute this means, make it not exist i.e. SDAI_String
* will exist in member variable ptr but SDAI_string will be told to report
* as not containing a value (even a value of no chars).
*/
Severity STEPattribute::set_null() {
if( _redefAttr ) {
return _redefAttr->set_null();
}
switch( NonRefType() ) {
case INTEGER_TYPE:
*( ptr.i ) = S_INT_NULL;
break;
case NUMBER_TYPE:
*( ptr.r ) = S_NUMBER_NULL;
break;
case REAL_TYPE:
*( ptr.r ) = S_REAL_NULL;
break;
case ENTITY_TYPE:
*( ptr.c ) = S_ENTITY_NULL;
break;
case STRING_TYPE:
ptr.S->clear();
break;
case BINARY_TYPE:
ptr.b ->clear();
break;
case AGGREGATE_TYPE:
case ARRAY_TYPE: // DAS
case BAG_TYPE: // DAS
case SET_TYPE: // DAS
case LIST_TYPE: { // DAS
ptr.a -> Empty();
break;
}
case ENUM_TYPE:
case BOOLEAN_TYPE:
case LOGICAL_TYPE:
ptr.e -> set_null();
break;
case SELECT_TYPE:
ptr.sh -> set_null();
break;
case REFERENCE_TYPE:
case GENERIC_TYPE:
cerr << "Internal error: " << __FILE__ << ":" << __LINE__ << "\n" << _POC_ "\n";
return SEVERITY_BUG;
case UNKNOWN_TYPE:
default:
ptr.u -> set_null();
std::stringstream err;
err << " Warning: attribute '" << Name() << " : " << TypeName() << " : ";
err << Type() << "' - " << "Don't know how to make attribute NULL" << std::endl;
_error.AppendToDetailMsg( err.str() );
_error.GreaterSeverity( SEVERITY_WARNING );
return SEVERITY_WARNING;
}
if( Nullable() ) {
return SEVERITY_NULL;
} else {
return SEVERITY_INCOMPLETE;
}
}
/**
* For a string value this reports whether the string exists (as reported by
* SDAI_String ) not whether SDAI_String contains a null string.
*/
bool STEPattribute::is_null() const {
if( _redefAttr ) {
return _redefAttr->is_null();
}
/* for NUMBER_TYPE and REAL_TYPE, we want an exact comparison. however, doing so causes a compiler warning.
* workaround is to use memcmp. need a variable, but can't declare it within the switch without errors.
*/
SDAI_Real z;
switch( NonRefType() ) {
case INTEGER_TYPE:
return ( *( ptr.i ) == S_INT_NULL );
case NUMBER_TYPE:
z = S_NUMBER_NULL;
return ( 0 == memcmp( ptr.r, &z, sizeof z ) );
case REAL_TYPE:
z = S_REAL_NULL;
return ( 0 == memcmp( ptr.r, &z, sizeof z ) );
case ENTITY_TYPE:
return ( *( ptr.c ) == S_ENTITY_NULL );
case STRING_TYPE:
return ( *( ptr.S ) == S_STRING_NULL );
case BINARY_TYPE:
return ptr.b->empty();
case AGGREGATE_TYPE:
case ARRAY_TYPE: // DAS
case BAG_TYPE: // DAS
case SET_TYPE: // DAS
case LIST_TYPE: { // DAS
return ( ptr.a -> is_null() );
}
case ENUM_TYPE:
case BOOLEAN_TYPE:
case LOGICAL_TYPE:
return ( ptr.e -> is_null() );
case SELECT_TYPE:
return( ptr.sh->is_null() );
case REFERENCE_TYPE:
case GENERIC_TYPE:
//should be an error, but this is a const function - no way to report.
return true;
case UNKNOWN_TYPE:
default:
return ( ptr.u -> is_null() );
}
}
// these get the attr value
SDAI_Integer * STEPattribute::Integer(){
if( NonRefType() == INTEGER_TYPE ) {
return ptr.i;
}
return 0;
}
SDAI_Real * STEPattribute::Number() {
if( NonRefType() == NUMBER_TYPE ) {
return ptr.r;
}
return 0;
}
SDAI_Real * STEPattribute::Real() {
if( NonRefType() == REAL_TYPE ) {
return ptr.r;
}
return 0;
}
SDAI_Application_instance * STEPattribute::Entity() {
if( NonRefType() == ENTITY_TYPE ) {
return *( ptr.c );
}
return 0;
}
SDAI_String * STEPattribute::String() {
if( NonRefType() == STRING_TYPE ) {
return ptr.S;
}
return 0;
}
SDAI_Binary * STEPattribute::Binary() {
if( NonRefType() == BINARY_TYPE ) {
return ptr.b;
}
return 0;
}
STEPaggregate * STEPattribute::Aggregate() {
if( ( NonRefType() == AGGREGATE_TYPE ) || ( NonRefType() == ARRAY_TYPE ) || ( NonRefType() == BAG_TYPE )
|| ( NonRefType() == SET_TYPE ) || ( NonRefType() == LIST_TYPE ) ) {
return ptr.a;
}
return 0;
}
SDAI_BOOLEAN * STEPattribute::Boolean() {
if( NonRefType() == BOOLEAN_TYPE ) {
return ( SDAI_BOOLEAN * ) ptr.e;
}
return 0;
}
SDAI_LOGICAL * STEPattribute::Logical() {
if( NonRefType() == LOGICAL_TYPE ) {
return ( SDAI_LOGICAL * ) ptr.e;
}
return 0;
}
SDAI_Enum * STEPattribute::Enum() {
if( NonRefType() == ENUM_TYPE ) {
return ptr.e;
}
return 0;
}
SDAI_Select * STEPattribute::Select() {
if( NonRefType() == SELECT_TYPE ) {
return ptr.sh;
}
return 0;
}
SCLundefined * STEPattribute::Undefined() {
if( ( NonRefType() != REFERENCE_TYPE ) && ( NonRefType() != GENERIC_TYPE ) ) {
return ptr.u;