def __str__(self): self.constructor_args_list = self.get_constructor_args() self.constructor_args = ", ".join(self.constructor_args_list) if generator_mode == 'HEADER': comment = IfcDocumentation.description(self.class_name) comment = comment+"\n" if comment else '' return "%sclass %s : public %s {\npublic:%s%s%s\n};" % (comment,self.class_name, "IfcBaseEntity" if self.parent_class is None else self.parent_class, self.arguments, self.inverse, ("\n bool is(Type::Enum v) const;"+ "\n Type::Enum type() const;"+ "\n static Type::Enum Class();"+ "\n %(class_name)s (IfcAbstractEntityPtr e = IfcAbstractEntityPtr());"+ ("\n %(class_name)s (%(constructor_args)s);" if len(self.constructor_args_list) else "")+ "\n typedef %(class_name)s* ptr;"+ "\n typedef SHARED_PTR< IfcTemplatedEntityList< %(class_name)s > > list;"+ "\n typedef IfcTemplatedEntityList< %(class_name)s >::it it;")%self.__dict__ ) elif generator_mode == 'SOURCE': self.arguments.argstart = argument_start(self.class_name) self.constructor_implementation = "; ".join(self.get_constructor_implementation()) return (("\n// Function implementations for %(class_name)s"+str(self.arguments)+str(self.inverse)+ ("\nbool %(class_name)s::is(Type::Enum v) const { return v == Type::%(class_name)s; }" if self.parent_class is None else "\nbool %(class_name)s::is(Type::Enum v) const { return v == Type::%(class_name)s || %(parent_class)s::is(v); }")+ "\nType::Enum %(class_name)s::type() const { return Type::%(class_name)s; }"+ "\nType::Enum %(class_name)s::Class() { return Type::%(class_name)s; }"+ "\n%(class_name)s::%(class_name)s(IfcAbstractEntityPtr e) { if (!is(Type::%(class_name)s)) throw IfcException(\"Unable to find find keyword in schema\"); entity = e; }"+ ("\n%(class_name)s::%(class_name)s(%(constructor_args)s) { IfcWritableEntity* e = new IfcWritableEntity(Class()); %(constructor_implementation)s; entity = e; EntityBuffer::Add(this); }" if len(self.constructor_args_list) else "") )%self.__dict__)%self.__dict__
def __init__(self,l): self.name,self.type=l[1:3] self.fancy_name = self.name[:-4] if self.name.endswith("Enum") else self.name if isinstance(self.type,EnumType): enumerations.add(self.name) self.len = len(self.type) elif isinstance(self.type,SelectType): selections.add(self.name) simple_types[self.name] = self comment = IfcDocumentation.description(self.name) self.comment = comment+"\n" if comment else ''
def __str__(self): s = "" argv = self.argstart for a in self.l: class_name = indent = comment = optional_comment = "" is_array = isinstance(a.type,ArrayType) and a.type.is_shared_ptr() return_type = str(a.type) if generator_mode == 'SOURCE': class_name = "%(class_name)s::" if isinstance(a.type,BinaryType) or (isinstance(a.type,ArrayType) and isinstance(a.type.type,BinaryType)): function_body = " { throw; /* Not implemented argument*/ }" elif isinstance(a.type,ArrayType) and str(a.type.type) in entity_names: function_body = " { RETURN_AS_LIST(%s,%d) }"%(a.type.type,argv) elif isinstance(a.type,ArrayType) and str(a.type.type) in selections: function_body = " { RETURN_AS_LIST(IfcAbstractSelect,%d) }"%(argv) elif return_type in entity_names: function_body = " { return reinterpret_pointer_cast<IfcBaseClass,%s>(*entity->getArgument(%d)); }"%(return_type,argv) elif return_type in enumerations: function_body = " { return %s::FromString(*entity->getArgument(%d)); }"%(return_type,argv) else: function_body = " { return *entity->getArgument(%d); }"%argv function_body2 = " { return !entity->getArgument(%d)->isNull(); }"%argv if isinstance(a.type,BinaryType) or (isinstance(a.type,ArrayType) and isinstance(a.type.type,BinaryType)): function_body3 = " { if ( ! entity->isWritable() ) { throw; } }" elif return_type in enumerations: function_body3 = " { if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(%d,v%s,%s::ToString(v)); }"%(argv,"->generalize()" if is_array else "",return_type) else: function_body3 = " { if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(%d,v%s); }"%(argv,"->generalize()" if is_array else "") else: indent = " " function_body = function_body2 = function_body3 = ";" comment = IfcDocumentation.description((self.class_name,a.name)) comment = comment+"\n" if comment else '' comment = comment.replace("///","%s///"%indent) optional_comment = "%s/// Whether the optional attribute %s is defined for this %s\n"%(indent,a.name,self.class_name) if a.optional: s += "\n%s%sbool %shas%s()%s"%(optional_comment,indent,class_name,a.name,function_body2) if ( str(a.type) in enumerations ): return_type = "%(type)s::%(type)s"%a.__dict__ elif ( str(a.type) in entity_names ): return_type = "%(type)s*"%a.__dict__ s += "\n%s%s%s %s%s()%s"%(comment,indent,return_type,class_name,a.name,function_body) s += "\n%svoid %sset%s(%s v)%s"%(indent,class_name,a.name,return_type,function_body3) argv += 1 if generator_mode == 'HEADER': s += "\n virtual unsigned int getArgumentCount() const { return %(n_arguments)d; }" % dict(class_name=self.class_name, n_arguments=len(self.l) + argument_start(self.class_name)) s += "\n virtual ArgumentType getArgumentType(unsigned int i) const {" if len(self.l): s += " switch (i) {" for i, a in enumerate(self.l): s += "case %d: " % (i + argument_start(self.class_name)) s += "return %s; " % a.type.type_enum() s += "}" if self.parent_class is not None: s += " return %s::getArgumentType(i); }" % self.parent_class else: s += " throw IfcException(\"argument out of range\"); }" s += "\n virtual const char* getArgumentName(unsigned int i) const {" if len(self.l): s += " switch (i) {" for i, a in enumerate(self.l): s += "case %d: " % (i + argument_start(self.class_name)) s += "return \"%s\"; " % a.name s += "}" if self.parent_class is not None: s += " return %s::getArgumentName(i); }" % self.parent_class else: s += " throw IfcException(\"argument out of range\"); }" s += "\n virtual ArgumentPtr getArgument(unsigned int i) const { return entity->getArgument(i); }" return s