@@ -145,7 +145,7 @@ class SelectType:
145145 def __init__ (self ,l ):
146146 for x in l :
147147 if x in simple_types : selectable_simple_types .add (x )
148- def __str__ (self ): return "SHARED_PTR<IfcAbstractSelect> "
148+ def __str__ (self ): return "IfcSchemaEntity "
149149class BinaryType :
150150 def __init__ (self ,l ): self .l = int (l )
151151 def __str__ (self ): return "char[%s]" % self .l
@@ -209,7 +209,7 @@ def __str__(self):
209209 if ( str (a .type ) in enumerations ):
210210 return_type = "%(type)s::%(type)s" % a .__dict__
211211 elif ( str (a .type ) in entity_names ):
212- return_type = "SHARED_PTR< %(type)s> " % a .__dict__
212+ return_type = "%(type)s* " % a .__dict__
213213 s += "\n %s%s %s%s()%s" % (indent ,return_type ,class_name ,a .name ,function_body )
214214 argv += 1
215215 return s
@@ -237,20 +237,20 @@ def __str__(self):
237237 "IfcBaseClass" if self .parent_class is None else self .parent_class ,
238238 self .arguments ,
239239 self .inverse ,
240- ("\n bool is(Type::Enum v);" +
241- "\n Type::Enum type();" +
240+ ("\n bool is(Type::Enum v) const ;" +
241+ "\n Type::Enum type() const ;" +
242242 "\n static Type::Enum Class();" +
243243 "\n %(class_name)s (IfcAbstractEntityPtr e = IfcAbstractEntityPtr());" +
244- "\n typedef SHARED_PTR< %(class_name)s> ptr;" +
244+ "\n typedef %(class_name)s* ptr;" +
245245 "\n typedef SHARED_PTR< IfcTemplatedEntityList<%(class_name)s> > list;" +
246246 "\n typedef IfcTemplatedEntityList<%(class_name)s>::it it;" )% self .__dict__
247247 )
248248 elif generator_mode == 'SOURCE' :
249249 self .arguments .argstart = argument_start (self .class_name )
250250 return (("\n // %(class_name)s" + str (self .arguments )+ str (self .inverse )+
251- ("\n bool %(class_name)s::is(Type::Enum v) { return v == Type::%(class_name)s; }" if self .parent_class is None else
252- "\n bool %(class_name)s::is(Type::Enum v) { return v == Type::%(class_name)s || %(parent_class)s::is(v); }" )+
253- "\n Type::Enum %(class_name)s::type() { return Type::%(class_name)s; }" +
251+ ("\n bool %(class_name)s::is(Type::Enum v) const { return v == Type::%(class_name)s; }" if self .parent_class is None else
252+ "\n bool %(class_name)s::is(Type::Enum v) const { return v == Type::%(class_name)s || %(parent_class)s::is(v); }" )+
253+ "\n Type::Enum %(class_name)s::type() const { return Type::%(class_name)s; }" +
254254 "\n Type::Enum %(class_name)s::Class() { return Type::%(class_name)s; }" +
255255 "\n %(class_name)s::%(class_name)s(IfcAbstractEntityPtr e) { if (!is(Type::%(class_name)s)) throw; entity = e; }" )% self .__dict__ )% self .__dict__
256256
@@ -340,6 +340,7 @@ def __str__(self):
340340
341341#include <string>
342342#include <vector>
343+ #include <map>
343344
344345#include "../ifcparse/IfcUtil.h"
345346#include "../ifcparse/%(schema)senum.h"
@@ -417,8 +418,9 @@ def __str__(self):
417418 if c .parent_class is None or c .parent_class in defined_classes :
418419 defined_classes .add (c .class_name )
419420 print >> h_file , c
420-
421- print >> h_file , "IfcSchemaEntity SchemaEntity(IfcAbstractEntityPtr e = IfcAbstractEntityPtr());"
421+
422+ print >> h_file , "void InitStringMap();"
423+ print >> h_file , "IfcSchemaEntity SchemaEntity(IfcAbstractEntityPtr e = 0);"
422424
423425print >> h_file , "}\n \n #endif"
424426
@@ -428,35 +430,47 @@ def __str__(self):
428430
429431using namespace %(schema)s;
430432
431- IfcSchemaEntity %(schema)s::SchemaEntity(IfcAbstractEntityPtr e) {""" % {'schema' :schema_version }
433+ IfcSchemaEntity %(schema)s::SchemaEntity(IfcAbstractEntityPtr e) {
434+ switch(e->type()){""" % {'schema' :schema_version }
432435
433436for e in simple_enumerations :
434- print >> cpp_file , " if ( e->is( Type::%s) ) return IfcSchemaEntity( new IfcEntitySelect(e)) ;" % e
437+ print >> cpp_file , " case Type::%s: return new IfcEntitySelect(e); break ;" % e
435438for e in entity_enumerations :
436- print >> cpp_file , " if ( e->is( Type::%s) ) return IfcSchemaEntity( new %s(e)) ;" % (e ,e )
437- print >> cpp_file , " throw; "
438- print >> cpp_file , "}"
439+ print >> cpp_file , " case Type::%s: return new %s(e); break ;" % (e ,e )
440+ print >> cpp_file , " default: throw; break ; "
441+ print >> cpp_file , " } \n }"
439442print >> cpp_file
440443print >> cpp_file , "std::string Type::ToString(Enum v) {"
441444print >> cpp_file , " if (v < 0 || v >= %d) throw;" % len (all_enumerations )
442445print >> cpp_file , ' const char* names[] = { "%s" };' % '","' .join (all_enumerations )
443446print >> cpp_file , ' return names[v];'
444447print >> cpp_file , "}"
445448print >> cpp_file
446- print >> cpp_file , "Type::Enum Type::FromString(const std::string& s){"
447- elseif = "if"
449+ #print >>cpp_file, "Type::Enum Type::FromStringOld(const std::string& s){"
450+ #elseif = "if"
451+ #maxlen = max([len(e) for e in all_enumerations])
452+ #for e in all_enumerations:
453+ # print >>cpp_file, ' %s(s=="%s"%s) { return %s; }'%(elseif,e.upper()," "*(maxlen-len(e)),e)
454+ #print >>cpp_file, " throw;"
455+ #print >>cpp_file, "}"
456+ print >> cpp_file , "std::map<std::string,Type::Enum> string_map;"
457+ print >> cpp_file , "void Ifc2x3::InitStringMap() {"
448458maxlen = max ([len (e ) for e in all_enumerations ])
449459for e in all_enumerations :
450- print >> cpp_file , ' %s(s=="%s"%s) { return %s; }' % (elseif ,e .upper ()," " * (maxlen - len (e )),e )
451- print >> cpp_file , " throw;"
452- print >> cpp_file , "}"
460+ print >> cpp_file , ' string_map["%s"%s] = Type::%s;' % (e .upper ()," " * (maxlen - len (e )),e )
461+ print >> cpp_file , """}
462+ Type::Enum Type::FromString(const std::string& s) {
463+ std::map<std::string,Type::Enum>::const_iterator it = string_map.find(s);
464+ if ( it == string_map.end() ) throw;
465+ else return it->second;
466+ }"""
453467
454468print >> cpp_file , "Type::Enum Type::Parent(Enum v){"
455- print >> cpp_file , " if (v < 0 || v >= %d) return -1;" % len (all_enumerations )
469+ print >> cpp_file , " if (v < 0 || v >= %d) return (Enum) -1;" % len (all_enumerations )
456470for e in entity_enumerations :
457- if e not in parent_relations : continue
471+ if e not in parent_relations or parent_relations [ e ] is None : continue
458472 print >> cpp_file , ' if(v==%s%s) { return %s; }' % (e ," " * (maxlen - len (e )),parent_relations [e ])
459- print >> cpp_file , " return -1;"
473+ print >> cpp_file , " return (Enum) -1;"
460474print >> cpp_file , "}"
461475
462476for t in [T for T in types if isinstance (T .type ,EnumType )]:
0 commit comments