|
89 | 89 | const std::string& GetAttributeName(Enum t, unsigned char a); |
90 | 90 | bool GetAttributeOptional(Enum t, unsigned char a); |
91 | 91 | std::pair<const char*, int> GetEnumerationIndex(Enum t, const std::string& a); |
| 92 | + std::pair<Enum, unsigned> GetInverseAttribute(Enum t, const std::string& a); |
92 | 93 | Enum GetAttributeEnumerationClass(Enum t, unsigned char a); |
93 | 94 | void PopulateDerivedFields(IfcWrite::IfcWritableEntity* e); |
94 | 95 | }} |
|
181 | 182 |
|
182 | 183 | std::map<Type::Enum,IfcEntityDescriptor*> entity_descriptor_map; |
183 | 184 | std::map<Type::Enum,IfcEnumerationDescriptor*> enumeration_descriptor_map; |
| 185 | +std::map<std::pair<Type::Enum, std::string>, std::pair<Type::Enum, int> > inverse_map; |
184 | 186 | void InitDescriptorMap() { |
185 | 187 | IfcEntityDescriptor* current; |
186 | 188 | %(entity_descriptors)s |
|
190 | 192 | %(enumeration_descriptors)s |
191 | 193 | } |
192 | 194 |
|
| 195 | +void InitInverseMap() { |
| 196 | +%(inverse_implementations)s |
| 197 | +} |
| 198 | +
|
193 | 199 | int Type::GetAttributeIndex(Enum t, const std::string& a) { |
194 | 200 | if (entity_descriptor_map.empty()) ::InitDescriptorMap(); |
195 | 201 | std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t); |
|
232 | 238 | else return i->second->getIndex(a); |
233 | 239 | } |
234 | 240 |
|
| 241 | +std::pair<Type::Enum, unsigned> Type::GetInverseAttribute(Enum t, const std::string& a) { |
| 242 | + if (inverse_map.empty()) ::InitInverseMap(); |
| 243 | + std::map<std::pair<Type::Enum, std::string>, std::pair<Type::Enum, int> >::const_iterator it; |
| 244 | + std::pair<Type::Enum, std::string> key = std::make_pair(t, a); |
| 245 | + while (true) { |
| 246 | + it = inverse_map.find(key); |
| 247 | + if (it != inverse_map.end()) return it->second; |
| 248 | + if ((key.first = Parent(key.first)) == -1) break; |
| 249 | + } |
| 250 | + throw IfcException("Attribute not found"); |
| 251 | +} |
| 252 | +
|
235 | 253 | Type::Enum Type::GetAttributeEnumerationClass(Enum t, unsigned char a) { |
236 | 254 | if (entity_descriptor_map.empty()) ::InitDescriptorMap(); |
237 | 255 | std::map<Type::Enum,IfcEntityDescriptor*>::const_iterator i = entity_descriptor_map.find(t); |
@@ -357,6 +375,8 @@ class %(name)s %(superclass)s{ |
357 | 375 | constructor_stmt_optional = " if (%(name)s) {%(stmt)s } else { e->setArgument(%(index)d); }" |
358 | 376 | constructor_stmt_derived = " e->setArgumentDerived(%(index)d);" |
359 | 377 |
|
| 378 | +inverse_implementation = " inverse_map.insert(std::make_pair(std::make_pair(Type::%(type)s, \"%(name)s\"), std::make_pair(Type::%(related_type)s, %(index)d)));" |
| 379 | + |
360 | 380 | def multi_line_comment(li): |
361 | 381 | return ("/// %s"%("\n/// ".join(li))) if len(li) else "" |
362 | 382 |
|
0 commit comments