-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathExpDict.cc
More file actions
1785 lines (1516 loc) · 48.6 KB
/
ExpDict.cc
File metadata and controls
1785 lines (1516 loc) · 48.6 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/ExpDict.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 <scl_cf.h>
#include <memory.h>
#include <math.h>
#include <stdio.h>
#include <ExpDict.h>
#include <STEPaggregate.h>
#include "scl_memmgr.h"
Explicit_item_id__set::Explicit_item_id__set( int defaultSize ) {
_bufsize = defaultSize;
_buf = new Explicit_item_id_ptr[_bufsize];
_count = 0;
}
Explicit_item_id__set::~Explicit_item_id__set() {
delete [] _buf;
}
void Explicit_item_id__set::Check( int index ) {
Explicit_item_id_ptr * newbuf;
if( index >= _bufsize ) {
_bufsize = ( index + 1 ) * 2;
newbuf = new Explicit_item_id_ptr[_bufsize];
memmove( newbuf, _buf, _count * sizeof( Explicit_item_id_ptr ) );
delete _buf;
_buf = newbuf;
}
}
void Explicit_item_id__set::Insert( Explicit_item_id_ptr v, int index ) {
Explicit_item_id_ptr * spot;
index = ( index < 0 ) ? _count : index;
if( index < _count ) {
Check( _count + 1 );
spot = &_buf[index];
memmove( spot + 1, spot, ( _count - index )*sizeof( Explicit_item_id_ptr ) );
} else {
Check( index );
spot = &_buf[index];
}
*spot = v;
++_count;
}
void Explicit_item_id__set::Append( Explicit_item_id_ptr v ) {
int index = _count;
Explicit_item_id_ptr * spot;
if( index < _count ) {
Check( _count + 1 );
spot = &_buf[index];
memmove( spot + 1, spot, ( _count - index )*sizeof( Explicit_item_id_ptr ) );
} else {
Check( index );
spot = &_buf[index];
}
*spot = v;
++_count;
}
void Explicit_item_id__set::Remove( int index ) {
if( 0 <= index && index < _count ) {
--_count;
Explicit_item_id_ptr * spot = &_buf[index];
memmove( spot, spot + 1, ( _count - index )*sizeof( Explicit_item_id_ptr ) );
}
}
int Explicit_item_id__set::Index( Explicit_item_id_ptr v ) {
for( int i = 0; i < _count; ++i ) {
if( _buf[i] == v ) {
return i;
}
}
return -1;
}
Explicit_item_id_ptr & Explicit_item_id__set::operator[]( int index ) {
Check( index );
_count = ( ( _count > index + 1 ) ? _count : ( index + 1 ) );
return _buf[index];
}
int Explicit_item_id__set::Count() {
return _count;
}
void Explicit_item_id__set::Clear() {
_count = 0;
}
///////////////////////////////////////////////////////////////////////////////
Implicit_item_id__set::Implicit_item_id__set( int defaultSize ) {
_bufsize = defaultSize;
_buf = new Implicit_item_id_ptr[_bufsize];
_count = 0;
}
Implicit_item_id__set::~Implicit_item_id__set() {
delete _buf;
}
void Implicit_item_id__set::Check( int index ) {
Implicit_item_id_ptr * newbuf;
if( index >= _bufsize ) {
_bufsize = ( index + 1 ) * 2;
newbuf = new Implicit_item_id_ptr[_bufsize];
memmove( newbuf, _buf, _count * sizeof( Implicit_item_id_ptr ) );
delete _buf;
_buf = newbuf;
}
}
void Implicit_item_id__set::Insert( Implicit_item_id_ptr v, int index ) {
Implicit_item_id_ptr * spot;
index = ( index < 0 ) ? _count : index;
if( index < _count ) {
Check( _count + 1 );
spot = &_buf[index];
memmove( spot + 1, spot, ( _count - index )*sizeof( Implicit_item_id_ptr ) );
} else {
Check( index );
spot = &_buf[index];
}
*spot = v;
++_count;
}
void Implicit_item_id__set::Append( Implicit_item_id_ptr v ) {
int index = _count;
Implicit_item_id_ptr * spot;
if( index < _count ) {
Check( _count + 1 );
spot = &_buf[index];
memmove( spot + 1, spot, ( _count - index )*sizeof( Implicit_item_id_ptr ) );
} else {
Check( index );
spot = &_buf[index];
}
*spot = v;
++_count;
}
void Implicit_item_id__set::Remove( int index ) {
if( 0 <= index && index < _count ) {
--_count;
Implicit_item_id_ptr * spot = &_buf[index];
memmove( spot, spot + 1, ( _count - index )*sizeof( Implicit_item_id_ptr ) );
}
}
int Implicit_item_id__set::Index( Implicit_item_id_ptr v ) {
for( int i = 0; i < _count; ++i ) {
if( _buf[i] == v ) {
return i;
}
}
return -1;
}
Implicit_item_id_ptr & Implicit_item_id__set::operator[]( int index ) {
Check( index );
_count = ( ( _count > index + 1 ) ? _count : ( index + 1 ) );
return _buf[index];
}
int Implicit_item_id__set::Count() {
return _count;
}
void Implicit_item_id__set::Clear() {
_count = 0;
}
///////////////////////////////////////////////////////////////////////////////
Interface_spec__set::Interface_spec__set( int defaultSize ) {
_bufsize = defaultSize;
_buf = new Interface_spec_ptr[_bufsize];
_count = 0;
}
Interface_spec__set::~Interface_spec__set() {
delete [] _buf;
}
void Interface_spec__set::Check( int index ) {
Interface_spec_ptr * newbuf;
if( index >= _bufsize ) {
_bufsize = ( index + 1 ) * 2;
newbuf = new Interface_spec_ptr[_bufsize];
memmove( newbuf, _buf, _count * sizeof( Interface_spec_ptr ) );
delete _buf;
_buf = newbuf;
}
}
void Interface_spec__set::Insert( Interface_spec_ptr v, int index ) {
Interface_spec_ptr * spot;
index = ( index < 0 ) ? _count : index;
if( index < _count ) {
Check( _count + 1 );
spot = &_buf[index];
memmove( spot + 1, spot, ( _count - index )*sizeof( Interface_spec_ptr ) );
} else {
Check( index );
spot = &_buf[index];
}
*spot = v;
++_count;
}
void Interface_spec__set::Append( Interface_spec_ptr v ) {
int index = _count;
Interface_spec_ptr * spot;
if( index < _count ) {
Check( _count + 1 );
spot = &_buf[index];
memmove( spot + 1, spot, ( _count - index )*sizeof( Interface_spec_ptr ) );
} else {
Check( index );
spot = &_buf[index];
}
*spot = v;
++_count;
}
void Interface_spec__set::Remove( int index ) {
if( 0 <= index && index < _count ) {
--_count;
Interface_spec_ptr * spot = &_buf[index];
memmove( spot, spot + 1, ( _count - index )*sizeof( Interface_spec_ptr ) );
}
}
int Interface_spec__set::Index( Interface_spec_ptr v ) {
for( int i = 0; i < _count; ++i ) {
if( _buf[i] == v ) {
return i;
}
}
return -1;
}
Interface_spec_ptr & Interface_spec__set::operator[]( int index ) {
Check( index );
_count = ( ( _count > index + 1 ) ? _count : ( index + 1 ) );
return _buf[index];
}
int Interface_spec__set::Count() {
return _count;
}
void Interface_spec__set::Clear() {
_count = 0;
}
///////////////////////////////////////////////////////////////////////////////
Interface_spec::Interface_spec()
: _explicit_items( new Explicit_item_id__set ),
_implicit_items( 0 ), _all_objects( 0 ) {
}
/// not tested
Interface_spec::Interface_spec( Interface_spec & is ) {
_explicit_items = new Explicit_item_id__set;
int count = is._explicit_items->Count();
int i;
for( i = 0; i < count; i++ ) {
( *_explicit_items )[i] =
( *( is._explicit_items ) )[i];
}
_current_schema_id = is._current_schema_id;
_foreign_schema_id = is._foreign_schema_id;
_all_objects = is._all_objects;
_implicit_items = 0;
}
Interface_spec::Interface_spec( const char * cur_sch_id,
const char * foreign_sch_id, int all_objects )
: _current_schema_id( cur_sch_id ), _explicit_items( new Explicit_item_id__set ),
_implicit_items( 0 ), _foreign_schema_id( foreign_sch_id ),
_all_objects( all_objects ) {
}
Interface_spec::~Interface_spec() {
delete _explicit_items;
delete _implicit_items;
}
//////////////////////////////////////////////////////////////////////////////
void Schema::AddFunction( const std::string & f ) {
_function_list.push_back( f );
}
void Schema::AddGlobal_rule( Global_rule_ptr gr ) {
if( _global_rules == 0 ) {
_global_rules = new Global_rule__set;
}
_global_rules->Append( gr );
}
/// not implemented
void Schema::global_rules_( Global_rule__set_var & grs ) {
}
void Schema::AddProcedure( const std::string & p ) {
_procedure_list.push_back( p );
}
/// the whole schema
void Schema::GenerateExpress( ostream & out ) const {
std::string tmp;
out << endl << "(* Generating: " << Name() << " *)" << endl;
out << endl << "SCHEMA " << StrToLower( Name(), tmp ) << ";" << endl;
GenerateUseRefExpress( out );
// print TYPE definitions
out << endl << "(* ////////////// TYPE Definitions *)" << endl;
GenerateTypesExpress( out );
// print Entity definitions
out << endl << "(* ////////////// ENTITY Definitions *)" << endl;
GenerateEntitiesExpress( out );
int count, i;
if( _global_rules != 0 ) {
out << endl << "(* *************RULES************* *)" << endl;
count = _global_rules->Count();
for( i = 0; i < count; i++ ) {
out << endl << ( *_global_rules )[i]->rule_text_() << endl;
}
}
if( !_function_list.empty() ) {
out << "(* *************FUNCTIONS************* *)" << endl;
count = _function_list.size();
for( i = 0; i < count; i++ ) {
out << endl << _function_list[i] << endl;
}
}
if( !_procedure_list.empty() ) {
out << "(* *************PROCEDURES************* *)" << endl;
count = _procedure_list.size();
for( i = 0; i < count; i++ ) {
out << endl << _procedure_list[i] << endl;
}
}
out << endl << "END_SCHEMA;" << endl;
}
/// USE, REFERENCE definitions
void Schema::GenerateUseRefExpress( ostream & out ) const {
int i, k;
int intf_count;
int count;
Interface_spec_ptr is;
int first_time;
std::string tmp;
/////////////////////// print USE statements
intf_count = _use_interface_list->Count();
if( intf_count ) { // there is at least 1 USE interface to a foreign schema
for( i = 0; i < intf_count; i++ ) { // print out each USE interface
is = ( *_use_interface_list )[i]; // the 1st USE interface
// count is # of USE items in interface
count = is->explicit_items_()->Count();
if( count > 0 ) {
out << endl << " USE FROM "
<< StrToLower( is->foreign_schema_id_().c_str(), tmp ) << endl;
out << " (";
first_time = 1;
for( k = 0; k < count; k++ ) { // print out each USE item
if( first_time ) {
first_time = 0;
} else {
out << "," << endl << "\t";
}
if( !( ( *( is->explicit_items_() ) )[k]->original_id_().size() ) ) {
// not renamed
out << ( *( is->explicit_items_() ) )[k]->new_id_();
} else { // renamed
out << ( *( is->explicit_items_() ) )[k]->original_id_();
out << " AS " << ( *( is->explicit_items_() ) )[k]->new_id_();
}
}
out << ");" << endl;
} else if( is->all_objects_() ) {
out << endl << " USE FROM "
<< StrToLower( is->foreign_schema_id_().c_str(), tmp ) << ";"
<< endl;
}
}
}
/////////////////////// print REFERENCE stmts
intf_count = _ref_interface_list->Count();
if( intf_count ) { //there is at least 1 REFERENCE interface to a foreign schema
for( i = 0; i < intf_count; i++ ) { // print out each REFERENCE interface
is = ( *_ref_interface_list )[i]; // the 1st REFERENCE interface
// count is # of REFERENCE items in interface
count = is->explicit_items_()->Count();
if( count > 0 ) {
out << endl << " REFERENCE FROM "
<< StrToLower( is->foreign_schema_id_().c_str(), tmp ) << endl;
out << " (";
first_time = 1;
for( k = 0; k < count; k++ ) { // print out each REFERENCE item
if( first_time ) {
first_time = 0;
} else {
out << "," << endl << "\t";
}
if( ( !( *( is->explicit_items_() ) )[k]->original_id_().size() ) ) {
// not renamed
out << ( *( is->explicit_items_() ) )[k]->new_id_();
} else { // renamed
out << ( *( is->explicit_items_() ) )[k]->original_id_();
out << " AS "
<< ( *( is->explicit_items_() ) )[k]->new_id_();
}
}
out << ");" << endl;
} else if( is->all_objects_() ) {
out << endl << " REFERENCE FROM "
<< StrToLower( is->foreign_schema_id_().c_str(), tmp ) << ";"
<< endl;
}
}
}
}
/// TYPE definitions
void Schema::GenerateTypesExpress( ostream & out ) const {
TypeDescItr tdi( _typeList );
tdi.ResetItr();
std::string tmp;
const TypeDescriptor * td = tdi.NextTypeDesc();
while( td ) {
out << endl << td->GenerateExpress( tmp );
td = tdi.NextTypeDesc();
}
}
/// Entity definitions
void Schema::GenerateEntitiesExpress( ostream & out ) const {
EntityDescItr edi( _entList );
edi.ResetItr();
std::string tmp;
const EntityDescriptor * ed = edi.NextEntityDesc();
while( ed ) {
out << endl << ed->GenerateExpress( tmp );
ed = edi.NextEntityDesc();
}
}
///////////////////////////////////////////////////////////////////////////////
EnumAggregate * create_EnumAggregate() {
return new EnumAggregate;
}
GenericAggregate * create_GenericAggregate() {
return new GenericAggregate;
}
EntityAggregate * create_EntityAggregate() {
return new EntityAggregate;
}
SelectAggregate * create_SelectAggregate() {
return new SelectAggregate;
}
StringAggregate * create_StringAggregate() {
return new StringAggregate;
}
BinaryAggregate * create_BinaryAggregate() {
return new BinaryAggregate;
}
RealAggregate * create_RealAggregate() {
return new RealAggregate;
}
IntAggregate * create_IntAggregate() {
return new IntAggregate;
}
const EntityDescriptor * EntityDescItr::NextEntityDesc() {
if( cur ) {
const EntityDescriptor * ed = cur->EntityDesc();
cur = ( EntityDescLinkNode * )( cur->NextNode() );
return ed;
}
return 0;
}
const AttrDescriptor * AttrDescItr::NextAttrDesc() {
if( cur ) {
const AttrDescriptor * ad = cur->AttrDesc();
cur = ( AttrDescLinkNode * )( cur->NextNode() );
return ad;
}
return 0;
}
const Inverse_attribute * InverseAItr::NextInverse_attribute() {
if( cur ) {
const Inverse_attribute * ia = cur->Inverse_attr();
cur = ( Inverse_attributeLinkNode * )( cur->NextNode() );
return ia;
}
return 0;
}
const TypeDescriptor * TypeDescItr::NextTypeDesc() {
if( cur ) {
const TypeDescriptor * td = cur->TypeDesc();
cur = ( TypeDescLinkNode * )( cur->NextNode() );
return td;
}
return 0;
}
///////////////////////////////////////////////////////////////////////////////
// AttrDescriptor functions
///////////////////////////////////////////////////////////////////////////////
const char * AttrDescriptor::AttrExprDefStr( std::string & s ) const {
std::string buf;
s = Name();
s.append( " : " );
if( _optional.asInt() == LTrue ) {
s.append( "OPTIONAL " );
}
if( DomainType() ) {
s.append( DomainType()->AttrTypeName( buf ) );
}
return const_cast<char *>( s.c_str() );
}
const PrimitiveType AttrDescriptor::BaseType() const {
if( _domainType ) {
return _domainType->BaseType();
}
return UNKNOWN_TYPE;
}
int AttrDescriptor::IsAggrType() const {
return ReferentType()->IsAggrType();
}
const PrimitiveType AttrDescriptor::AggrElemType() const {
if( IsAggrType() ) {
return ReferentType()->AggrElemType();
}
return UNKNOWN_TYPE;
}
const TypeDescriptor * AttrDescriptor::AggrElemTypeDescriptor() const {
if( IsAggrType() ) {
return ReferentType()->AggrElemTypeDescriptor();
}
return 0;
}
const TypeDescriptor * AttrDescriptor::NonRefTypeDescriptor() const {
if( _domainType ) {
return _domainType->NonRefTypeDescriptor();
}
return 0;
}
const PrimitiveType AttrDescriptor::NonRefType() const {
if( _domainType ) {
return _domainType->NonRefType();
}
return UNKNOWN_TYPE;
}
const PrimitiveType AttrDescriptor::Type() const {
if( _domainType ) {
return _domainType->Type();
}
return UNKNOWN_TYPE;
}
/**
* right side of attr def
* NOTE this returns a \'const char * \' instead of an std::string
*/
const char * AttrDescriptor::TypeName() const {
std::string buf;
if( _domainType ) {
return _domainType->AttrTypeName( buf );
} else {
return "";
}
}
/// an expanded right side of attr def
const char * AttrDescriptor::ExpandedTypeName( std::string & s ) const {
s.clear();
if( Derived() == LTrue ) {
s = "DERIVE ";
}
if( _domainType ) {
std::string tmp;
return const_cast<char *>( ( s.append( _domainType->TypeString( tmp ) ).c_str() ) );
} else {
return 0;
}
}
const char * AttrDescriptor::GenerateExpress( std::string & buf ) const {
std::string sstr;
buf = AttrExprDefStr( sstr );
buf.append( ";\n" );
return const_cast<char *>( buf.c_str() );
}
///////////////////////////////////////////////////////////////////////////////
// Derived_attribute functions
///////////////////////////////////////////////////////////////////////////////
const char * Derived_attribute::AttrExprDefStr( std::string & s ) const {
std::string buf;
s.clear();
if( Name() && strchr( Name(), '.' ) ) {
s = "SELF\\";
}
s.append( Name() );
s.append( " : " );
if( DomainType() ) {
s.append( DomainType()->AttrTypeName( buf ) );
}
if( _initializer ) { // this is supposed to exist for a derived attribute.
s.append( " \n\t\t:= " );
s.append( _initializer );
}
return const_cast<char *>( s.c_str() );
}
///////////////////////////////////////////////////////////////////////////////
// Inverse_attribute functions
///////////////////////////////////////////////////////////////////////////////
const char * Inverse_attribute::AttrExprDefStr( std::string & s ) const {
std::string buf;
s = Name();
s.append( " : " );
if( _optional.asInt() == LTrue ) {
s.append( "OPTIONAL " );
}
if( DomainType() ) {
s.append( DomainType()->AttrTypeName( buf ) );
}
s.append( " FOR " );
s.append( _inverted_attr_id );
return const_cast<char *>( s.c_str() );
}
///////////////////////////////////////////////////////////////////////////////
// EnumDescriptor functions
///////////////////////////////////////////////////////////////////////////////
EnumTypeDescriptor::EnumTypeDescriptor( const char * nm, PrimitiveType ft,
Schema * origSchema,
const char * d, EnumCreator f )
: TypeDescriptor( nm, ft, origSchema, d ), CreateNewEnum( f ) {
}
SDAI_Enum * EnumTypeDescriptor::CreateEnum() {
if( CreateNewEnum ) {
return CreateNewEnum();
} else {
return 0;
}
}
const char * EnumTypeDescriptor::GenerateExpress( std::string & buf ) const {
char tmp[BUFSIZ];
buf = "TYPE ";
buf.append( StrToLower( Name(), tmp ) );
buf.append( " = ENUMERATION OF \n (" );
const char * desc = Description();
const char * ptr = &( desc[16] );
int all_comments = 1;
while( *ptr != '\0' ) {
if( *ptr == ',' ) {
buf.append( ",\n " );
} else if( isupper( *ptr ) ) {
buf += ( char )tolower( *ptr );
} else {
buf += *ptr;
}
ptr++;
}
buf.append( ";\n" );
///////////////
// count is # of WHERE rules
if( _where_rules != 0 ) {
int count = _where_rules->Count();
for( int i = 0; i < count; i++ ) { // print out each UNIQUE rule
if( !( *( _where_rules ) )[i]->_label.size() ) {
all_comments = 0;
}
}
if( all_comments ) {
buf.append( " (* WHERE *)\n" );
} else {
buf.append( " WHERE\n" );
}
for( int i = 0; i < count; i++ ) { // print out each WHERE rule
if( !( *( _where_rules ) )[i]->_comment.empty() ) {
buf.append( " " );
buf.append( ( *( _where_rules ) )[i]->comment_() );
}
if( ( *( _where_rules ) )[i]->_label.size() ) {
buf.append( " " );
buf.append( ( *( _where_rules ) )[i]->label_() );
}
}
}
buf.append( "END_TYPE;\n" );
return const_cast<char *>( buf.c_str() );
}
///////////////////////////////////////////////////////////////////////////////
// EntityDescriptor functions
///////////////////////////////////////////////////////////////////////////////
EntityDescriptor::EntityDescriptor( )
: _abstractEntity( LUnknown ), _extMapping( LUnknown ),
_uniqueness_rules( ( Uniqueness_rule__set_var )0 ), NewSTEPentity( 0 ) {
}
EntityDescriptor::EntityDescriptor( const char * name, // i.e. char *
Schema * origSchema,
Logical abstractEntity, // F U or T
Logical extMapping,
Creator f
)
: TypeDescriptor( name, ENTITY_TYPE, origSchema, name ),
_abstractEntity( abstractEntity ), _extMapping( extMapping ),
_uniqueness_rules( ( Uniqueness_rule__set_var )0 ), NewSTEPentity( f ) {
}
EntityDescriptor::~EntityDescriptor() {
delete _uniqueness_rules;
}
const char * EntityDescriptor::GenerateExpress( std::string & buf ) const {
std::string sstr;
int count;
int i;
int all_comments = 1;
buf = "ENTITY ";
buf.append( StrToLower( Name(), sstr ) );
if( strlen( _supertype_stmt.c_str() ) > 0 ) {
buf.append( "\n " );
}
buf.append( _supertype_stmt.c_str() );
const EntityDescriptor * ed = 0;
EntityDescItr edi_super( _supertypes );
edi_super.ResetItr();
ed = edi_super.NextEntityDesc();
int supertypes = 0;
if( ed ) {
buf.append( "\n SUBTYPE OF (" );
buf.append( StrToLower( ed->Name(), sstr ) );
supertypes = 1;
}
ed = edi_super.NextEntityDesc();
while( ed ) {
buf.append( ",\n\t\t" );
buf.append( StrToLower( ed->Name(), sstr ) );
ed = edi_super.NextEntityDesc();
}
if( supertypes ) {
buf.append( ")" );
}
buf.append( ";\n" );
AttrDescItr adi( _explicitAttr );
adi.ResetItr();
const AttrDescriptor * ad = adi.NextAttrDesc();
while( ad ) {
if( ad->AttrType() == AttrType_Explicit ) {
buf.append( " " );
buf.append( ad->GenerateExpress( sstr ) );
}
ad = adi.NextAttrDesc();
}
adi.ResetItr();
ad = adi.NextAttrDesc();
count = 1;
while( ad ) {
if( ad->AttrType() == AttrType_Deriving ) {
if( count == 1 ) {
buf.append( " DERIVE\n" );
}
buf.append( " " );
buf.append( ad->GenerateExpress( sstr ) );
count++;
}
ad = adi.NextAttrDesc();
}
/////////
InverseAItr iai( _inverseAttr );
iai.ResetItr();
const Inverse_attribute * ia = iai.NextInverse_attribute();
if( ia ) {
buf.append( " INVERSE\n" );
}
while( ia ) {
buf.append( " " );
buf.append( ia->GenerateExpress( sstr ) );
ia = iai.NextInverse_attribute();
}
///////////////
// count is # of UNIQUE rules
if( _uniqueness_rules != 0 ) {
count = _uniqueness_rules->Count();
for( i = 0; i < count; i++ ) { // print out each UNIQUE rule
if( !( *( _uniqueness_rules ) )[i]->_label.size() ) {
all_comments = 0;
}
}
if( all_comments ) {
buf.append( " (* UNIQUE *)\n" );
} else {
buf.append( " UNIQUE\n" );
}
for( i = 0; i < count; i++ ) { // print out each UNIQUE rule
if( !( *( _uniqueness_rules ) )[i]->_comment.empty() ) {
buf.append( " " );
buf.append( ( *( _uniqueness_rules ) )[i]->comment_() );
buf.append( "\n" );
}
if( ( *( _uniqueness_rules ) )[i]->_label.size() ) {
buf.append( " " );
buf.append( ( *( _uniqueness_rules ) )[i]->label_() );
buf.append( "\n" );
}
}
}
///////////////
// count is # of WHERE rules
if( _where_rules != 0 ) {
all_comments = 1;
count = _where_rules->Count();
for( i = 0; i < count; i++ ) { // print out each UNIQUE rule
if( !( *( _where_rules ) )[i]->_label.size() ) {
all_comments = 0;
}
}
if( !all_comments ) {
buf.append( " WHERE\n" );
} else {
buf.append( " (* WHERE *)\n" );
}
for( i = 0; i < count; i++ ) { // print out each WHERE rule
if( !( *( _where_rules ) )[i]->_comment.empty() ) {
buf.append( " " );
buf.append( ( *( _where_rules ) )[i]->comment_() );
buf.append( "\n" );
}
if( ( *( _where_rules ) )[i]->_label.size() ) {
buf.append( " " );
buf.append( ( *( _where_rules ) )[i]->label_() );
buf.append( "\n" );
}
}
}
buf.append( "END_ENTITY;\n" );
return const_cast<char *>( buf.c_str() );
}
const char * EntityDescriptor::QualifiedName( std::string & s ) const {
s.clear();
EntityDescItr edi( _supertypes );
int count = 1;
const EntityDescriptor * ed = 0;
while( ( ed = edi.NextEntityDesc() ) ) {
if( count > 1 ) {
s.append( "&" );
}
s.append( ed->Name() );
count++;
}
if( count > 1 ) {
s.append( "&" );
}
s.append( Name() );
return const_cast<char *>( s.c_str() );
}
const TypeDescriptor * EntityDescriptor::IsA( const TypeDescriptor * td ) const {
if( td -> NonRefType() == ENTITY_TYPE ) {
return IsA( ( EntityDescriptor * ) td );
} else {
return 0;
}
}
const EntityDescriptor * EntityDescriptor::IsA( const EntityDescriptor * other ) const {
const EntityDescriptor * found = 0;
const EntityDescLinkNode * link = ( const EntityDescLinkNode * )( GetSupertypes().GetHead() );
if( this == other ) {
return other;
} else {
while( link && ! found ) {
found = link -> EntityDesc() -> IsA( other );
link = ( EntityDescLinkNode * ) link -> NextNode();
}
}
return found;
}
///////////////////////////////////////////////////////////////////////////////
Type_or_rule::Type_or_rule() {
}
Type_or_rule::Type_or_rule( const Type_or_rule & tor ) {
}