py3: Base: files R-Z ported to python3
issue 0000995
This commit is contained in:
@@ -142,9 +142,14 @@ QString UnitsApi::schemaTranslate(const Base::Quantity& quant, double &factor, Q
|
||||
|
||||
double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
|
||||
{
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyUnicode_Check(ArgObj)) {
|
||||
QString str = QString::fromUtf8(PyUnicode_AsUTF8(ArgObj));
|
||||
#else
|
||||
if (PyString_Check(ArgObj)) {
|
||||
// Parse the string
|
||||
QString str = QString::fromLatin1(PyString_AsString(ArgObj));
|
||||
#endif
|
||||
// Parse the string
|
||||
Quantity q = Quantity::parse(str);
|
||||
if (q.getUnit() == u)
|
||||
return q.getValue();
|
||||
@@ -153,8 +158,13 @@ double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
|
||||
else if (PyFloat_Check(ArgObj)) {
|
||||
return PyFloat_AsDouble(ArgObj);
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(ArgObj)) {
|
||||
return static_cast<double>(PyInt_AsLong(ArgObj));
|
||||
#else
|
||||
else if (PyLong_Check(ArgObj)) {
|
||||
return static_cast<double>(PyLong_AsLong(ArgObj));
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
throw Base::UnitsMismatchError("Wrong parameter type!");
|
||||
@@ -164,17 +174,27 @@ double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
|
||||
Quantity UnitsApi::toQuantity(PyObject *ArgObj, const Base::Unit &u)
|
||||
{
|
||||
double d;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyUnicode_Check(ArgObj)) {
|
||||
QString str = QString::fromUtf8(PyUnicode_AsUTF8(ArgObj));
|
||||
#else
|
||||
if (PyString_Check(ArgObj)) {
|
||||
// Parse the string
|
||||
QString str = QString::fromLatin1(PyString_AsString(ArgObj));
|
||||
#endif
|
||||
// Parse the string
|
||||
Quantity q = Quantity::parse(str);
|
||||
d = q.getValue();
|
||||
}
|
||||
else if (PyFloat_Check(ArgObj)) {
|
||||
d = PyFloat_AsDouble(ArgObj);
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(ArgObj)) {
|
||||
d = static_cast<double>(PyInt_AsLong(ArgObj));
|
||||
#else
|
||||
else if (PyLong_Check(ArgObj)) {
|
||||
d = static_cast<double>(PyLong_AsLong(ArgObj));
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
throw Base::UnitsMismatchError("Wrong parameter type!");
|
||||
|
||||
Reference in New Issue
Block a user