py2cpp::pyResult(result) = fn(v);
CPPUNIT_ASSERT(std::vector<double>({2.1, 3.2, 4.3, 5.4}) == result);
+
+ auto tup = std::make_tuple(4, 4.2);
+ py2cpp::PyPtr pyTup = py2cpp::toPyPtr(tup);
+ py2cpp::fromPyPtr(pyTup, result);
+ CPPUNIT_ASSERT(std::vector<double>({4, 4.2}) == result);
}
void ConversionTest::listTest()
py2cpp::pyResult(result) = fn(v);
CPPUNIT_ASSERT(std::list<double>({2.1, 3.2, 4.3, 5.4}) == result);
+
+ auto tup = std::make_tuple(4, 4.2);
+ py2cpp::PyPtr pyTup = py2cpp::toPyPtr(tup);
+ py2cpp::fromPyPtr(pyTup, result);
+ CPPUNIT_ASSERT(std::list<double>({4, 4.2}) == result);
}
void ConversionTest::pyobjTest()
if(!check)
check.addError("std::vector", obj);
}
+ else if(PyTuple_Check(obj))
+ {
+ result.clear();
+ std::size_t size = PyTuple_Size(obj);
+ result.resize(size);
+ for(std::size_t i=0; i < size && check; i++)
+ check.addError(fromPy(PyTuple_GetItem(obj, i), result[i]));
+ if(!check)
+ check.addError("std::vector", obj);
+ }
else
check.addError("std::vector", obj);
return check;
++i;
}
}
+ else if(PyTuple_Check(obj))
+ {
+ result.clear();
+ std::size_t size = PyTuple_Size(obj);
+ result.resize(size); //result will have "size" default constructed elements.
+ std::size_t i = 0;
+ for(T& it : result)
+ {
+ check.addError(fromPy(PyTuple_GetItem(obj, i), it));
+ if(!check)
+ {
+ check.addError("std::list", obj);
+ break;
+ }
+ ++i;
+ }
+ }
else
check.addError("std::list", obj);
return check;