-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathentityDescriptor.cc
More file actions
257 lines (226 loc) · 7.58 KB
/
entityDescriptor.cc
File metadata and controls
257 lines (226 loc) · 7.58 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
#include <string>
#include "entityDescriptor.h"
#include "Registry.h"
#include "attrDescriptor.h"
#include "inverseAttribute.h"
#include "SubSuperIterators.h"
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;
}
// initialize one inverse attr; used in InitIAttrs, below
void initIAttr( Inverse_attribute * ia, Registry & reg, const char * schNm, const char * name ) {
const AttrDescriptor * ad;
const char * aid = ia->inverted_attr_id_();
const char * eid = ia->inverted_entity_id_();
const EntityDescriptor * e = reg.FindEntity( eid, schNm );
AttrDescItr adl( e->ExplicitAttr() );
while( 0 != ( ad = adl.NextAttrDesc() ) ) {
if( !strcmp( aid, ad->Name() ) ) {
ia->inverted_attr_( ad );
return;
}
}
supertypesIterator sit( e );
for( ; !sit.empty(); ++sit ) {
AttrDescItr adi( sit.current()->ExplicitAttr() );
while( 0 != ( ad = adi.NextAttrDesc() ) ) {
if( !strcmp( aid, ad->Name() ) ) {
ia->inverted_attr_( ad );
return;
}
}
}
std::cerr << "Inverse attr " << ia->Name() << " for " << name << ": cannot find AttrDescriptor " << aid << " for entity " << eid << "." << std::endl;
//FIXME should we abort? or is there a sensible recovery path?
abort();
}
/** initialize inverse attrs
* call once per eDesc (once per EXPRESS entity type)
* must be called _after_ init_Sdai* functions for any ia->inverted_entity_id_'s
*
*/
void EntityDescriptor::InitIAttrs( Registry & reg, const char * schNm ) {
InverseAItr iai( &( InverseAttr() ) );
Inverse_attribute * ia;
while( 0 != ( ia = iai.NextInverse_attribute() ) ) {
initIAttr( ia, reg, schNm, _name );
}
}
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 );
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 = edi.NextEntityDesc();
while( ed ) {
if( count > 1 ) {
s.append( "&" );
}
s.append( ed->Name() );
count++;
ed = edi.NextEntityDesc();
}
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;
}