Skip to content

Commit 1ec1411

Browse files
committed
Introduce specific exception for out of range attribute indexing
1 parent 381f711 commit 1ec1411

10 files changed

Lines changed: 748 additions & 742 deletions

File tree

src/ifcexpressparser/header.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,17 @@ def write_inverse(attr):
9595
argument_start = argument_count - len(type.attributes)
9696

9797
argument_name_function_body_switch_stmt = " switch (i) {%s}"%("".join(['case %d: return "%s"; '%(i+argument_start, attr.name) for i, attr in enumerate(type.attributes)])) if len(type.attributes) else ""
98-
argument_name_function_body_tail = (" return %s::getArgumentName(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' throw IfcParse::IfcException("argument out of range"); '
98+
argument_name_function_body_tail = (" return %s::getArgumentName(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); '
9999

100100
argument_name_function_body = argument_name_function_body_switch_stmt + argument_name_function_body_tail
101101

102102
argument_type_function_body_switch_stmt = " switch (i) {%s}"%("".join(['case %d: return %s; '%(i+argument_start, mapping.make_argument_type(attr)) for i, attr in enumerate(type.attributes)])) if len(type.attributes) else ""
103-
argument_type_function_body_tail = (" return %s::getArgumentType(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' throw IfcParse::IfcException("argument out of range"); '
103+
argument_type_function_body_tail = (" return %s::getArgumentType(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); '
104104

105105
argument_type_function_body = argument_type_function_body_switch_stmt + argument_type_function_body_tail
106106

107107
argument_entity_function_body_switch_stmt = " switch (i) {%s}"%("".join(['case %d: return %s; '%(i+argument_start, mapping.make_argument_entity(attr)) for i, attr in enumerate(type.attributes)])) if len(type.attributes) else ""
108-
argument_entity_function_body_tail = (" return %s::getArgumentEntity(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' throw IfcParse::IfcException("argument out of range"); '
108+
argument_entity_function_body_tail = (" return %s::getArgumentEntity(i); "%type.supertypes[0]) if len(type.supertypes) == 1 else ' throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); '
109109

110110
argument_entity_function_body = argument_entity_function_body_switch_stmt + argument_entity_function_body_tail
111111

src/ifcexpressparser/templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ class %(name)s : public %(superclass)s {
338338
"""
339339

340340
simpletype_impl_comment = "// Function implementations for %(name)s"
341-
simpletype_impl_argument_type = "if (i == 0) { return %(attr_type)s; } else { throw IfcParse::IfcException(\"argument out of range\"); }"
341+
simpletype_impl_argument_type = "if (i == 0) { return %(attr_type)s; } else { throw IfcParse::IfcAttributeOutOfRangeException(\"Argument index out of range\"); }"
342342
simpletype_impl_argument = "return entity->getArgument(i);"
343343
simpletype_impl_is_with_supertype = "return v == Type::%(class_name)s || %(superclass)s::is(v);"
344344
simpletype_impl_is_without_supertype = "return v == %(class_name)s::Class();"

src/ifcparse/Ifc2x3.cpp

Lines changed: 117 additions & 117 deletions
Large diffs are not rendered by default.

src/ifcparse/Ifc2x3.h

Lines changed: 303 additions & 303 deletions
Large diffs are not rendered by default.

src/ifcparse/Ifc4.cpp

Lines changed: 126 additions & 126 deletions
Large diffs are not rendered by default.

src/ifcparse/Ifc4.h

Lines changed: 177 additions & 177 deletions
Large diffs are not rendered by default.

src/ifcparse/IfcEntityDescriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace IfcUtil {
8282
}
8383
const IfcArgumentDescriptor& get_argument(unsigned i) const {
8484
if (i < arguments.size()) return arguments[i];
85-
else throw IfcParse::IfcException("Argument out of range");
85+
else throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range");
8686
}
8787
public:
8888
IfcEntityDescriptor(IfcSchema::Type::Enum type, IfcEntityDescriptor* parent)

src/ifcparse/IfcException.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@
2626
namespace IfcParse {
2727
class IfcException : public std::exception {
2828
private:
29-
std::string error;
29+
std::string message;
3030
public:
31-
IfcException(std::string e);
32-
~IfcException () throw ();
33-
const char* what() const throw();
31+
IfcException(const std::string& m)
32+
: message(m) {}
33+
~IfcException () throw () {}
34+
const char* what() const throw() {
35+
return message.c_str();
36+
}
37+
};
38+
39+
class IfcAttributeOutOfRangeException : public IfcException {
40+
public:
41+
IfcAttributeOutOfRangeException(const std::string& e)
42+
: IfcException(e) {}
43+
~IfcAttributeOutOfRangeException () throw () {}
3444
};
3545
}
3646

src/ifcparse/IfcParse.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ unsigned int ArgumentList::size() const { return (unsigned int) list.size(); }
650650

651651
Argument* ArgumentList::operator [] (unsigned int i) const {
652652
if ( i >= list.size() ) {
653-
throw IfcException("Argument index out of range");
653+
throw IfcAttributeOutOfRangeException("Argument index out of range");
654654
}
655655
return list[i];
656656
}
@@ -951,7 +951,7 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* s) {
951951
} else {
952952
entity = IfcSchema::SchemaEntity(e);
953953
}
954-
} catch (IfcException ex) {
954+
} catch (const IfcException& ex) {
955955
currentId = 0;
956956
Logger::Message(Logger::LOG_ERROR,ex.what());
957957
continue;
@@ -971,7 +971,7 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* s) {
971971
Logger::Message(Logger::LOG_WARNING,ss.str());
972972
}
973973
byguid[guid] = ifc_root;
974-
} catch (IfcException ex) {
974+
} catch (const IfcException& ex) {
975975
Logger::Message(Logger::LOG_ERROR,ex.what());
976976
}
977977
}
@@ -1176,7 +1176,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity) {
11761176
Logger::Message(Logger::LOG_WARNING,ss.str());
11771177
}
11781178
byguid[guid] = ifc_root;
1179-
} catch (IfcException ex) {
1179+
} catch (const IfcException& ex) {
11801180
Logger::Message(Logger::LOG_ERROR,ex.what());
11811181
}
11821182
}
@@ -1230,7 +1230,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity) {
12301230
}
12311231
refs->push(entity);
12321232
}
1233-
} catch (IfcParse::IfcException&) {}
1233+
} catch (const IfcParse::IfcException&) {}
12341234
}
12351235

12361236
return entity;
@@ -1382,10 +1382,6 @@ IfcSchema::IfcRoot* IfcFile::entityByGuid(const std::string& guid) {
13821382
}
13831383
}
13841384

1385-
IfcException::IfcException(std::string e) { error = e; }
1386-
IfcException::~IfcException() throw () {}
1387-
const char* IfcException::what() const throw() { return error.c_str(); }
1388-
13891385
// FIXME: Test destructor to delete entity and arg allocations
13901386
IfcFile::~IfcFile() {
13911387
for( entity_by_id_t::const_iterator it = byid.begin(); it != byid.end(); ++ it ) {

src/ifcparse/IfcUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ IfcEntityList::ptr IfcEntityList::filtered(const std::set<IfcSchema::Type::Enum>
7171

7272
unsigned int IfcUtil::IfcBaseType::getArgumentCount() const { return 1; }
7373
Argument* IfcUtil::IfcBaseType::getArgument(unsigned int i) const { return entity->getArgument(i); }
74-
const char* IfcUtil::IfcBaseType::getArgumentName(unsigned int i) const { if (i == 0) { return "wrappedValue"; } else { throw IfcParse::IfcException("argument out of range"); } }
74+
const char* IfcUtil::IfcBaseType::getArgumentName(unsigned int i) const { if (i == 0) { return "wrappedValue"; } else { throw IfcParse::IfcAttributeOutOfRangeException("Argument index out of range"); } }
7575

7676
void Logger::SetOutput(std::ostream* l1, std::ostream* l2) {
7777
log1 = l1;

0 commit comments

Comments
 (0)