Distinguish between nil and derived in validate.py

This commit is contained in:
Thomas Krijnen
2022-11-10 14:04:25 +01:00
parent 631722303f
commit ff2b79a41f
3 changed files with 66 additions and 3 deletions
+34
View File
@@ -54,7 +54,41 @@ private:
%rename("add") addEntity;
%rename("remove") removeEntity;
class attribute_value_derived {};
%{
class attribute_value_derived {};
%}
%extend attribute_value_derived {
%pythoncode %{
def __bool__(self): return False
def __repr__(self): return '*'
%}
}
%inline %{
static bool feature_use_attribute_value_derived = false;
void set_feature(const std::string& x, PyObject* v) {
if (PyBool_Check(v) && x == "use_attribute_value_derived") {
feature_use_attribute_value_derived = v == Py_True;
} else {
throw std::runtime_error("Invalid feature specification");
}
}
PyObject* get_feature(const std::string& x) {
if (x == "use_attribute_value_derived") {
return PyBool_FromLong(feature_use_attribute_value_derived);
} else {
throw std::runtime_error("Invalid feature specification");
}
}
%}
%{
static const std::string& helper_fn_declaration_get_name(const IfcParse::declaration* decl) {
return decl->name();
}
+8 -1
View File
@@ -38,9 +38,16 @@
try {
const Argument& arg = *($1.second);
const IfcUtil::ArgumentType type = $1.first;
if (arg.isNull() || type == IfcUtil::Argument_DERIVED) {
if (arg.isNull()) {
Py_INCREF(Py_None);
$result = Py_None;
} else if (type == IfcUtil::Argument_DERIVED) {
if (feature_use_attribute_value_derived) {
$result = SWIG_NewPointerObj(new attribute_value_derived, SWIGTYPE_p_attribute_value_derived, SWIG_POINTER_OWN);
} else {
Py_INCREF(Py_None);
$result = Py_None;
}
} else {
switch(type) {
case IfcUtil::Argument_INT: {