-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathsdaiSelect.cc
More file actions
1206 lines (1096 loc) · 40.1 KB
/
Copy pathsdaiSelect.cc
File metadata and controls
1206 lines (1096 loc) · 40.1 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/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"
#include "clstepcore/STEPaggregate.h"
#include "clstepcore/read_func.h"
#ifdef SC_LOGGING
#include <fstream.h>
extern ofstream * logStream;
#endif
class SDAI_Select::Storage {
public:
const TypeDescriptor * type;
SDAI_Integer integer_value;
SDAI_Real real_value;
SDAI_Application_instance * entity_value;
SDAI_String * string_value;
SDAI_Binary * binary_value;
SDAI_Enum * enum_value;
SDAI_Select * select_value;
STEPaggregate * aggregate_value;
Storage()
: type( 0 ), integer_value( 0 ), real_value( 0.0 ), entity_value( 0 ),
string_value( 0 ), binary_value( 0 ), enum_value( 0 ),
select_value( 0 ), aggregate_value( 0 ) {
}
~Storage() {
Clear();
}
void Clear() {
delete string_value;
delete binary_value;
delete enum_value;
delete select_value;
delete aggregate_value;
type = 0;
integer_value = 0;
real_value = 0.0;
entity_value = 0;
string_value = 0;
binary_value = 0;
enum_value = 0;
select_value = 0;
aggregate_value = 0;
}
bool Reset( const TypeDescriptor * td ) {
Clear();
if( !td ) {
return true;
}
type = td;
const TypeDescriptor * concrete = td->NonRefTypeDescriptor();
switch( td->NonRefType() ) {
case sdaiSTRING:
string_value = new SDAI_String;
break;
case sdaiBINARY:
binary_value = new SDAI_Binary;
break;
case sdaiBOOLEAN:
enum_value = new SDAI_BOOLEAN;
break;
case sdaiLOGICAL:
enum_value = new SDAI_LOGICAL;
break;
case sdaiENUMERATION: {
const EnumTypeDescriptor * enum_type =
dynamic_cast<const EnumTypeDescriptor *>( concrete );
enum_value = enum_type ? enum_type->CreateEnum() : 0;
break;
}
case sdaiSELECT: {
const SelectTypeDescriptor * select_type =
dynamic_cast<const SelectTypeDescriptor *>( concrete );
select_value = select_type ? select_type->CreateSelect() : 0;
if( !select_value && select_type ) {
select_value = new SDAI_Select( select_type );
}
break;
}
case sdaiAGGR:
case ARRAY_TYPE:
case BAG_TYPE:
case SET_TYPE:
case LIST_TYPE: {
const AggrTypeDescriptor * aggregate_type =
dynamic_cast<const AggrTypeDescriptor *>( concrete );
aggregate_value = aggregate_type ? aggregate_type->CreateAggregate() : 0;
break;
}
default:
break;
}
if( ( td->NonRefType() == sdaiENUMERATION && !enum_value ) ||
( td->NonRefType() == sdaiSELECT && !select_value ) ||
( td->IsAggrType() && !aggregate_value ) ) {
Clear();
return false;
}
return true;
}
bool CopyFrom( const Storage & other ) {
if( !Reset( other.type ) ) {
return false;
}
if( !type ) {
return true;
}
switch( type->NonRefType() ) {
case sdaiINTEGER:
integer_value = other.integer_value;
break;
case sdaiREAL:
case sdaiNUMBER:
real_value = other.real_value;
break;
case sdaiINSTANCE:
entity_value = other.entity_value;
break;
case sdaiSTRING:
*string_value = *other.string_value;
break;
case sdaiBINARY:
*binary_value = *other.binary_value;
break;
case sdaiBOOLEAN:
case sdaiLOGICAL:
case sdaiENUMERATION:
*enum_value = *other.enum_value;
break;
case sdaiSELECT:
*select_value = *other.select_value;
break;
case sdaiAGGR:
case ARRAY_TYPE:
case BAG_TYPE:
case SET_TYPE:
case LIST_TYPE:
aggregate_value->ShallowCopy( *other.aggregate_value );
break;
default:
break;
}
return true;
}
void * Address() {
if( !type ) {
return 0;
}
switch( type->NonRefType() ) {
case sdaiINTEGER:
return &integer_value;
case sdaiREAL:
case sdaiNUMBER:
return &real_value;
case sdaiINSTANCE:
return entity_value;
case sdaiSTRING:
return string_value;
case sdaiBINARY:
return binary_value;
case sdaiBOOLEAN:
case sdaiLOGICAL:
case sdaiENUMERATION:
return enum_value;
case sdaiSELECT:
return select_value;
case sdaiAGGR:
case ARRAY_TYPE:
case BAG_TYPE:
case SET_TYPE:
case LIST_TYPE:
return aggregate_value;
default:
return 0;
}
}
};
/**********
(member) functions for the select class SDAI_Select
**********/
SDAI_Select::SDAI_Select( const SelectTypeDescriptor * s,
const TypeDescriptor * td )
: _storage( 0 ), _type( s ), underlying_type( td ),
base_type( td ? td->NonRefType() : UNKNOWN_TYPE ) {
#ifdef SC_LOGGING
*logStream << "Exiting SDAI_Select constructor." << endl;
#endif
}
SDAI_Select::SDAI_Select( const SDAI_Select & other )
: _storage( 0 ), _type( other._type ),
underlying_type( other.underlying_type ), base_type( other.base_type ),
val( other.val ), _error( other._error ) {
if( other._storage ) {
_storage = new Storage;
_storage->CopyFrom( *other._storage );
}
#ifdef SC_LOGGING
*logStream << "Exiting SDAI_Select constructor." << endl;
#endif
}
SDAI_Select::~SDAI_Select() {
delete _storage;
}
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;
if( other._storage ) {
if( !_storage ) {
_storage = new Storage;
}
_storage->CopyFrom( *other._storage );
} else {
delete _storage;
_storage = 0;
}
}
return *this;
}
SDAI_Select & SDAI_Select::operator=( const SDAI_Select * other ) {
if( other ) {
return operator=( *other );
}
nullify();
return *this;
}
SDAI_Select * SDAI_Select::Clone() const {
SDAI_Select * result = _type ? _type->CreateSelect() : 0;
if( !result ) {
result = new SDAI_Select( _type );
}
*result = *this;
return result;
}
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 && !( _type -> CanBe( td ) ) ) ) {
return 0;
}
if( _storage && _storage->type != td ) {
_storage->Clear();
}
base_type = td -> NonRefType();
return underlying_type = td;
}
void * SDAI_Select::ValueAddress() {
if( !underlying_type ) {
return 0;
}
if( !_storage ) {
_storage = new Storage;
}
if( _storage->type != underlying_type && !_storage->Reset( underlying_type ) ) {
Error( "Unable to create storage for SELECT value." );
severity( SEVERITY_BUG );
return 0;
}
return _storage->Address();
}
const void * SDAI_Select::ValueAddress() const {
return const_cast<SDAI_Select *>( this )->ValueAddress();
}
SDAI_Select * SDAI_Select::NewSelect() {
SDAI_Select * result = _type ? _type->CreateSelect() : 0;
return result ? result : new SDAI_Select( _type );
}
const TypeDescriptor *
SDAI_Select::AssignEntity( SDAI_Application_instance * se ) {
if( !_type || !se ) {
return 0;
}
TypeDescItr elements( _type->GetElements() );
const TypeDescriptor * td;
while( ( td = elements.NextTypeDesc() ) ) {
const EntityDescriptor * entity_type =
dynamic_cast<const EntityDescriptor *>( td->NonRefTypeDescriptor() );
if( entity_type && se->IsA( entity_type ) ) {
SetUnderlyingType( td );
if( !_storage ) {
_storage = new Storage;
}
if( !_storage->Reset( td ) ) {
return 0;
}
_storage->entity_value = se;
return td;
}
if( td->NonRefType() == sdaiSELECT && td->CanBe( se->eDesc ) ) {
SetUnderlyingType( td );
SDAI_Select * nested = static_cast<SDAI_Select *>( ValueAddress() );
if( nested && nested->AssignEntity( se ) ) {
return td;
}
}
}
severity( SEVERITY_WARNING );
Error( "Mismatch in underlying type." );
return 0;
}
BASE_TYPE SDAI_Select::ValueType() const {
if( !underlying_type ) {
return UNKNOWN_TYPE;
}
if( underlying_type->NonRefType() == sdaiSELECT ) {
const SDAI_Select * nested =
static_cast<const SDAI_Select *>( ValueAddress() );
return nested ? nested->ValueType() : UNKNOWN_TYPE;
}
return underlying_type->NonRefType();
}
bool SDAI_Select::SetInteger( const TypeDescriptor * td, SDAI_Integer value ) {
if( !td || td->NonRefType() != sdaiINTEGER || !SetUnderlyingType( td ) ) {
return false;
}
SDAI_Integer * target = static_cast<SDAI_Integer *>( ValueAddress() );
if( target ) {
*target = value;
}
return target != 0;
}
bool SDAI_Select::SetReal( const TypeDescriptor * td, SDAI_Real value ) {
if( !td || ( td->NonRefType() != sdaiREAL && td->NonRefType() != sdaiNUMBER ) ||
!SetUnderlyingType( td ) ) {
return false;
}
SDAI_Real * target = static_cast<SDAI_Real *>( ValueAddress() );
if( target ) {
*target = value;
}
return target != 0;
}
bool SDAI_Select::SetString( const TypeDescriptor * td, const SDAI_String & value ) {
if( !td || td->NonRefType() != sdaiSTRING || !SetUnderlyingType( td ) ) {
return false;
}
SDAI_String * target = static_cast<SDAI_String *>( ValueAddress() );
if( target ) {
*target = value;
}
return target != 0;
}
bool SDAI_Select::SetBinary( const TypeDescriptor * td, const SDAI_Binary & value ) {
if( !td || td->NonRefType() != sdaiBINARY || !SetUnderlyingType( td ) ) {
return false;
}
SDAI_Binary * target = static_cast<SDAI_Binary *>( ValueAddress() );
if( target ) {
*target = value;
}
return target != 0;
}
bool SDAI_Select::SetEnum( const TypeDescriptor * td, const SDAI_Enum & value ) {
PrimitiveType kind = td ? td->NonRefType() : UNKNOWN_TYPE;
if( !td || ( kind != sdaiENUMERATION && kind != sdaiBOOLEAN && kind != sdaiLOGICAL ) ||
!SetUnderlyingType( td ) ) {
return false;
}
SDAI_Enum * target = static_cast<SDAI_Enum *>( ValueAddress() );
if( target ) {
*target = value;
}
return target != 0;
}
bool SDAI_Select::SetSelect( const TypeDescriptor * td, const SDAI_Select & value ) {
if( !td || td->NonRefType() != sdaiSELECT || !SetUnderlyingType( td ) ) {
return false;
}
SDAI_Select * target = static_cast<SDAI_Select *>( ValueAddress() );
if( target ) {
*target = value;
}
return target != 0;
}
bool SDAI_Select::SetAggregate( const TypeDescriptor * td, const STEPaggregate & value ) {
if( !td || !td->IsAggrType() || !SetUnderlyingType( td ) ) {
return false;
}
STEPaggregate * target = static_cast<STEPaggregate *>( ValueAddress() );
if( target ) {
target->ShallowCopy( value );
}
return target != 0;
}
bool SDAI_Select::SetEntity( SDAI_Application_instance * value ) {
return AssignEntity( value ) != 0;
}
SDAI_Integer * SDAI_Select::IntegerValue() {
return underlying_type && underlying_type->NonRefType() == sdaiINTEGER ?
static_cast<SDAI_Integer *>( ValueAddress() ) : 0;
}
const SDAI_Integer * SDAI_Select::IntegerValue() const {
return underlying_type && underlying_type->NonRefType() == sdaiINTEGER ?
static_cast<const SDAI_Integer *>( ValueAddress() ) : 0;
}
SDAI_Real * SDAI_Select::RealValue() {
BASE_TYPE kind = underlying_type ? underlying_type->NonRefType() : UNKNOWN_TYPE;
return ( kind == sdaiREAL || kind == sdaiNUMBER ) ?
static_cast<SDAI_Real *>( ValueAddress() ) : 0;
}
const SDAI_Real * SDAI_Select::RealValue() const {
BASE_TYPE kind = underlying_type ? underlying_type->NonRefType() : UNKNOWN_TYPE;
return ( kind == sdaiREAL || kind == sdaiNUMBER ) ?
static_cast<const SDAI_Real *>( ValueAddress() ) : 0;
}
SDAI_String * SDAI_Select::StringValue() {
return underlying_type && underlying_type->NonRefType() == sdaiSTRING ?
static_cast<SDAI_String *>( ValueAddress() ) : 0;
}
const SDAI_String * SDAI_Select::StringValue() const {
return underlying_type && underlying_type->NonRefType() == sdaiSTRING ?
static_cast<const SDAI_String *>( ValueAddress() ) : 0;
}
SDAI_Binary * SDAI_Select::BinaryValue() {
return underlying_type && underlying_type->NonRefType() == sdaiBINARY ?
static_cast<SDAI_Binary *>( ValueAddress() ) : 0;
}
const SDAI_Binary * SDAI_Select::BinaryValue() const {
return underlying_type && underlying_type->NonRefType() == sdaiBINARY ?
static_cast<const SDAI_Binary *>( ValueAddress() ) : 0;
}
SDAI_Enum * SDAI_Select::EnumValue() {
BASE_TYPE kind = underlying_type ? underlying_type->NonRefType() : UNKNOWN_TYPE;
return ( kind == sdaiENUMERATION || kind == sdaiBOOLEAN || kind == sdaiLOGICAL ) ?
static_cast<SDAI_Enum *>( ValueAddress() ) : 0;
}
const SDAI_Enum * SDAI_Select::EnumValue() const {
BASE_TYPE kind = underlying_type ? underlying_type->NonRefType() : UNKNOWN_TYPE;
return ( kind == sdaiENUMERATION || kind == sdaiBOOLEAN || kind == sdaiLOGICAL ) ?
static_cast<const SDAI_Enum *>( ValueAddress() ) : 0;
}
SDAI_Select * SDAI_Select::SelectValue() {
return underlying_type && underlying_type->NonRefType() == sdaiSELECT ?
static_cast<SDAI_Select *>( ValueAddress() ) : 0;
}
const SDAI_Select * SDAI_Select::SelectValue() const {
return underlying_type && underlying_type->NonRefType() == sdaiSELECT ?
static_cast<const SDAI_Select *>( ValueAddress() ) : 0;
}
STEPaggregate * SDAI_Select::AggregateValue() {
return underlying_type && underlying_type->IsAggrType() ?
static_cast<STEPaggregate *>( ValueAddress() ) : 0;
}
const STEPaggregate * SDAI_Select::AggregateValue() const {
return underlying_type && underlying_type->IsAggrType() ?
static_cast<const STEPaggregate *>( ValueAddress() ) : 0;
}
SDAI_Application_instance * SDAI_Select::EntityValue() const {
if( !_storage || !underlying_type || underlying_type->NonRefType() != sdaiINSTANCE ) {
return 0;
}
return _storage->entity_value;
}
bool SDAI_Select::exists() const {
return underlying_type != NULL;
}
void SDAI_Select::nullify() {
underlying_type = 0;
base_type = UNKNOWN_TYPE;
if( _storage ) {
_storage->Clear();
}
}
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;
}
void SDAI_Select::STEPwrite_content( ostream & out, const char * currSch ) const {
const void * value = ValueAddress();
if( !underlying_type || !value ) {
out << "$";
return;
}
switch( underlying_type->NonRefType() ) {
case sdaiINTEGER:
out << *static_cast<const SDAI_Integer *>( value );
break;
case sdaiREAL:
case sdaiNUMBER:
WriteReal( *static_cast<const SDAI_Real *>( value ), out );
break;
case sdaiINSTANCE:
static_cast<SDAI_Application_instance *>(
const_cast<void *>( value ) )->STEPwrite_reference( out );
break;
case sdaiSTRING:
static_cast<const SDAI_String *>( value )->STEPwrite( out );
break;
case sdaiBINARY:
static_cast<const SDAI_Binary *>( value )->STEPwrite( out );
break;
case sdaiBOOLEAN:
case sdaiLOGICAL:
case sdaiENUMERATION:
static_cast<const SDAI_Enum *>( value )->STEPwrite( out );
break;
case sdaiSELECT:
static_cast<const SDAI_Select *>( value )->STEPwrite( out, currSch );
break;
case sdaiAGGR:
case ARRAY_TYPE:
case BAG_TYPE:
case SET_TYPE:
case LIST_TYPE:
static_cast<const STEPaggregate *>( value )->STEPwrite( out, currSch );
break;
default:
out << "$";
break;
}
}
Severity SDAI_Select::STEPread_content( istream & in, InstMgrBase * instances,
const char * utype, int addFileId,
const char * currSch ) {
if( !underlying_type ) {
severity( SEVERITY_BUG );
Error( "Unable to create storage for SELECT value." );
return severity();
}
void * value = ValueAddress();
if( underlying_type->NonRefType() != sdaiINSTANCE && !value ) {
severity( SEVERITY_BUG );
Error( "Unable to create storage for SELECT value." );
return severity();
}
switch( underlying_type->NonRefType() ) {
case sdaiINTEGER:
ReadInteger( *static_cast<SDAI_Integer *>( value ), in, &_error, ")," );
break;
case sdaiREAL:
case sdaiNUMBER:
ReadReal( *static_cast<SDAI_Real *>( value ), in, &_error, ")," );
break;
case sdaiINSTANCE: {
SDAI_Application_instance * entity =
ReadEntityRef( in, &_error, ",)", instances, addFileId );
if( entity && entity != S_ENTITY_NULL && underlying_type->CanBe( entity->eDesc ) ) {
_storage->entity_value = entity;
} else {
Error( "Reference to instance that is not indicated type\n" );
nullify();
return severity( SEVERITY_USERMSG );
}
break;
}
case sdaiSTRING:
static_cast<SDAI_String *>( value )->STEPread( in, &_error );
break;
case sdaiBINARY:
static_cast<SDAI_Binary *>( value )->STEPread( in, &_error );
break;
case sdaiBOOLEAN:
case sdaiLOGICAL:
case sdaiENUMERATION:
static_cast<SDAI_Enum *>( value )->STEPread( in, &_error );
break;
case sdaiSELECT:
static_cast<SDAI_Select *>( value )->STEPread(
in, &_error, instances, utype, addFileId, currSch );
break;
case sdaiAGGR:
case ARRAY_TYPE:
case BAG_TYPE:
case SET_TYPE:
case LIST_TYPE:
static_cast<STEPaggregate *>( value )->STEPread(
in, &_error, underlying_type->AggrElemTypeDescriptor(),
instances, addFileId, currSch );
break;
default:
severity( SEVERITY_WARNING );
Error( "Mismatch in underlying type." );
break;
}
return severity();
}
Severity SDAI_Select::StrToVal_content( const char * str, InstMgrBase * instances ) {
if( !underlying_type ) {
return severity( SEVERITY_BUG );
}
void * value = ValueAddress();
if( underlying_type->NonRefType() != sdaiINSTANCE && !value ) {
return severity( SEVERITY_BUG );
}
switch( underlying_type->NonRefType() ) {
case sdaiSTRING:
return static_cast<SDAI_String *>( value )->StrToVal( str );
case sdaiBINARY:
return static_cast<SDAI_Binary *>( value )->StrToVal( str, &_error );
case sdaiBOOLEAN:
case sdaiLOGICAL:
case sdaiENUMERATION:
return static_cast<SDAI_Enum *>( value )->StrToVal( str, &_error );
case sdaiSELECT:
return static_cast<SDAI_Select *>( value )->StrToVal(
str, underlying_type->Name(), &_error, instances );
case sdaiAGGR:
case ARRAY_TYPE:
case BAG_TYPE:
case SET_TYPE:
case LIST_TYPE:
return static_cast<STEPaggregate *>( value )->StrToVal(
str, &_error, underlying_type->AggrElemTypeDescriptor(), instances );
default: {
istringstream input( str );
return STEPread_content( input, instances );
}
}
}
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" );