Add support for reading and writing BINARY attributes. Rename members of the IfcUtil::ArgumentType enumeration.

This commit is contained in:
Thomas Krijnen
2015-04-07 15:06:56 +00:00
parent 462425f61d
commit 955190b517
21 changed files with 1915 additions and 1715 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ boost::optional<std::string> format_attribute(const Argument* argument, IfcUtil:
stream << v;
value = stream.str();
break; }
case IfcUtil::Argument_ENTITY: {
case IfcUtil::Argument_ENTITY_INSTANCE: {
IfcUtil::IfcBaseClass* e = *argument;
if (Type::IsSimple(e->type())) {
IfcUtil::IfcBaseType* f = (IfcUtil::IfcBaseType*) e;
+15 -12
View File
@@ -28,7 +28,14 @@ class Mapping:
'integer' : 'int',
'real' : 'double',
'number' : 'double',
'string' : 'std::string'
'string' : 'std::string',
'binary' : 'boost::dynamic_bitset<>'
}
supported_argument_types = {
'INT', 'BOOL', 'DOUBLE', 'STRING', 'BINARY', 'ENUMERATION', 'ENTITY_INSTANCE',
'AGGREGATE_OF_INT', 'AGGREGATE_OF_DOUBLE', 'AGGREGATE_OF_STRING', 'AGGREGATE_OF_BINARY', 'AGGREGATE_OF_ENTITY_INSTANCE',
'AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE'
}
def __init__(self, schema):
@@ -77,24 +84,21 @@ class Mapping:
def _make_argument_type(type):
if type in self.express_to_cpp_typemapping:
return self.express_to_cpp_typemapping.get(type, type).split('::')[-1].upper()
elif self.schema.is_entity(type):
return "ENTITY"
elif self.schema.is_entity(type) or isinstance(type, nodes.SelectType):
return "ENTITY_INSTANCE"
elif self.schema.is_type(type):
return _make_argument_type(self.schema.types[type].type.type)
elif isinstance(type, nodes.BinaryType):
return "UNKNOWN"
return "BINARY"
elif isinstance(type, nodes.EnumerationType):
return "ENUMERATION"
elif isinstance(type, nodes.SelectType):
return "ENTITY"
elif isinstance(type, nodes.AggregationType):
ty = _make_argument_type(type.type)
if ty == "UNKNOWN": return "UNKNOWN"
return "%s_LIST"%ty if ty.startswith("ENTITY") else ("VECTOR_%s"%ty)
return "AGGREGATE_OF_" + ty
else: raise ValueError
supported = {'INT', 'BOOL', 'DOUBLE', 'STRING', 'VECTOR_INT', 'VECTOR_DOUBLE', 'VECTOR_STRING', 'ENTITY', 'ENTITY_LIST', 'ENTITY_LIST_LIST', 'ENUMERATION'}
ty = _make_argument_type(attr.type if hasattr(attr, 'type') else attr)
if ty not in supported: ty = 'UNKNOWN'
if ty not in self.supported_argument_types: ty = 'UNKNOWN'
return "IfcUtil::Argument_%s" % ty
def get_type_dep(self, type):
@@ -104,7 +108,6 @@ class Mapping:
return self.get_type_dep(type.type)
def get_parameter_type(self, attr, allow_optional, allow_entities, allow_pointer = True):
attr_type = self.flatten_type(attr.type)
type_str = self.express_to_cpp_typemapping.get(str(attr_type), attr_type)
@@ -115,7 +118,7 @@ class Mapping:
elif isinstance(type_str, nodes.AggregationType):
is_nested_list = isinstance(attr_type.type, nodes.AggregationType)
ty = self.get_parameter_type(attr_type.type if is_nested_list else attr_type, False, allow_entities, False)
if True and self.schema.is_select(attr_type.type):
if self.schema.is_select(attr_type.type):
type_str = templates.untyped_list
elif self.schema.is_simpletype(ty) or ty in self.express_to_cpp_typemapping.values():
type_str = templates.array_type % {
@@ -151,7 +154,7 @@ class Mapping:
return c + ([str(s) for s in t.derive.elements] if t.derive else [])
def list_instance_type(self, attr):
f = lambda v : 'IfcUtil::IfcBaseClass' if self.schema.is_select(v) else v
f = lambda v : 'IfcUtil::IfcBaseClass' if self.schema.is_select(v) else str(v)
if self.is_array(attr.type):
if not isinstance(attr.type, str) and self.is_array(attr.type.type):
if isinstance(attr.type.type, str):
+1 -1
View File
@@ -149,7 +149,7 @@ class BinaryType(Node):
def init(self):
pass
def __repr__(self):
return "BINARY"
return "binary"
class BoundSpecification(Node):
-1
View File
@@ -415,7 +415,6 @@ inverse_attr = "IfcTemplatedEntityList< %(entity)s >::ptr %(name)s() const; // I
enum_from_string_stmt = ' if (s == "%(value)s") return ::%(schema_name)s::%(name)s::%(short_name)s_%(value)s;'
schema_entity_stmt = ' case Type::%(name)s: return new %(name)s(e); break;'
schema_simple_stmt = ' case Type::%(name)s: return new IfcUtil::IfcEntitySelect(e); break;'
string_map_statement = ' string_map["%(uppercase_name)s"%(padding)s] = Type::%(name)s;'
parent_type_stmt = ' if(v==%(name)s%(padding)s) { return %(parent)s; }'
File diff suppressed because it is too large Load Diff
+4 -2
View File
@@ -23,7 +23,7 @@
* but instead modify the python script that has been used to generate this. *
* *
********************************************************************************/
#ifndef USE_IFC4
#include "../ifcparse/Ifc2x3.h"
@@ -10710,11 +10710,13 @@ int IfcPixelTexture::Height() const { return *entity->getArgument(5); }
void IfcPixelTexture::setHeight(int v) { if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(5,v); }
int IfcPixelTexture::ColourComponents() const { return *entity->getArgument(6); }
void IfcPixelTexture::setColourComponents(int v) { if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(6,v); }
std::vector< boost::dynamic_bitset<> > /*[1:?]*/ IfcPixelTexture::Pixel() const { return *entity->getArgument(7); }
void IfcPixelTexture::setPixel(std::vector< boost::dynamic_bitset<> > /*[1:?]*/ v) { if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(7,v); }
bool IfcPixelTexture::is(Type::Enum v) const { return v == Type::IfcPixelTexture || IfcSurfaceTexture::is(v); }
Type::Enum IfcPixelTexture::type() const { return Type::IfcPixelTexture; }
Type::Enum IfcPixelTexture::Class() { return Type::IfcPixelTexture; }
IfcPixelTexture::IfcPixelTexture(IfcAbstractEntity* e) : IfcSurfaceTexture((IfcAbstractEntity*)0) { if (!e) return; if (!e->is(Type::IfcPixelTexture)) throw IfcException("Unable to find find keyword in schema"); entity = e; }
IfcPixelTexture::IfcPixelTexture(bool v1_RepeatS, bool v2_RepeatT, IfcSurfaceTextureEnum::IfcSurfaceTextureEnum v3_TextureType, IfcCartesianTransformationOperator2D* v4_TextureTransform, int v5_Width, int v6_Height, int v7_ColourComponents) : IfcSurfaceTexture((IfcAbstractEntity*)0) { IfcWritableEntity* e = new IfcWritableEntity(Class()); e->setArgument(0,(v1_RepeatS)); e->setArgument(1,(v2_RepeatT)); e->setArgument(2,v3_TextureType,IfcSurfaceTextureEnum::ToString(v3_TextureType)); e->setArgument(3,(v4_TextureTransform)); e->setArgument(4,(v5_Width)); e->setArgument(5,(v6_Height)); e->setArgument(6,(v7_ColourComponents)); entity = e; EntityBuffer::Add(this); }
IfcPixelTexture::IfcPixelTexture(bool v1_RepeatS, bool v2_RepeatT, IfcSurfaceTextureEnum::IfcSurfaceTextureEnum v3_TextureType, IfcCartesianTransformationOperator2D* v4_TextureTransform, int v5_Width, int v6_Height, int v7_ColourComponents, std::vector< boost::dynamic_bitset<> > /*[1:?]*/ v8_Pixel) : IfcSurfaceTexture((IfcAbstractEntity*)0) { IfcWritableEntity* e = new IfcWritableEntity(Class()); e->setArgument(0,(v1_RepeatS)); e->setArgument(1,(v2_RepeatT)); e->setArgument(2,v3_TextureType,IfcSurfaceTextureEnum::ToString(v3_TextureType)); e->setArgument(3,(v4_TextureTransform)); e->setArgument(4,(v5_Width)); e->setArgument(5,(v6_Height)); e->setArgument(6,(v7_ColourComponents)); e->setArgument(7,(v8_Pixel)); entity = e; EntityBuffer::Add(this); }
// Function implementations for IfcPlacement
IfcCartesianPoint* IfcPlacement::Location() const { return (IfcCartesianPoint*)((IfcUtil::IfcBaseClass*)(*entity->getArgument(0))); }
+286 -284
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -23,7 +23,7 @@
* but instead modify the python script that has been used to generate this. *
* *
********************************************************************************/
#ifndef IFC2X3ENUM_H
#define IFC2X3ENUM_H
File diff suppressed because it is too large Load Diff
+8 -4
View File
@@ -23,7 +23,7 @@
* but instead modify the python script that has been used to generate this. *
* *
********************************************************************************/
#ifdef USE_IFC4
#include "../ifcparse/Ifc4.h"
@@ -7360,7 +7360,7 @@ IfcPressureMeasure::IfcPressureMeasure(double v) { IfcWritableEntity* e = new If
IfcPressureMeasure::operator double() const { return *entity->getArgument(0); }
// Function implementations for IfcPropertySetDefinitionSet
IfcUtil::ArgumentType IfcPropertySetDefinitionSet::getArgumentType(unsigned int i) const { if (i == 0) { return IfcUtil::Argument_ENTITY; } else { throw IfcParse::IfcException("argument out of range"); } }
IfcUtil::ArgumentType IfcPropertySetDefinitionSet::getArgumentType(unsigned int i) const { if (i == 0) { return IfcUtil::Argument_ENTITY_INSTANCE; } else { throw IfcParse::IfcException("argument out of range"); } }
Argument* IfcPropertySetDefinitionSet::getArgument(unsigned int i) const { return entity->getArgument(i); }
bool IfcPropertySetDefinitionSet::is(Type::Enum v) const { return v == IfcPropertySetDefinitionSet::Class(); }
Type::Enum IfcPropertySetDefinitionSet::type() const { return Type::IfcPropertySetDefinitionSet; }
@@ -8319,11 +8319,13 @@ IfcBeamType::IfcBeamType(std::string v1_GlobalId, IfcOwnerHistory* v2_OwnerHisto
// Function implementations for IfcBlobTexture
std::string IfcBlobTexture::RasterFormat() const { return *entity->getArgument(5); }
void IfcBlobTexture::setRasterFormat(std::string v) { if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(5,v); }
boost::dynamic_bitset<> IfcBlobTexture::RasterCode() const { return *entity->getArgument(6); }
void IfcBlobTexture::setRasterCode(boost::dynamic_bitset<> v) { if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(6,v); }
bool IfcBlobTexture::is(Type::Enum v) const { return v == Type::IfcBlobTexture || IfcSurfaceTexture::is(v); }
Type::Enum IfcBlobTexture::type() const { return Type::IfcBlobTexture; }
Type::Enum IfcBlobTexture::Class() { return Type::IfcBlobTexture; }
IfcBlobTexture::IfcBlobTexture(IfcAbstractEntity* e) : IfcSurfaceTexture((IfcAbstractEntity*)0) { if (!e) return; if (!e->is(Type::IfcBlobTexture)) throw IfcException("Unable to find find keyword in schema"); entity = e; }
IfcBlobTexture::IfcBlobTexture(bool v1_RepeatS, bool v2_RepeatT, boost::optional< std::string > v3_Mode, IfcCartesianTransformationOperator2D* v4_TextureTransform, boost::optional< std::vector< std::string > /*[1:?]*/ > v5_Parameter, std::string v6_RasterFormat) : IfcSurfaceTexture((IfcAbstractEntity*)0) { IfcWritableEntity* e = new IfcWritableEntity(Class()); e->setArgument(0,(v1_RepeatS)); e->setArgument(1,(v2_RepeatT)); if (v3_Mode) { e->setArgument(2,(*v3_Mode)); } else { e->setArgument(2); } e->setArgument(3,(v4_TextureTransform)); if (v5_Parameter) { e->setArgument(4,(*v5_Parameter)); } else { e->setArgument(4); } e->setArgument(5,(v6_RasterFormat)); entity = e; EntityBuffer::Add(this); }
IfcBlobTexture::IfcBlobTexture(bool v1_RepeatS, bool v2_RepeatT, boost::optional< std::string > v3_Mode, IfcCartesianTransformationOperator2D* v4_TextureTransform, boost::optional< std::vector< std::string > /*[1:?]*/ > v5_Parameter, std::string v6_RasterFormat, boost::dynamic_bitset<> v7_RasterCode) : IfcSurfaceTexture((IfcAbstractEntity*)0) { IfcWritableEntity* e = new IfcWritableEntity(Class()); e->setArgument(0,(v1_RepeatS)); e->setArgument(1,(v2_RepeatT)); if (v3_Mode) { e->setArgument(2,(*v3_Mode)); } else { e->setArgument(2); } e->setArgument(3,(v4_TextureTransform)); if (v5_Parameter) { e->setArgument(4,(*v5_Parameter)); } else { e->setArgument(4); } e->setArgument(5,(v6_RasterFormat)); e->setArgument(6,(v7_RasterCode)); entity = e; EntityBuffer::Add(this); }
// Function implementations for IfcBlock
double IfcBlock::XLength() const { return *entity->getArgument(1); }
@@ -12673,11 +12675,13 @@ int IfcPixelTexture::Height() const { return *entity->getArgument(6); }
void IfcPixelTexture::setHeight(int v) { if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(6,v); }
int IfcPixelTexture::ColourComponents() const { return *entity->getArgument(7); }
void IfcPixelTexture::setColourComponents(int v) { if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(7,v); }
std::vector< boost::dynamic_bitset<> > /*[1:?]*/ IfcPixelTexture::Pixel() const { return *entity->getArgument(8); }
void IfcPixelTexture::setPixel(std::vector< boost::dynamic_bitset<> > /*[1:?]*/ v) { if ( ! entity->isWritable() ) { entity = new IfcWritableEntity(entity); } ((IfcWritableEntity*)entity)->setArgument(8,v); }
bool IfcPixelTexture::is(Type::Enum v) const { return v == Type::IfcPixelTexture || IfcSurfaceTexture::is(v); }
Type::Enum IfcPixelTexture::type() const { return Type::IfcPixelTexture; }
Type::Enum IfcPixelTexture::Class() { return Type::IfcPixelTexture; }
IfcPixelTexture::IfcPixelTexture(IfcAbstractEntity* e) : IfcSurfaceTexture((IfcAbstractEntity*)0) { if (!e) return; if (!e->is(Type::IfcPixelTexture)) throw IfcException("Unable to find find keyword in schema"); entity = e; }
IfcPixelTexture::IfcPixelTexture(bool v1_RepeatS, bool v2_RepeatT, boost::optional< std::string > v3_Mode, IfcCartesianTransformationOperator2D* v4_TextureTransform, boost::optional< std::vector< std::string > /*[1:?]*/ > v5_Parameter, int v6_Width, int v7_Height, int v8_ColourComponents) : IfcSurfaceTexture((IfcAbstractEntity*)0) { IfcWritableEntity* e = new IfcWritableEntity(Class()); e->setArgument(0,(v1_RepeatS)); e->setArgument(1,(v2_RepeatT)); if (v3_Mode) { e->setArgument(2,(*v3_Mode)); } else { e->setArgument(2); } e->setArgument(3,(v4_TextureTransform)); if (v5_Parameter) { e->setArgument(4,(*v5_Parameter)); } else { e->setArgument(4); } e->setArgument(5,(v6_Width)); e->setArgument(6,(v7_Height)); e->setArgument(7,(v8_ColourComponents)); entity = e; EntityBuffer::Add(this); }
IfcPixelTexture::IfcPixelTexture(bool v1_RepeatS, bool v2_RepeatT, boost::optional< std::string > v3_Mode, IfcCartesianTransformationOperator2D* v4_TextureTransform, boost::optional< std::vector< std::string > /*[1:?]*/ > v5_Parameter, int v6_Width, int v7_Height, int v8_ColourComponents, std::vector< boost::dynamic_bitset<> > /*[1:?]*/ v9_Pixel) : IfcSurfaceTexture((IfcAbstractEntity*)0) { IfcWritableEntity* e = new IfcWritableEntity(Class()); e->setArgument(0,(v1_RepeatS)); e->setArgument(1,(v2_RepeatT)); if (v3_Mode) { e->setArgument(2,(*v3_Mode)); } else { e->setArgument(2); } e->setArgument(3,(v4_TextureTransform)); if (v5_Parameter) { e->setArgument(4,(*v5_Parameter)); } else { e->setArgument(4); } e->setArgument(5,(v6_Width)); e->setArgument(6,(v7_Height)); e->setArgument(7,(v8_ColourComponents)); e->setArgument(8,(v9_Pixel)); entity = e; EntityBuffer::Add(this); }
// Function implementations for IfcPlacement
IfcCartesianPoint* IfcPlacement::Location() const { return (IfcCartesianPoint*)((IfcUtil::IfcBaseClass*)(*entity->getArgument(0))); }
+300 -296
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -23,7 +23,7 @@
* but instead modify the python script that has been used to generate this. *
* *
********************************************************************************/
#ifndef IFC4ENUM_H
#define IFC4ENUM_H
+24 -14
View File
@@ -122,58 +122,68 @@ void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, int v) {
writable_entity()->setArgument(i,v);
} else if ( (arg_type == Argument_BOOL) && ( (v == 0) || (v == 1) ) ) {
writable_entity()->setArgument(i, v == 1);
} else invalid_argument(i,"INT");
} else invalid_argument(i,"INTEGER");
}
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, bool v) {
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
if (arg_type == Argument_BOOL) {
writable_entity()->setArgument(i,v);
} else invalid_argument(i,"BOOL");
} else invalid_argument(i,"BOOLEAN");
}
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, double v) {
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
if (arg_type == Argument_DOUBLE) {
writable_entity()->setArgument(i,v);
} else invalid_argument(i,"DOUBLE");
} else invalid_argument(i,"REAL");
}
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, const std::string& a) {
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
if (arg_type == Argument_STRING) {
writable_entity()->setArgument(i,a);
writable_entity()->setArgument(i,a);
} else if (arg_type == Argument_ENUMERATION) {
std::pair<const char*, int> enum_data = IfcSchema::Type::GetEnumerationIndex(IfcSchema::Type::GetAttributeEntity(_type, i), a);
writable_entity()->setArgument(i, enum_data.second, enum_data.first);
} else if (arg_type == Argument_BINARY) {
boost::dynamic_bitset<> bits(a);
writable_entity()->setArgument(i, bits);
} else invalid_argument(i,"STRING");
}
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, const std::vector<int>& v) {
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
if (arg_type == Argument_VECTOR_INT) {
if (arg_type == Argument_AGGREGATE_OF_INT) {
writable_entity()->setArgument(i,v);
} else invalid_argument(i,"LIST of INT");
} else invalid_argument(i,"AGGREGATE OF INT");
}
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, const std::vector<double>& v) {
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
if (arg_type == Argument_VECTOR_DOUBLE) {
if (arg_type == Argument_AGGREGATE_OF_DOUBLE) {
writable_entity()->setArgument(i,v);
} else invalid_argument(i,"LIST of DOUBLE");
} else invalid_argument(i,"AGGREGATE OF DOUBLE");
}
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, const std::vector<std::string>& v) {
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
if (arg_type == Argument_VECTOR_STRING) {
if (arg_type == Argument_AGGREGATE_OF_STRING) {
writable_entity()->setArgument(i,v);
} else invalid_argument(i,"LIST of STRING");
} else if (arg_type == Argument_AGGREGATE_OF_BINARY) {
std::vector< boost::dynamic_bitset<> > bits;
bits.reserve(v.size());
for (std::vector<std::string>::const_iterator it = v.begin(); it != v.end(); ++it) {
bits.push_back(boost::dynamic_bitset<>(*it));
}
writable_entity()->setArgument(i, bits);
} else invalid_argument(i,"AGGREGATE OF STRING");
}
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, IfcParse::IfcLateBoundEntity* v) {
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
if (arg_type == Argument_ENTITY) {
if (arg_type == Argument_ENTITY_INSTANCE) {
writable_entity()->setArgument(i,v);
} else invalid_argument(i,"ENTITY");
} else invalid_argument(i,"ENTITY INSTANCE");
}
void IfcParse::IfcLateBoundEntity::setArgument(unsigned int i, IfcEntityList::ptr v) {
IfcUtil::ArgumentType arg_type = IfcSchema::Type::GetAttributeType(_type,i);
if (arg_type == Argument_ENTITY_LIST) {
if (arg_type == Argument_AGGREGATE_OF_ENTITY_INSTANCE) {
writable_entity()->setArgument(i,v);
} else invalid_argument(i,"LIST of ENTITY");
} else invalid_argument(i,"AGGREGATE OF ENTITY INSTANCE");
}
std::pair<IfcUtil::ArgumentType,Argument*> IfcParse::IfcLateBoundEntity::get_argument(unsigned i) {
return std::pair<IfcUtil::ArgumentType,Argument*>(getArgumentType(i),getArgument(i));
+91 -47
View File
@@ -376,9 +376,13 @@ bool TokenFunc::isEnumeration(const Token& t) {
return ! isOperator(t) && startsWith(t, '.');
}
bool TokenFunc::isBinary(const Token& t) {
return ! isOperator(t) && startsWith(t, '"');
}
bool TokenFunc::isKeyword(const Token& t) {
// bool is a subtype of enumeration, no need to test for that
return !isOperator(t) && !isIdentifier(t) && !isString(t) && !isEnumeration(t) && !isInt(t) && !isFloat(t);
return !isOperator(t) && !isIdentifier(t) && !isString(t) && !isEnumeration(t) && !isInt(t) && !isFloat(t) && !isBinary(t);
}
bool TokenFunc::isInt(const Token& t) {
@@ -445,7 +449,37 @@ std::string TokenFunc::asString(const Token& t) {
if ( isOperator(t,'$') ) return "";
else if ( isOperator(t) ) throw IfcException("Token is not a string");
std::string str = t.first->TokenString(t.second);
return isString(t) || isEnumeration(t) ? str.substr(1,str.size()-2) : str;
return isString(t) || isEnumeration(t) || isBinary(t) ? str.substr(1,str.size()-2) : str;
}
boost::dynamic_bitset<> TokenFunc::asBinary(const Token& t) {
const std::string str = asString(t);
if (str.size() < 1) {
throw IfcException("Token is not a valid binary sequence");
}
std::string::const_iterator it = str.begin();
int n = *it - '0';
if ((n < 0 || n > 3) || (str.size() == 1 && n != 0)) {
throw IfcException("Token is not a valid binary sequence");
}
++it;
unsigned i = (str.size()-1) * 4 - n;
boost::dynamic_bitset<> bitset(i);
for(; it != str.end(); ++it) {
const std::string::value_type& c = *it;
int value = (c < 'A') ? (c - '0') : (c - 'A' + 10);
for (unsigned j = 0; j < 4; ++j) {
if (i-- == 0) break;
if (value & (1 << (3-j))) {
bitset.set(i);
}
}
}
return bitset;
}
std::string TokenFunc::toString(const Token& t) {
@@ -506,13 +540,17 @@ IfcUtil::ArgumentType ArgumentList::type() const {
if (list.empty()) return IfcUtil::Argument_UNKNOWN;
const IfcUtil::ArgumentType elem_type = list[0]->type();
if (elem_type == IfcUtil::Argument_INT) {
return IfcUtil::Argument_VECTOR_INT;
return IfcUtil::Argument_AGGREGATE_OF_INT;
} else if (elem_type == IfcUtil::Argument_DOUBLE) {
return IfcUtil::Argument_VECTOR_DOUBLE;
return IfcUtil::Argument_AGGREGATE_OF_DOUBLE;
} else if (elem_type == IfcUtil::Argument_STRING) {
return IfcUtil::Argument_VECTOR_STRING;
} else if (elem_type == IfcUtil::Argument_ENTITY) {
return IfcUtil::Argument_ENTITY_LIST;
return IfcUtil::Argument_AGGREGATE_OF_STRING;
} else if (elem_type == IfcUtil::Argument_BINARY) {
return IfcUtil::Argument_AGGREGATE_OF_BINARY;
} else if (elem_type == IfcUtil::Argument_ENTITY_INSTANCE) {
return IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE;
} else if (elem_type == IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE) {
return IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE;
} else {
return IfcUtil::Argument_UNKNOWN;
}
@@ -522,6 +560,18 @@ void ArgumentList::push(Argument* l) {
list.push_back(l);
}
// templated helper function for reading arguments into a list
template<typename T>
std::vector<T> read_list_as_vector(const std::vector<Argument*>& list) {
std::vector<T> return_value;
return_value.reserve(list.size());
std::vector<Argument*>::const_iterator it = list.begin();
for (; it != list.end(); ++it) {
return_value.push_back(**it);
}
return return_value;
}
//
// Functions for casting the ArgumentList to other types
//
@@ -529,32 +579,20 @@ ArgumentList::operator int() const { throw IfcException("Argument is not an inte
ArgumentList::operator bool() const { throw IfcException("Argument is not a boolean"); }
ArgumentList::operator double() const { throw IfcException("Argument is not a number"); }
ArgumentList::operator std::string() const { throw IfcException("Argument is not a string"); }
ArgumentList::operator boost::dynamic_bitset<>() const { throw IfcException("Argument is not a binary"); }
ArgumentList::operator std::vector<double>() const {
std::vector<double> r;
std::vector<Argument*>::const_iterator it;
for ( it = list.begin(); it != list.end(); ++ it ) {
r.push_back(**it);
}
return r;
return read_list_as_vector<double>(list);
}
ArgumentList::operator std::vector<int>() const {
std::vector<int> r;
std::vector<Argument*>::const_iterator it;
for ( it = list.begin(); it != list.end(); ++ it ) {
r.push_back(**it);
}
return r;
return read_list_as_vector<int>(list);
}
ArgumentList::operator std::vector<std::string>() const {
std::vector<std::string> r;
std::vector<Argument*>::const_iterator it;
for ( it = list.begin(); it != list.end(); ++ it ) {
r.push_back(**it);
}
return r;
return read_list_as_vector<std::string>(list);
}
ArgumentList::operator IfcUtil::IfcBaseClass*() const { throw IfcException("Argument is not an IFC type"); }
//ArgumentList::operator IfcUtil::IfcAbstractSelect::ptr() const { throw IfcException("Argument is not an IFC type"); }
ArgumentList::operator std::vector<boost::dynamic_bitset<> >() const {
return read_list_as_vector<boost::dynamic_bitset<> >(list);
}
ArgumentList::operator IfcUtil::IfcBaseClass*() const { throw IfcException("Argument is not an entity instance"); }
ArgumentList::operator IfcEntityList::ptr() const {
IfcEntityList::ptr l ( new IfcEntityList() );
std::vector<Argument*>::const_iterator it;
@@ -626,7 +664,9 @@ IfcUtil::ArgumentType TokenArgument::type() const {
} else if (TokenFunc::isEnumeration(token)) {
return IfcUtil::Argument_ENUMERATION;
} else if (TokenFunc::isIdentifier(token)) {
return IfcUtil::Argument_ENTITY;
return IfcUtil::Argument_ENTITY_INSTANCE;
} else if (TokenFunc::isBinary(token)) {
return IfcUtil::Argument_BINARY;
} else if (TokenFunc::isOperator(token, '$')) {
return IfcUtil::Argument_NULL;
} else if (TokenFunc::isOperator(token, '*')) {
@@ -643,14 +683,16 @@ TokenArgument::operator int() const { return TokenFunc::asInt(token); }
TokenArgument::operator bool() const { return TokenFunc::asBool(token); }
TokenArgument::operator double() const { return TokenFunc::asFloat(token); }
TokenArgument::operator std::string() const { return TokenFunc::asString(token); }
TokenArgument::operator boost::dynamic_bitset<>() const { return TokenFunc::asBinary(token); }
TokenArgument::operator std::vector<double>() const { throw IfcException("Argument is not a list of floats"); }
TokenArgument::operator std::vector<int>() const { throw IfcException("Argument is not a list of ints"); }
TokenArgument::operator std::vector<std::string>() const { throw IfcException("Argument is not a list of strings"); }
TokenArgument::operator std::vector<boost::dynamic_bitset<> >() const { throw IfcException("Argument is not a list of binaries"); }
TokenArgument::operator IfcUtil::IfcBaseClass*() const { return token.first->file->entityById(TokenFunc::asInt(token)); }
TokenArgument::operator IfcEntityList::ptr() const { throw IfcException("Argument is not a list of entities"); }
TokenArgument::operator IfcEntityListList::ptr() const { throw IfcException("Argument is not a list of entity lists"); }
TokenArgument::operator IfcEntityList::ptr() const { throw IfcException("Argument is not a list of entity instances"); }
TokenArgument::operator IfcEntityListList::ptr() const { throw IfcException("Argument is not a list of list of entity instances"); }
unsigned int TokenArgument::size() const { return 1; }
Argument* TokenArgument::operator [] (unsigned int i) const { throw IfcException("Argument is not a list of arguments"); }
Argument* TokenArgument::operator [] (unsigned int i) const { throw IfcException("Argument is not a list of attributes"); }
std::string TokenArgument::toString(bool upper) const {
if ( upper && TokenFunc::isString(token) ) {
return IfcWrite::IfcCharacterEncoder(TokenFunc::asString(token));
@@ -661,7 +703,7 @@ std::string TokenArgument::toString(bool upper) const {
bool TokenArgument::isNull() const { return TokenFunc::isOperator(token,'$'); }
IfcUtil::ArgumentType EntityArgument::type() const {
return IfcUtil::Argument_ENTITY;
return IfcUtil::Argument_ENTITY_INSTANCE;
}
//
@@ -670,14 +712,16 @@ IfcUtil::ArgumentType EntityArgument::type() const {
EntityArgument::operator int() const { throw IfcException("Argument is not an integer"); }
EntityArgument::operator bool() const { throw IfcException("Argument is not a boolean"); }
EntityArgument::operator double() const { throw IfcException("Argument is not a number"); }
EntityArgument::operator boost::dynamic_bitset<>() const { throw IfcException("Argument is not a binary"); }
EntityArgument::operator std::string() const { throw IfcException("Argument is not a string"); }
EntityArgument::operator std::vector<double>() const { throw IfcException("Argument is not a list of floats"); }
EntityArgument::operator std::vector<int>() const { throw IfcException("Argument is not a list of ints"); }
EntityArgument::operator std::vector<std::string>() const { throw IfcException("Argument is not a list of strings"); }
EntityArgument::operator std::vector<boost::dynamic_bitset<> >() const { throw IfcException("Argument is not a list of binaries"); }
EntityArgument::operator IfcUtil::IfcBaseClass*() const { return entity; }
//EntityArgument::operator IfcUtil::IfcAbstractSelect::ptr() const { return entity; }
EntityArgument::operator IfcEntityList::ptr() const { throw IfcException("Argument is not a list of entities"); }
EntityArgument::operator IfcEntityListList::ptr() const { throw IfcException("Argument is not a list of entity lists"); }
EntityArgument::operator IfcEntityList::ptr() const { throw IfcException("Argument is not a list of entity instances"); }
EntityArgument::operator IfcEntityListList::ptr() const { throw IfcException("Argument is not a list of list of entity instances"); }
unsigned int EntityArgument::size() const { return 1; }
Argument* EntityArgument::operator [] (unsigned int i) const { throw IfcException("Argument is not a list of arguments"); }
std::string EntityArgument::toString(bool upper) const {
@@ -951,14 +995,14 @@ void IfcFile::traverse(IfcUtil::IfcBaseClass* instance, std::set<IfcUtil::IfcBas
for (unsigned i = 0; i < instance->getArgumentCount(); ++i) {
Argument* arg = instance->getArgument(i);
if (arg->type() == IfcUtil::Argument_ENTITY) {
if (arg->type() == IfcUtil::Argument_ENTITY_INSTANCE) {
traverse(*arg, visited, list, level + 1, max_level);
} else if (arg->type() == IfcUtil::Argument_ENTITY_LIST) {
} else if (arg->type() == IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE) {
IfcEntityList::ptr entity_list_attribute = *arg;
for (IfcEntityList::it it = entity_list_attribute->begin(); it != entity_list_attribute->end(); ++it) {
traverse(*it, visited, list, level + 1, max_level);
}
} else if (arg->type() == IfcUtil::Argument_ENTITY_LIST_LIST) {
} else if (arg->type() == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE) {
IfcEntityListList::ptr entity_list_attribute = *arg;
for (IfcEntityListList::outer_it it = entity_list_attribute->begin(); it != entity_list_attribute->end(); ++it) {
for (IfcEntityListList::inner_it jt = it->begin(); jt != it->end(); ++jt) {
@@ -1029,11 +1073,11 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity) {
for (unsigned i = 0; i < we->getArgumentCount(); ++i) {
Argument* attr = we->getArgument(i);
IfcUtil::ArgumentType attr_type = attr->type();
if (attr_type == IfcUtil::Argument_ENTITY) {
if (attr_type == IfcUtil::Argument_ENTITY_INSTANCE) {
entity_entity_map_t::const_iterator eit = entity_file_map.find(*attr);
if (eit == entity_file_map.end()) throw IfcParse::IfcException("Unable to map instance to file");
we->setArgument(i, eit->second);
} else if (attr_type == IfcUtil::Argument_ENTITY_LIST) {
} else if (attr_type == IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE) {
IfcEntityList::ptr instances = *attr;
IfcEntityList::ptr new_instances(new IfcEntityList);
for (IfcEntityList::it it = instances->begin(); it != instances->end(); ++it) {
@@ -1042,7 +1086,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity) {
new_instances->push(eit->second);
}
we->setArgument(i, new_instances);
} else if (attr_type == IfcUtil::Argument_ENTITY_LIST_LIST) {
} else if (attr_type == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE) {
IfcEntityListList::ptr instances = *attr;
IfcEntityListList::ptr new_instances(new IfcEntityListList);
for (IfcEntityListList::outer_it it = instances->begin(); it != instances->end(); ++it) {
@@ -1066,7 +1110,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity) {
double v = *attr;
v *= *conversion_factor;
we->setArgument(i, v);
} else if (attr_type == IfcUtil::Argument_VECTOR_DOUBLE) {
} else if (attr_type == IfcUtil::Argument_AGGREGATE_OF_DOUBLE) {
std::vector<double> v = *attr;
for (std::vector<double>::iterator it = v.begin(); it != v.end(); ++it) {
(*it) *= *conversion_factor;
@@ -1195,14 +1239,14 @@ void IfcFile::removeEntity(IfcUtil::IfcBaseClass* entity) {
IfcUtil::ArgumentType attr_type = related_instance->getArgumentType(i);
switch(attr_type) {
case IfcUtil::Argument_ENTITY: {
case IfcUtil::Argument_ENTITY_INSTANCE: {
IfcUtil::IfcBaseClass* instance_attribute = *attr;
if (instance_attribute == entity) {
make_writable(related_instance)->setArgument(i);
// deletion_queue.insert(related_instance);
} }
break;
case IfcUtil::Argument_ENTITY_LIST: {
case IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE: {
IfcEntityList::ptr instance_list = *attr;
if (instance_list->contains(entity)) {
instance_list->remove(entity);
@@ -1212,7 +1256,7 @@ void IfcFile::removeEntity(IfcUtil::IfcBaseClass* entity) {
} */
} }
break;
case IfcUtil::Argument_ENTITY_LIST_LIST: {
case IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE: {
IfcEntityListList::ptr instance_list_list = *attr;
if (instance_list_list->contains(entity)) {
IfcEntityListList::ptr new_list(new IfcEntityListList);
@@ -1364,12 +1408,12 @@ IfcEntityList::ptr IfcFile::getInverse(int instance_id, IfcSchema::Type::Enum ty
bool valid = type == IfcSchema::Type::UNDEFINED || (*it)->is(type);
if (valid && attribute_index >= 0) {
Argument* arg = (*it)->entity->getArgument(attribute_index);
if (arg->type() == IfcUtil::Argument_ENTITY) {
if (arg->type() == IfcUtil::Argument_ENTITY_INSTANCE) {
valid = instance == *arg;
} else if (arg->type() == IfcUtil::Argument_ENTITY_LIST) {
} else if (arg->type() == IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE) {
IfcEntityList::ptr li = *arg;
valid = li->contains(instance);
} else if (arg->type() == IfcUtil::Argument_ENTITY_LIST_LIST) {
} else if (arg->type() == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE) {
IfcEntityListList::ptr li = *arg;
valid = li->contains(instance);
}
+40 -18
View File
@@ -37,6 +37,8 @@
#include <cstring>
#include <map>
#include <boost/dynamic_bitset.hpp>
#include "../ifcparse/SharedPointer.h"
#include "../ifcparse/IfcCharacterDecoder.h"
#include "../ifcparse/IfcUtil.h"
@@ -81,6 +83,8 @@ namespace IfcParse {
static bool isBool(const Token& t);
/// Returns whether the token can be interpreted as a floating point number
static bool isFloat(const Token& t);
/// Returns whether the token can be interpreted as a binary type
static bool isBinary(const Token& t);
/// Returns the token interpreted as an integer
static int asInt(const Token& t);
/// Returns the token interpreted as an boolean (.T. or .F.)
@@ -89,6 +93,8 @@ namespace IfcParse {
static double asFloat(const Token& t);
/// Returns the token as a string (without the dot or apostrophe)
static std::string asString(const Token& t);
/// Returns the token as a string (without the dot or apostrophe)
static boost::dynamic_bitset<> asBinary(const Token& t);
/// Returns a string representation of the token (including the dot or apostrophe)
static std::string toString(const Token& t);
};
@@ -134,19 +140,24 @@ namespace IfcParse {
operator bool() const;
operator double() const;
operator std::string() const;
operator std::vector<double>() const;
operator std::vector<int>() const;
operator std::vector<std::string>() const;
operator boost::dynamic_bitset<>() const;
operator IfcUtil::IfcBaseClass*() const;
operator std::vector<int>() const;
operator std::vector<double>() const;
operator std::vector<std::string>() const;
operator std::vector<boost::dynamic_bitset<> >() const;
operator IfcEntityList::ptr() const;
operator IfcEntityListList::ptr() const;
operator IfcEntityListList::ptr() const;
bool isNull() const;
unsigned int size() const;
Argument* operator [] (unsigned int i) const;
void set(unsigned int i, Argument*);
std::string toString(bool upper=false) const;
bool isNull() const;
};
/// Argument of type scalar or string, e.g.
@@ -165,16 +176,21 @@ namespace IfcParse {
operator bool() const;
operator double() const;
operator std::string() const;
operator std::vector<double>() const;
operator std::vector<int>() const;
operator std::vector<std::string>() const;
operator boost::dynamic_bitset<>() const;
operator IfcUtil::IfcBaseClass*() const;
operator std::vector<int>() const;
operator std::vector<double>() const;
operator std::vector<std::string>() const;
operator std::vector<boost::dynamic_bitset<> >() const;
operator IfcEntityList::ptr() const;
operator IfcEntityListList::ptr() const;
unsigned int size() const;
Argument* operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
operator IfcEntityListList::ptr() const;
bool isNull() const;
unsigned int size() const;
Argument* operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
};
/// Argument of an IFC simple type
@@ -182,7 +198,7 @@ namespace IfcParse {
/// ===================== =====================
class EntityArgument : public Argument {
private:
IfcUtil::IfcBaseClass* entity;
IfcUtil::IfcBaseClass* entity;
public:
EntityArgument(const Token& t);
~EntityArgument();
@@ -193,16 +209,22 @@ namespace IfcParse {
operator bool() const;
operator double() const;
operator std::string() const;
operator std::vector<double>() const;
operator std::vector<int>() const;
operator std::vector<std::string>() const;
operator boost::dynamic_bitset<>() const;
operator IfcUtil::IfcBaseClass*() const;
operator std::vector<int>() const;
operator std::vector<double>() const;
operator std::vector<std::string>() const;
operator std::vector<boost::dynamic_bitset<> >() const;
operator IfcEntityList::ptr() const;
operator IfcEntityListList::ptr() const;
operator IfcEntityListList::ptr() const;
bool isNull() const;
unsigned int size() const;
Argument* operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
bool isNull() const;
};
/// Entity defined in an IFC file, e.g.
+13 -8
View File
@@ -112,14 +112,19 @@ static const char* const argument_type_string[] = {
"INT",
"BOOL",
"DOUBLE",
"STRING",
"VECTOR_INT",
"VECTOR_DOUBLE",
"VECTOR_STRING",
"ENUMERATION",
"ENTITY",
"ENTITY_LIST",
"ENTITY_LIST_LIST",
"STRING",
"BINARY",
"ENUMERATION",
"ENTITY_INSTANCE",
"AGGREGATE_OF_INT",
"AGGREGATE_OF_DOUBLE",
"AGGREGATE_OF_STRING",
"AGGREGATE_OF_BINARY",
"AGGREGATE_OF_ENTITY_INSTANCE",
"AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE",
"UNKNOWN"
};
+31 -16
View File
@@ -26,6 +26,8 @@
#include <sstream>
#include <algorithm>
#include <boost/dynamic_bitset.hpp>
#include "../ifcparse/SharedPointer.h"
#ifdef USE_IFC4
@@ -43,22 +45,27 @@ namespace IfcWrite {
}
namespace IfcUtil {
enum ArgumentType {
Argument_NULL,
enum ArgumentType {
Argument_NULL,
Argument_DERIVED,
Argument_INT,
Argument_BOOL,
Argument_DOUBLE,
Argument_STRING,
Argument_VECTOR_INT,
Argument_VECTOR_DOUBLE,
Argument_VECTOR_STRING,
Argument_STRING,
Argument_BINARY,
Argument_ENUMERATION,
Argument_ENTITY,
Argument_ENTITY_LIST,
Argument_ENTITY_LIST_LIST,
Argument_ENTITY_INSTANCE,
Argument_AGGREGATE_OF_INT,
Argument_AGGREGATE_OF_DOUBLE,
Argument_AGGREGATE_OF_STRING,
Argument_AGGREGATE_OF_BINARY,
Argument_AGGREGATE_OF_ENTITY_INSTANCE,
Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE,
Argument_UNKNOWN
};
};
const char* ArgumentTypeToString(ArgumentType argument_type);
@@ -247,21 +254,29 @@ namespace IfcParse {
class Argument {
public:
virtual IfcUtil::ArgumentType type() const = 0;
virtual operator int() const = 0;
virtual operator bool() const = 0;
virtual operator double() const = 0;
virtual operator std::string() const = 0;
virtual operator std::vector<double>() const = 0;
virtual operator std::vector<int>() const = 0;
virtual operator std::vector<std::string>() const = 0;
virtual operator boost::dynamic_bitset<>() const = 0;
virtual operator IfcUtil::IfcBaseClass*() const = 0;
virtual operator std::vector<int>() const = 0;
virtual operator std::vector<double>() const = 0;
virtual operator std::vector<std::string>() const = 0;
virtual operator std::vector<boost::dynamic_bitset<> >() const = 0;
virtual operator IfcEntityList::ptr() const = 0;
virtual operator IfcEntityListList::ptr() const = 0;
virtual operator IfcEntityListList::ptr() const = 0;
virtual bool isNull() const = 0;
virtual unsigned int size() const = 0;
virtual IfcUtil::ArgumentType type() const = 0;
virtual Argument* operator [] (unsigned int i) const = 0;
virtual std::string toString(bool upper=false) const = 0;
virtual bool isNull() const = 0;
virtual ~Argument() {};
};
+4
View File
@@ -33,6 +33,8 @@
#include <map>
#include <boost/dynamic_bitset.hpp>
#include "IfcUtil.h"
namespace IfcWrite {
@@ -68,6 +70,7 @@ namespace IfcWrite {
void setArgument(int i,int v);
void setArgument(int i,int v, const char* c);
void setArgument(int i,const std::string& v);
void setArgument(int i,const boost::dynamic_bitset<>& v);
void setArgument(int i,double v);
void setArgument(int i,IfcUtil::IfcBaseClass* v);
void setArgument(int i,IfcEntityList::ptr v);
@@ -75,6 +78,7 @@ namespace IfcWrite {
void setArgument(int i,const std::vector<double>& v);
void setArgument(int i,const std::vector<std::string>& v);
void setArgument(int i,const std::vector<int>& v);
void setArgument(int i,const std::vector< boost::dynamic_bitset<> >& v);
};
}
+65 -13
View File
@@ -158,19 +158,26 @@ void IfcWritableEntity::setArgument(int i, Argument* a) {
break;
case IfcUtil::Argument_STRING:
this->setArgument(i, static_cast<std::string>(*a));
break;
case IfcUtil::Argument_VECTOR_INT: {
break;
case IfcUtil::Argument_BINARY:
this->setArgument(i, static_cast< boost::dynamic_bitset<> >(*a));
break;
case IfcUtil::Argument_AGGREGATE_OF_INT: {
std::vector<int> attr_value = *a;
this->setArgument(i, attr_value); }
break;
case IfcUtil::Argument_VECTOR_DOUBLE: {
case IfcUtil::Argument_AGGREGATE_OF_DOUBLE: {
std::vector<double> attr_value = *a;
this->setArgument(i, attr_value); }
break;
case IfcUtil::Argument_VECTOR_STRING: {
case IfcUtil::Argument_AGGREGATE_OF_STRING: {
std::vector<std::string> attr_value = *a;
this->setArgument(i, attr_value); }
break;
case IfcUtil::Argument_AGGREGATE_OF_BINARY: {
std::vector< boost::dynamic_bitset<> > attr_value = *a;
this->setArgument(i, attr_value); }
break;
case IfcUtil::Argument_ENUMERATION: {
IfcSchema::Type::Enum ty = IfcSchema::Type::GetAttributeEntity(_type, i);
std::string enum_literal = a->toString();
@@ -178,19 +185,19 @@ void IfcWritableEntity::setArgument(int i, Argument* a) {
enum_literal = enum_literal.substr(1, enum_literal.size() - 2);
std::pair<const char*, int> enum_ref = IfcSchema::Type::GetEnumerationIndex(ty, enum_literal);
this->setArgument(i, enum_ref.second, enum_ref.first); }
break;
case IfcUtil::Argument_ENTITY: {
break;
case IfcUtil::Argument_ENTITY_INSTANCE: {
this->setArgument(i, static_cast<IfcUtil::IfcBaseClass*>(*a)); }
break;
case IfcUtil::Argument_ENTITY_LIST: {
break;
case IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE: {
IfcEntityList::ptr instances = *a;
IfcEntityList::ptr mapped_instances(new IfcEntityList);
for (IfcEntityList::it it = instances->begin(); it != instances->end(); ++it) {
mapped_instances->push(*it);
}
this->setArgument(i, mapped_instances); }
break;
case IfcUtil::Argument_ENTITY_LIST_LIST: {
break;
case IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE: {
IfcEntityListList::ptr instances = *a;
IfcEntityListList::ptr mapped_instances(new IfcEntityListList);
for (IfcEntityListList::outer_it it = instances->begin(); it != instances->end(); ++it) {
@@ -201,7 +208,8 @@ void IfcWritableEntity::setArgument(int i, Argument* a) {
mapped_instances->push(inner);
}
this->setArgument(i, mapped_instances); }
break;
break;
default:
case IfcUtil::Argument_UNKNOWN:
throw IfcParse::IfcException("Unknown argument encountered");
break;
@@ -224,6 +232,9 @@ void IfcWritableEntity::setArgument(int i,int v, const char* c){
void IfcWritableEntity::setArgument(int i,const std::string& v){
_setArgument(i, v);
}
void IfcWritableEntity::setArgument(int i,const boost::dynamic_bitset<>& v){
_setArgument(i, v);
}
void IfcWritableEntity::setArgument(int i,double v){
_setArgument(i, v);
}
@@ -257,6 +268,9 @@ void IfcWritableEntity::setArgument(int i,const std::vector<std::string>& v){
void IfcWritableEntity::setArgument(int i,const std::vector<int>& v){
_setArgument(i, v);
}
void IfcWritableEntity::setArgument(int i,const std::vector< boost::dynamic_bitset<> >& v){
_setArgument(i, v);
}
class SizeVisitor : public boost::static_visitor<int> {
public:
@@ -265,10 +279,12 @@ public:
int operator()(const int& i) const { return -1; }
int operator()(const bool& i) const { return -1; }
int operator()(const double& i) const { return -1; }
int operator()(const std::string& i) const { return i.size(); }
int operator()(const std::string& i) const { return -1; }
int operator()(const boost::dynamic_bitset<>& i) const { return -1; }
int operator()(const std::vector<int>& i) const { return i.size(); }
int operator()(const std::vector<double>& i) const { return i.size(); }
int operator()(const std::vector<std::string>& i) const { return i.size(); }
int operator()(const std::vector< boost::dynamic_bitset<> >& i) const { return i.size(); }
int operator()(const IfcWriteArgument::EnumerationReference& i) const { return -1; }
int operator()(const IfcUtil::IfcBaseClass* const& i) const { return -1; }
int operator()(const IfcEntityList::ptr& i) const { return i->size(); }
@@ -310,6 +326,27 @@ private:
}
return oss.str();
}
std::string format_binary(const boost::dynamic_bitset<>& b) {
std::ostringstream oss;
oss.imbue(std::locale::classic());
oss.put('"');
oss << std::hex << std::setw(1);
unsigned c = b.size();
unsigned n = c % 4;
oss << n;
for (unsigned i = 0; i < c + n;) {
unsigned accum = 0;
for (int j = 0; j < 4; ++j, ++i) {
unsigned bit = i < n ? 0 : b.test(c - i + n - 1) ? 1 : 0;
accum |= bit << (3-j);
}
oss << accum;
}
oss.put('"');
return oss.str();
}
bool upper;
public:
StringBuilderVisitor(std::ostringstream& stream, bool upper = false)
@@ -319,6 +356,7 @@ public:
void operator()(const int& i) { data << i; }
void operator()(const bool& i) { data << (i ? ".T." : ".F."); }
void operator()(const double& i) { data << format_double(i); }
void operator()(const boost::dynamic_bitset<>& i) { data << format_binary(i); }
void operator()(const std::string& i) {
std::string s = i;
if (upper) {
@@ -330,6 +368,7 @@ public:
void operator()(const std::vector<int>& i);
void operator()(const std::vector<double>& i);
void operator()(const std::vector<std::string>& i);
void operator()(const std::vector< boost::dynamic_bitset<> >& i);
void operator()(const IfcWriteArgument::EnumerationReference& i) {
data << "." << i.enumeration_value << ".";
}
@@ -390,9 +429,20 @@ void StringBuilderVisitor::serialize(const std::vector<double>& i) {
data << ")";
}
template <>
void StringBuilderVisitor::serialize(const std::vector< boost::dynamic_bitset<> >& i) {
data << "(";
for (std::vector< boost::dynamic_bitset<> >::const_iterator it = i.begin(); it != i.end(); ++it) {
if (it != i.begin()) data << ",";
data << format_binary(*it);
}
data << ")";
}
void StringBuilderVisitor::operator()(const std::vector<int>& i) { serialize(i); }
void StringBuilderVisitor::operator()(const std::vector<double>& i) { serialize(i); }
void StringBuilderVisitor::operator()(const std::vector<std::string>& i) { serialize(i); }
void StringBuilderVisitor::operator()(const std::vector< boost::dynamic_bitset<> >& i) { serialize(i); }
IfcWriteArgument::operator int() const { return as<int>(); }
@@ -404,10 +454,12 @@ IfcWriteArgument::operator std::string() const {
}
return as<std::string>();
}
IfcWriteArgument::operator IfcUtil::IfcBaseClass*() const { return as<IfcUtil::IfcBaseClass*>(); }
IfcWriteArgument::operator boost::dynamic_bitset<>() const { return as< boost::dynamic_bitset<> >(); }
IfcWriteArgument::operator std::vector<double>() const { return as<std::vector<double> >(); }
IfcWriteArgument::operator std::vector<int>() const { return as<std::vector<int> >(); }
IfcWriteArgument::operator std::vector<std::string>() const { return as<std::vector<std::string > >(); }
IfcWriteArgument::operator IfcUtil::IfcBaseClass*() const { return as<IfcUtil::IfcBaseClass*>(); }
IfcWriteArgument::operator std::vector< boost::dynamic_bitset<> >() const { return as< std::vector< boost::dynamic_bitset<> > >(); }
IfcWriteArgument::operator IfcEntityList::ptr() const { return as<IfcEntityList::ptr>(); }
IfcWriteArgument::operator IfcEntityListList::ptr() const { throw; }
bool IfcWriteArgument::isNull() const { return type() == IfcUtil::Argument_NULL; }
+31 -14
View File
@@ -30,6 +30,7 @@
#include <boost/variant.hpp>
#include <boost/optional.hpp>
#include <boost/dynamic_bitset.hpp>
#include "../ifcparse/IfcUtil.h"
#include "../ifcparse/IfcParse.h"
@@ -58,20 +59,18 @@ namespace IfcWrite {
boost::none_t,
// A derived argument, it will always serialize to *
Derived,
// An integer argument, e.g. 123
// An integer argument, e.g. 123
// SCALARS:
int,
// A boolean argument, it will serialize to either .T. or .F.
bool,
// A floating point argument, e.g. 12.3
double,
// A character string argument, e.g. 'IfcOpenShell'
std::string,
// A list of integers, e.g. (1,2,3)
std::vector<int>,
// A list of floats, e.g. (12.3,4.)
std::vector<double>,
// A list of strings, e.g. ('Ifc','Open','Shell')
std::vector<std::string>,
std::string,
// A binary argument, e.g. "092A" -> 100100101010
boost::dynamic_bitset<>,
// An enumeration argument, e.g. .USERDEFINED.
// To initialize the argument a string representation
// has to be explicitely passed of the enumeration value
@@ -83,11 +82,23 @@ namespace IfcWrite {
// e.g. #123 or datatype identifier for simple types, e.g.
// IFCREAL(12.3)
IfcUtil::IfcBaseClass*,
// An entity list argument. It will either serialize to
// AGGREGATES:
// An aggregate of integers, e.g. (1,2,3)
std::vector<int>,
// An aggregate of floats, e.g. (12.3,4.)
std::vector<double>,
// An aggregate of strings, e.g. ('Ifc','Open','Shell')
std::vector<std::string>,
// An aggregate of binaries, e.g. ("23B", "092A") -> (111011, 100100101010)
std::vector<boost::dynamic_bitset<> >,
// An aggregate of entity instances. It will either serialize to
// e.g. (#1,#2,#3) or datatype identifier for simple types,
// e.g. (IFCREAL(1.2),IFCINTEGER(3.))
IfcEntityList::ptr,
// A list of list of entities. E.g. ((#1, #2), (#3))
// AGGREGATES OF AGGREGATES:
// An aggregate of an aggregate of entities. E.g. ((#1, #2), (#3))
IfcEntityListList::ptr
> container;
public:
@@ -102,16 +113,22 @@ namespace IfcWrite {
template <typename T> void set(const T& t) {
container = t;
}
operator int() const;
operator bool() const;
operator double() const;
operator std::string() const;
operator std::vector<double>() const;
operator std::vector<int>() const;
operator std::vector<std::string>() const;
operator boost::dynamic_bitset<>() const;
operator IfcUtil::IfcBaseClass*() const;
operator std::vector<int>() const;
operator std::vector<double>() const;
operator std::vector<std::string>() const;
operator std::vector<boost::dynamic_bitset<> >() const;
operator IfcEntityList::ptr() const;
operator IfcEntityListList::ptr() const;
operator IfcEntityListList::ptr() const;
bool isNull() const;
Argument* operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
+21 -5
View File
@@ -130,7 +130,13 @@ namespace IfcUtil {
const std::string s = arg;
$result = PyString_FromString(s.c_str());
break; }
case IfcUtil::Argument_VECTOR_INT: {
case IfcUtil::Argument_BINARY: {
const boost::dynamic_bitset<> b = arg;
std::string bitstring;
boost::to_string(b, bitstring);
$result = PyString_FromString(bitstring.c_str());
break; }
case IfcUtil::Argument_AGGREGATE_OF_INT: {
const std::vector<int> v = arg;
const unsigned size = v.size();
$result = PyList_New(size);
@@ -138,7 +144,7 @@ namespace IfcUtil {
PyList_SetItem($result,i,PyInt_FromLong(v[i]));
}
break; }
case IfcUtil::Argument_VECTOR_DOUBLE: {
case IfcUtil::Argument_AGGREGATE_OF_DOUBLE: {
const std::vector<double> v = arg;
const unsigned size = v.size();
$result = PyList_New(size);
@@ -146,7 +152,7 @@ namespace IfcUtil {
PyList_SetItem($result,i,PyFloat_FromDouble(v[i]));
}
break; }
case IfcUtil::Argument_VECTOR_STRING: {
case IfcUtil::Argument_AGGREGATE_OF_STRING: {
const std::vector<std::string> v = arg;
const unsigned size = v.size();
$result = PyList_New(size);
@@ -154,11 +160,11 @@ namespace IfcUtil {
PyList_SetItem($result,i,PyString_FromString(v[i].c_str()));
}
break; }
case IfcUtil::Argument_ENTITY: {
case IfcUtil::Argument_ENTITY_INSTANCE: {
IfcUtil::IfcBaseClass* e = arg;
$result = SWIG_NewPointerObj(SWIG_as_voidptr(e), SWIGTYPE_p_IfcParse__IfcLateBoundEntity, 0);
break; }
case IfcUtil::Argument_ENTITY_LIST: {
case IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE: {
IfcEntityList::ptr es = arg;
const unsigned size = es->size();
$result = PyList_New(size);
@@ -167,6 +173,16 @@ namespace IfcUtil {
PyList_SetItem($result,i,o);
}
break; }
case IfcUtil::Argument_AGGREGATE_OF_BINARY: {
const std::vector< boost::dynamic_bitset<> > bs = arg;
const unsigned size = bs.size();
$result = PyList_New(size);
for (unsigned int i = 0; i < size; ++i) {
std::string bitstring;
boost::to_string(bs[i], bitstring);
PyList_SetItem($result,i,PyString_FromString(bitstring.c_str()));
}
break; }
case IfcUtil::Argument_UNKNOWN:
default:
SWIG_exception(SWIG_RuntimeError,"Unknown argument type");