mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-14 11:24:19 +00:00
logical handling in python and small fixes
This commit is contained in:
@@ -123,6 +123,7 @@
|
||||
PyObject* pythonize(const int& t) { return PyInt_FromLong(t); }
|
||||
PyObject* pythonize(const unsigned int& t) { return PyInt_FromLong(t); }
|
||||
PyObject* pythonize(const bool& t) { return PyBool_FromLong(t); }
|
||||
PyObject* pythonize(const boost::logic::tribool& t) { return boost::logic::indeterminate(t) ? PyUnicode_FromString("UNKNOWN") : PyBool_FromLong((bool)t) ;}
|
||||
PyObject* pythonize(const double& t) { return PyFloat_FromDouble(t); }
|
||||
PyObject* pythonize(const std::string& t) { return PyUnicode_FromString(t.c_str()); }
|
||||
PyObject* pythonize(const IfcUtil::IfcBaseClass* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcUtil__IfcBaseClass, 0); }
|
||||
|
||||
@@ -241,6 +241,28 @@ CREATE_VECTOR_TYPEMAP_IN(std::string, STRING, str)
|
||||
$1 = check_aggregate_of_aggregate_of_type($input, get_python_type<double>());
|
||||
}
|
||||
|
||||
%typemap(in) boost::logic::tribool {
|
||||
if (PyBool_Check($input)) {
|
||||
$1 = $input == Py_True;
|
||||
} else if (PyUnicode_Check($input)) {
|
||||
// we already checked the value of the string in the typecheck typemap
|
||||
$1 = boost::logic::indeterminate;
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "Logical needs boolean or \"UNKOWN\"");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) boost::logic::tribool {
|
||||
$1 = PyBool_Check($input);
|
||||
if (!$1 && PyUnicode_Check($input)) {
|
||||
PyObject * ascii = PyUnicode_AsEncodedString(result, "UTF-8", "strict");
|
||||
if (ascii) {
|
||||
$1 = strcmp(PyBytes_AS_STRING(ascii), "UNKNOWN") == 0;
|
||||
Py_DECREF(ascii);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%define CREATE_OPTIONAL_TYPEMAP_IN(template_type, express_name, python_name)
|
||||
|
||||
%typemap(in) const boost::optional<template_type>& {
|
||||
|
||||
@@ -51,6 +51,10 @@
|
||||
bool v = arg;
|
||||
$result = pythonize(v);
|
||||
break; }
|
||||
case IfcUtil::Argument_LOGICAL: {
|
||||
boost::logic::tribool v = arg;
|
||||
$result = pythonize(v);
|
||||
break; }
|
||||
case IfcUtil::Argument_DOUBLE: {
|
||||
double v = arg;
|
||||
$result = pythonize(v);
|
||||
|
||||
Reference in New Issue
Block a user