|
94 | 94 | bool GetAttributeDerived(Enum t, unsigned char a); |
95 | 95 | std::pair<const char*, int> GetEnumerationIndex(Enum t, const std::string& a); |
96 | 96 | std::pair<Enum, unsigned> GetInverseAttribute(Enum t, const std::string& a); |
| 97 | + std::set<std::string> GetInverseAttributeNames(Enum t); |
97 | 98 | void PopulateDerivedFields(IfcWrite::IfcWritableEntity* e); |
98 | 99 | }} |
99 | 100 |
|
|
168 | 169 | using namespace IfcWrite; |
169 | 170 | using namespace IfcUtil; |
170 | 171 |
|
171 | | -std::map<Type::Enum,IfcEntityDescriptor*> entity_descriptor_map; |
172 | | -std::map<Type::Enum,IfcEnumerationDescriptor*> enumeration_descriptor_map; |
173 | | -std::map<std::pair<Type::Enum, std::string>, std::pair<Type::Enum, int> > inverse_map; |
174 | | -std::map<Type::Enum,std::set<int> > derived_map; |
| 172 | +typedef std::map<Type::Enum,IfcEntityDescriptor*> entity_descriptor_map_t; |
| 173 | +typedef std::map<Type::Enum,IfcEnumerationDescriptor*> enumeration_descriptor_map_t; |
| 174 | +typedef std::map<Type::Enum, std::map<std::string, std::pair<Type::Enum, int> > > inverse_map_t; |
| 175 | +typedef std::map<Type::Enum,std::set<int> > derived_map_t; |
| 176 | +
|
| 177 | +entity_descriptor_map_t entity_descriptor_map; |
| 178 | +enumeration_descriptor_map_t enumeration_descriptor_map; |
| 179 | +inverse_map_t inverse_map; |
| 180 | +derived_map_t derived_map; |
175 | 181 |
|
176 | 182 | void InitDescriptorMap() { |
177 | 183 | IfcEntityDescriptor* current; |
|
247 | 253 |
|
248 | 254 | std::pair<Type::Enum, unsigned> Type::GetInverseAttribute(Enum t, const std::string& a) { |
249 | 255 | if (inverse_map.empty()) ::InitInverseMap(); |
250 | | - std::map<std::pair<Type::Enum, std::string>, std::pair<Type::Enum, int> >::const_iterator it; |
251 | | - std::pair<Type::Enum, std::string> key = std::make_pair(t, a); |
| 256 | + inverse_map_t::const_iterator it; |
| 257 | + inverse_map_t::mapped_type::const_iterator jt; |
252 | 258 | while (true) { |
253 | | - it = inverse_map.find(key); |
254 | | - if (it != inverse_map.end()) return it->second; |
255 | | - if ((key.first = Parent(key.first)) == -1) break; |
| 259 | + it = inverse_map.find(t); |
| 260 | + if (it != inverse_map.end()) { |
| 261 | + jt = it->second.find(a); |
| 262 | + if (jt != it->second.end()) { |
| 263 | + return jt->second; |
| 264 | + } |
| 265 | + } |
| 266 | + if ((t = Parent(t)) == -1) break; |
256 | 267 | } |
257 | 268 | throw IfcException("Attribute not found"); |
258 | 269 | } |
259 | 270 |
|
| 271 | +std::set<std::string> Type::GetInverseAttributeNames(Enum t) { |
| 272 | + if (inverse_map.empty()) ::InitInverseMap(); |
| 273 | + inverse_map_t::const_iterator it; |
| 274 | + inverse_map_t::mapped_type::const_iterator jt; |
| 275 | +
|
| 276 | + std::set<std::string> return_value; |
| 277 | +
|
| 278 | + while (true) { |
| 279 | + it = inverse_map.find(t); |
| 280 | + if (it != inverse_map.end()) { |
| 281 | + for (jt = it->second.begin(); jt != it->second.end(); ++jt) { |
| 282 | + return_value.insert(jt->first); |
| 283 | + } |
| 284 | + } |
| 285 | + if ((t = Parent(t)) == -1) break; |
| 286 | + } |
| 287 | + |
| 288 | + return return_value; |
| 289 | +} |
| 290 | +
|
260 | 291 | void Type::PopulateDerivedFields(IfcWrite::IfcWritableEntity* e) { |
261 | 292 | std::map<Type::Enum, std::set<int> >::const_iterator i = derived_map.find(e->type()); |
262 | 293 | if (i != derived_map.end()) { |
@@ -401,7 +432,7 @@ class %(name)s %(superclass)s{ |
401 | 432 | constructor_stmt_optional = " if (%(name)s) {%(stmt)s } else { e->setArgument(%(index)d); }" |
402 | 433 | constructor_stmt_derived = " e->setArgumentDerived(%(index)d);" |
403 | 434 |
|
404 | | -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)));" |
| 435 | +inverse_implementation = " inverse_map[Type::%(type)s].insert(std::make_pair(\"%(name)s\", std::make_pair(Type::%(related_type)s, %(index)d)));" |
405 | 436 |
|
406 | 437 | def multi_line_comment(li): |
407 | 438 | return ("/// %s"%("\n/// ".join(li))) if len(li) else "" |
|
0 commit comments