38bool HasAttrDirect(
PyObject* pyclass,
PyObject* pyname,
bool mustBeCPyCppyy =
false) {
67inline bool IsTemplatedSTLClass(
const std::string&
name,
const std::string& klass) {
69 auto pos =
name.find(klass);
70 return (pos == 0 || pos == 5) &&
name.find(
"::",
name.rfind(
">")) == std::string::npos;
78 PyObject*
result = PyObject_CallMethod(obj,
const_cast<char*
>(meth),
const_cast<char*
>(
""));
89 obj,
const_cast<char*
>(meth),
const_cast<char*
>(
"O"), arg1);
103 if (idx >=
size || (idx < 0 && idx < -
size)) {
104 PyErr_SetString(PyExc_IndexError,
"index out of range");
113 pyindex = PyLong_FromSsize_t(
size+idx);
122 if ((step > 0 && stop <= start) || (step < 0 && start <= stop))
125 if (start < 0)
start = 0;
126 if (start >= nlen)
start = nlen-1;
127 if (step >= nlen) step = nlen;
129 stop = step > 0 ? std::min(nlen, stop) : (stop >= 0 ? stop : -1);
164 PyErr_SetString(PyExc_TypeError,
"getattr(): attribute name must be string");
172 PyObject* val1 = PyObject_Str(self);
174 PyErr_Format(PyExc_AttributeError,
"%s has no attribute \'%s\'",
194 PyErr_SetString(PyExc_TypeError,
"getattr(): attribute name must be string");
209 PyErr_SetString(PyExc_TypeError,
"C++ object proxy expected");
220#if PY_VERSION_HEX < 0x03040000
221#define PyObject_LengthHint _PyObject_LengthHint
226 ItemGetter(
PyObject* pyobj) : fPyObject(pyobj) { Py_INCREF(fPyObject); }
227 virtual ~ItemGetter() { Py_DECREF(fPyObject); }
233struct CountedItemGetter :
public ItemGetter {
234 CountedItemGetter(
PyObject* pyobj) : ItemGetter(pyobj), fCur(0) {}
238struct TupleItemGetter :
public CountedItemGetter {
239 using CountedItemGetter::CountedItemGetter;
242 if (fCur < PyTuple_GET_SIZE(fPyObject)) {
243 PyObject* item = PyTuple_GET_ITEM(fPyObject, fCur++);
247 PyErr_SetString(PyExc_StopIteration,
"end of tuple");
252struct ListItemGetter :
public CountedItemGetter {
253 using CountedItemGetter::CountedItemGetter;
256 if (fCur < PyList_GET_SIZE(fPyObject)) {
257 PyObject* item = PyList_GET_ITEM(fPyObject, fCur++);
261 PyErr_SetString(PyExc_StopIteration,
"end of list");
266struct SequenceItemGetter :
public CountedItemGetter {
267 using CountedItemGetter::CountedItemGetter;
276 virtual PyObject* get() {
return PySequence_GetItem(fPyObject, fCur++); }
279struct IterItemGetter :
public ItemGetter {
280 using ItemGetter::ItemGetter;
282 virtual PyObject* get() {
return (*(
Py_TYPE(fPyObject)->tp_iternext))(fPyObject); }
285static ItemGetter* GetGetter(
PyObject* args)
288 ItemGetter* getter =
nullptr;
290 if (PyTuple_GET_SIZE(args) == 1) {
291 PyObject* fi = PyTuple_GET_ITEM(args, 0);
298 if (PyObject_CheckBuffer(fi))
301 if (PyTuple_CheckExact(fi))
302 getter =
new TupleItemGetter(fi);
303 else if (PyList_CheckExact(fi))
304 getter =
new ListItemGetter(fi);
305 else if (PySequence_Check(fi))
306 getter =
new SequenceItemGetter(fi);
308 PyObject* iter = PyObject_GetIter(fi);
310 getter =
new IterItemGetter{iter};
328 PyObject* res = PyObject_CallMethod(vecin, (
char*)
"reserve", (
char*)
"n", sz);
337 PyObject* fi = PySequence_GetItem(PyTuple_GET_ITEM(args, 0), 0);
338 if (!fi) PyErr_Clear();
339 if (fi && (PyTuple_CheckExact(fi) || PyList_CheckExact(fi))) {
341 PyObject* eb_call = PyObject_GetAttrString(vecin, (
char*)
"emplace_back");
343 bool value_is_vector =
false;
347 value_is_vector =
true;
354 for (
int i = 0; ; ++
i) {
357 if (value_is_vector && PySequence_Check(item)) {
358 eb_args = PyTuple_New(1);
359 PyTuple_SET_ITEM(eb_args, 0, item);
360 }
else if (PyTuple_CheckExact(item)) {
362 }
else if (PyList_CheckExact(item)) {
364 eb_args = PyTuple_New(isz);
366 PyObject* iarg = PyList_GET_ITEM(item, j);
368 PyTuple_SET_ITEM(eb_args, j, iarg);
373 PyErr_Format(PyExc_TypeError,
"argument %d is not a tuple or list",
i);
377 PyObject* ebres = PyObject_CallObject(eb_call, eb_args);
385 if (PyErr_Occurred()) {
386 if (!(PyErr_ExceptionMatches(PyExc_IndexError) ||
387 PyErr_ExceptionMatches(PyExc_StopIteration)))
389 else { PyErr_Clear(); }
398 PyObject* pb_call = PyObject_GetAttrString(vecin, (
char*)
"push_back");
403 PyObject* pbres = PyObject_CallFunctionObjArgs(pb_call, item,
nullptr);
411 if (PyErr_Occurred()) {
412 if (!(PyErr_ExceptionMatches(PyExc_IndexError) ||
413 PyErr_ExceptionMatches(PyExc_StopIteration)))
415 else { PyErr_Clear(); }
431 ItemGetter* getter = GetGetter(args);
434 bool fill_ok =
FillVector(self, args, getter);
446 if (PyTuple_GET_SIZE(args) == 1) {
447 PyObject* fi = PyTuple_GET_ITEM(args, 0);
458 if (!PyErr_Occurred())
459 PyErr_SetString(PyExc_TypeError,
"argument is not iterable");
472 ItemGetter* getter = GetGetter(args);
482 bool fill_ok =
FillVector(self, args, getter);
507 PyObject* pydata = CallPyObjMethod(self,
"__real_data");
517 long clen = PyInt_AsLong(pylen);
540 PyObject* pydata = VectorData(self,
nullptr);
550 if (!vi)
return nullptr;
564 vi->
vi_stride = PyLong_AsLong(pyvalue_size);
565 Py_DECREF(pyvalue_size);
588 if (value_type.back() !=
'*')
602 PyObject* pydata = CallPyObjMethod(
v,
"__real_data");
616 Py_XDECREF(pyvalue_type);
619 vi->
ii_len = PySequence_Size(
v);
621 PyObject_GC_Track(vi);
628 if (PySlice_Check(
index)) {
630 PyErr_SetString(PyExc_TypeError,
"unsubscriptable object");
635 PyObject* nseq = PyObject_CallObject(pyclass,
nullptr);
641 if (!AdjustSlice(nlen, start, stop, step))
648 CallPyObjMethod(nseq,
"push_back", item);
667 PyErr_Format(PyExc_TypeError,
668 "require object of type std::vector<bool>, but %s given",
674 PyErr_SetString(PyExc_TypeError,
"unsubscriptable object");
678 if (PySlice_Check(idx)) {
680 PyObject* nseq = PyObject_CallObject(pyclass,
nullptr);
685 if (!AdjustSlice(nlen, start, stop, step))
692 CallPyObjMethod(nseq,
"push_back", item);
704 int index = (
int)PyLong_AsLong(pyindex);
708 std::vector<bool>* vb = (std::vector<bool>*)self->GetObject();
711 if (
bool((*vb)[
index]))
721 PyErr_Format(PyExc_TypeError,
722 "require object of type std::vector<bool>, but %s given",
728 PyErr_SetString(PyExc_TypeError,
"unsubscriptable object");
732 int bval = 0;
PyObject* idx =
nullptr;
733 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"Oi:__setitem__"), &idx, &bval))
740 int index = (
int)PyLong_AsLong(pyindex);
744 std::vector<bool>* vb = (std::vector<bool>*)self->
GetObject();
760 if (args && PyTuple_GET_SIZE(args) == 1 && PySequence_Check(PyTuple_GET_ITEM(args, 0))) {
766 PyObject* items = PyTuple_GET_ITEM(args, 0);
768 if (PySequence_Size(self) != fillsz) {
769 PyErr_Format(PyExc_ValueError,
"received sequence of size %zd where %zd expected",
770 fillsz, PySequence_Size(self));
777 PyObject* item = PySequence_GetItem(items,
i);
779 PyObject* sires = PyObject_CallFunctionObjArgs(si_call,
index, item,
nullptr);
819 if (
pair && PySequence_Check(
pair) && PySequence_Size(
pair) == 2) {
822 sires = PyObject_CallFunctionObjArgs(si_call, key,
value,
nullptr);
830 if (!PyErr_Occurred())
831 PyErr_SetString(PyExc_TypeError,
"Failed to fill map (argument not a dict or sequence of pairs)");
849 if (PyTuple_GET_SIZE(args) == 1 && PyMapping_Check(PyTuple_GET_ITEM(args, 0)) && \
850 !(PyTuple_Check(PyTuple_GET_ITEM(args, 0)) || PyList_Check(PyTuple_GET_ITEM(args, 0)))) {
851 PyObject* assoc = PyTuple_GET_ITEM(args, 0);
852#if PY_VERSION_HEX < 0x03000000
854 PyObject* items = PyObject_CallMethod(assoc, (
char*)
"items",
nullptr);
857 PyObject* items = PyMapping_Items(assoc);
859 if (items && PySequence_Check(items)) {
872 if (PyTuple_GET_SIZE(args) == 1 && PySequence_Check(PyTuple_GET_ITEM(args, 0)))
873 return MapFromPairs(self, PyTuple_GET_ITEM(args, 0));
891 PyObject* iter = CallPyObjMethod(self,
"find", obj);
895 if (!PyObject_RichCompareBool(iter, end, Py_EQ)) {
918 if (PyTuple_GET_SIZE(args) == 1 && PySet_Check(PyTuple_GET_ITEM(args, 0))) {
919 PyObject* pyset = PyTuple_GET_ITEM(args, 0);
926 PyObject* iter = PyObject_GetIter(pyset);
928 PyObject* ins_call = PyObject_GetAttrString(self, (
char*)
"insert");
930 IterItemGetter getter{iter};
935 PyObject* insres = PyObject_CallFunctionObjArgs(ins_call, item,
nullptr);
964static const ptrdiff_t PS_END_ADDR = 7;
965static const ptrdiff_t PS_FLAG_ADDR = 11;
966static const ptrdiff_t PS_COLL_ADDR = 13;
988 PyErr_SetString(PyExc_TypeError,
"unrecognized iterator type for low level views");
1004 auto& dmc = ((
CPPInstance*)iter)->GetDatamemberCache();
1005 dmc.push_back(std::make_pair(PS_END_ADDR, end));
1008 Py_INCREF(Py_False);
1009 dmc.push_back(std::make_pair(PS_FLAG_ADDR, Py_False));
1013 dmc.push_back(std::make_pair(PS_COLL_ADDR, self));
1028 if (!ii)
return nullptr;
1033 ii->
ii_len = PySequence_Size(
c);
1035 PyObject_GC_Track(ii);
1073 long idx = PyLong_AsLong(pyindex);
1074 if (idx == -1 && PyErr_Occurred())
1078 PyErr_SetString(PyExc_TypeError,
"unsubscriptable object");
1084 else if ((
int)idx == 1)
1088 PyErr_SetString(PyExc_IndexError,
"out of bounds");
1094 return PyInt_FromLong(2);
1105 Py_DECREF(realInit);
1117#if PY_VERSION_HEX >= 0x03000000
1120 return !PyObject_RichCompareBool(one, other, Py_EQ);
1124PyObject* CPyCppyy_PyString_FromCppString(std::string* s,
bool native=
true) {
1131PyObject* CPyCppyy_PyString_FromCppString(std::wstring* s,
bool native=
true) {
1132 PyObject* pyobj = PyUnicode_FromWideChar(s->data(), s->size());
1133 if (pyobj && native) {
1134 PyObject* pybytes = PyUnicode_AsEncodedString(pyobj,
"UTF-8",
"strict");
1141#define CPPYY_IMPL_STRING_PYTHONIZATION(type, name) \
1143PyObject* name##StringGetData(PyObject* self, bool native=true) \
1145 if (CPyCppyy::CPPInstance_Check(self)) { \
1146 type* obj = ((type*)((CPPInstance*)self)->GetObject()); \
1147 if (obj) return CPyCppyy_PyString_FromCppString(obj, native); \
1149 PyErr_Format(PyExc_TypeError, "object mismatch (%s expected)", #type); \
1153PyObject* name##StringStr(PyObject* self) \
1155 PyObject* pyobj = name##StringGetData(self, false); \
1159 PyObject* pybytes = name##StringGetData(self, true); \
1161 pyobj = PyObject_Str(pybytes); \
1162 Py_DECREF(pybytes); \
1168PyObject* name##StringBytes(PyObject* self) \
1170 return name##StringGetData(self, true); \
1173PyObject* name##StringRepr(PyObject* self) \
1175 PyObject* data = name##StringGetData(self, true); \
1177 PyObject* repr = PyObject_Repr(data); \
1184PyObject* name##StringIsEqual(PyObject* self, PyObject* obj) \
1186 PyObject* data = name##StringGetData(self, PyBytes_Check(obj)); \
1188 PyObject* result = PyObject_RichCompare(data, obj, Py_EQ); \
1195PyObject* name##StringIsNotEqual(PyObject* self, PyObject* obj) \
1197 PyObject* data = name##StringGetData(self, PyBytes_Check(obj)); \
1199 PyObject* result = PyObject_RichCompare(data, obj, Py_NE); \
1207#define CPPYY_IMPL_STRING_PYTHONIZATION_CMP(type, name) \
1208CPPYY_IMPL_STRING_PYTHONIZATION(type, name) \
1209PyObject* name##StringCompare(PyObject* self, PyObject* obj) \
1211 PyObject* data = name##StringGetData(self, PyBytes_Check(obj)); \
1214 result = PyObject_Compare(data, obj); \
1217 if (PyErr_Occurred()) \
1219 return PyInt_FromLong(result); \
1225static inline std::string* GetSTLString(
CPPInstance* self) {
1227 PyErr_SetString(PyExc_TypeError,
"std::string object expected");
1231 std::string* obj = (std::string*)self->
GetObject();
1233 PyErr_SetString(PyExc_ReferenceError,
"attempt to access a null-pointer");
1240 std::string* obj = GetSTLString(self);
1244 char* keywords[] = {(
char*)
"encoding", (
char*)
"errors", (
char*)
nullptr};
1245 const char* encoding;
const char* errors;
1246 if (!PyArg_ParseTupleAndKeywords(args, kwds,
1247 const_cast<char*
>(
"s|s"), keywords, &encoding, &errors))
1250 return PyUnicode_Decode(obj->data(), obj->size(), encoding, errors);
1255 std::string* obj = GetSTLString(self);
1263 if (obj->find(needle) != std::string::npos) {
1272 std::string* obj = GetSTLString(self);
1282 PyObject* meth = PyObject_GetAttrString(pystr, (
char*)
"replace");
1289 PyObject* cppreplace = PyObject_GetAttrString((
PyObject*)self, (
char*)
"__cpp_replace");
1292 Py_DECREF(cppreplace);
1296 PyErr_SetString(PyExc_AttributeError,
"\'std::string\' object has no attribute \'replace\'");
1300#define CPYCPPYY_STRING_FINDMETHOD(name, cppname, pyname) \
1301PyObject* STLString##name(CPPInstance* self, PyObject* args, PyObject* ) \
1303 std::string* obj = GetSTLString(self); \
1307 PyObject* cppmeth = PyObject_GetAttrString((PyObject*)self, (char*)#cppname);\
1309 PyObject* result = PyObject_Call(cppmeth, args, nullptr); \
1310 Py_DECREF(cppmeth); \
1312 if (PyLongOrInt_AsULong64(result) == (PY_ULONG_LONG)std::string::npos) {\
1313 Py_DECREF(result); \
1314 return PyInt_FromLong(-1); \
1321 PyObject* pystr = CPyCppyy_PyText_FromStringAndSize(obj->data(), obj->size());\
1322 PyObject* pymeth = PyObject_GetAttrString(pystr, (char*)#pyname); \
1324 PyObject* result = PyObject_CallObject(pymeth, args); \
1325 Py_DECREF(pymeth); \
1336 std::string* obj = GetSTLString(self);
1354 PyObject* str_res = PyObject_Str(res);
1365 PyObject* str_res = PyObject_Str(res);
1390 PyObject *strbuf =
nullptr, *newArgs =
nullptr;
1391 if (PyTuple_GET_SIZE(args) == 1) {
1392 PyObject* arg0 = PyTuple_GET_ITEM(args, 0);
1393 if (PyUnicode_Check(arg0)) {
1395 strbuf = PyUnicode_AsEncodedString(arg0,
"UTF-8",
"strict");
1396 newArgs = PyTuple_New(1);
1398 PyTuple_SET_ITEM(newArgs, 0, strbuf);
1406 PyObject*
result = PyObject_Call(realInit, newArgs ? newArgs : args,
nullptr);
1408 Py_XDECREF(newArgs);
1409 Py_DECREF(realInit);
1413 if (
result && self && strbuf)
1427 bool mustIncrement =
true;
1430 auto& dmc = ((
CPPInstance*)self)->GetDatamemberCache();
1431 for (
auto& p: dmc) {
1432 if (p.first == PS_END_ADDR) {
1435 }
else if (p.first == PS_FLAG_ADDR) {
1436 mustIncrement = p.second == Py_True;
1437 if (!mustIncrement) {
1438 Py_DECREF(p.second);
1449 if (!PyObject_RichCompareBool(last, self, Py_EQ)) {
1450 bool iter_valid =
true;
1451 if (mustIncrement) {
1457 static PyObject* dummy = PyInt_FromLong(1l);
1460 iter_valid = iter && PyObject_RichCompareBool(last, self, Py_NE);
1466 if (!next) PyErr_Clear();
1472 if (!next) PyErr_SetString(PyExc_StopIteration,
"");
1478#define COMPLEX_METH_GETSET(name, cppname) \
1479static PyObject* name##ComplexGet(PyObject* self, void*) { \
1480 return PyObject_CallMethodNoArgs(self, cppname); \
1482static int name##ComplexSet(PyObject* self, PyObject* value, void*) { \
1483 PyObject* result = PyObject_CallMethodOneArg(self, cppname, value); \
1485 Py_DECREF(result); \
1490PyGetSetDef name##Complex{(char*)#name, (getter)name##ComplexGet, (setter)name##ComplexSet, nullptr, nullptr};
1497 if (!real)
return nullptr;
1498 double r = PyFloat_AsDouble(real);
1500 if (
r == -1. && PyErr_Occurred())
1504 if (!imag)
return nullptr;
1505 double i = PyFloat_AsDouble(imag);
1507 if (
i == -1. && PyErr_Occurred())
1510 return PyComplex_FromDoubles(
r,
i);
1515 if (!real)
return nullptr;
1516 double r = PyFloat_AsDouble(real);
1518 if (
r == -1. && PyErr_Occurred())
1522 if (!imag)
return nullptr;
1523 double i = PyFloat_AsDouble(imag);
1525 if (
i == -1. && PyErr_Occurred())
1528 std::ostringstream s;
1529 s <<
'(' <<
r <<
'+' <<
i <<
"j)";
1535 return PyFloat_FromDouble(((std::complex<double>*)self->
GetObject())->real());
1540 double d = PyFloat_AsDouble(
value);
1541 if (
d == -1.0 && PyErr_Occurred())
1543 ((std::complex<double>*)self->
GetObject())->real(
d);
1547PyGetSetDef ComplexDReal{(
char*)
"real", (getter)ComplexDRealGet, (setter)ComplexDRealSet,
nullptr,
nullptr};
1552 return PyFloat_FromDouble(((std::complex<double>*)self->
GetObject())->imag());
1557 double d = PyFloat_AsDouble(
value);
1558 if (
d == -1.0 && PyErr_Occurred())
1560 ((std::complex<double>*)self->
GetObject())->imag(
d);
1564PyGetSetDef ComplexDImag{(
char*)
"imag", (getter)ComplexDImagGet, (setter)ComplexDImagSet,
nullptr,
nullptr};
1568 double r = ((std::complex<double>*)self->
GetObject())->real();
1569 double i = ((std::complex<double>*)self->
GetObject())->imag();
1570 return PyComplex_FromDoubles(
r,
i);
1586 Py_INCREF(pyclass); PyTuple_SET_ITEM(args, 0, pyclass);
1587 Py_INCREF(pyname); PyTuple_SET_ITEM(args, 1, pyname);
1589 bool pstatus =
true;
1590 for (
auto pythonizor :
v) {
1625#if PY_VERSION_HEX >= 0x03000000
1626 const char* pybool_name =
"__bool__";
1628 const char* pybool_name =
"__nonzero__";
1637 if (!IsTemplatedSTLClass(
name,
"vector") &&
1638 !((PyTypeObject*)pyclass)->tp_iter) {
1649 if (resname.find(
"iterator") == std::string::npos)
1656 ((PyTypeObject*)pyclass)->tp_iter = (getiterfunc)STLSequenceIter;
1662 if (resolved.back() ==
'*' &&
Cppyy::IsBuiltin(resolved.substr(0, resolved.size()-1))) {
1663 ((PyTypeObject*)pyclass)->tp_iter = (getiterfunc)LLSequenceIter;
1669 if (!((PyTypeObject*)pyclass)->tp_iter &&
1675 ((PyTypeObject*)pyclass)->tp_iter = (getiterfunc)index_iter;
1737 std::string rname =
name;
1740 std::ostringstream initdef;
1741 initdef <<
"namespace __cppyy_internal {\n"
1742 <<
"void init_" << rname <<
"(" <<
name <<
"*& self";
1743 bool codegen_ok =
true;
1744 std::vector<std::string> arg_types, arg_names, arg_defaults;
1745 arg_types.reserve(ndata); arg_names.reserve(ndata); arg_defaults.reserve(ndata);
1755 if (res_clean ==
"internal_enum_type_t")
1758 if (res.rfind(
']') == std::string::npos && res.rfind(
')') == std::string::npos) {
1759 if (!cpd.empty()) arg_types.push_back(res_clean+cpd);
1760 else arg_types.push_back(
"const "+res_clean+
"&");
1763 arg_defaults.push_back(
"0");
1774 if (codegen_ok && !arg_types.empty()) {
1775 bool defaults_ok = arg_defaults.size() == arg_types.size();
1776 for (std::vector<std::string>::size_type
i = 0;
i < arg_types.size(); ++
i) {
1777 initdef <<
", " << arg_types[
i] <<
" " << arg_names[
i];
1778 if (defaults_ok) initdef <<
" = " << arg_defaults[
i];
1780 initdef <<
") {\n self = new " <<
name <<
"{";
1781 for (std::vector<std::string>::size_type
i = 0;
i < arg_names.size(); ++
i) {
1782 if (
i != 0) initdef <<
", ";
1783 initdef << arg_names[
i];
1785 initdef <<
"};\n} }";
1804 if (IsTemplatedSTLClass(
name,
"vector")) {
1808 if (klass->
fCppType == sVectorBoolTypeID) {
1814 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)VectorInit, METH_VARARGS | METH_KEYWORDS);
1836 ((PyTypeObject*)pyclass)->tp_iter = (getiterfunc)vector_iter;
1839 Utility::AddToClass(pyclass,
"__iadd__", (PyCFunction)VectorIAdd, METH_VARARGS | METH_KEYWORDS);
1843 if (vtype.rfind(
"value_type") == std::string::npos) {
1846 Py_DECREF(pyvalue_type);
1851 PyObject* pyvalue_size = PyLong_FromSsize_t(typesz);
1853 Py_DECREF(pyvalue_size);
1858 else if (IsTemplatedSTLClass(
name,
"array")) {
1861 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)ArrayInit, METH_VARARGS | METH_KEYWORDS);
1864 else if (IsTemplatedSTLClass(
name,
"map") || IsTemplatedSTLClass(
name,
"unordered_map")) {
1867 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)MapInit, METH_VARARGS | METH_KEYWORDS);
1872 else if (IsTemplatedSTLClass(
name,
"set")) {
1875 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)SetInit, METH_VARARGS | METH_KEYWORDS);
1880 else if (IsTemplatedSTLClass(
name,
"pair")) {
1885 if (IsTemplatedSTLClass(
name,
"shared_ptr") || IsTemplatedSTLClass(
name,
"unique_ptr")) {
1887 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)SmartPtrInit, METH_VARARGS | METH_KEYWORDS);
1890 else if (!((PyTypeObject*)pyclass)->tp_iter && \
1892 ((PyTypeObject*)pyclass)->tp_iternext = (iternextfunc)STLIterNext;
1894 ((PyTypeObject*)pyclass)->tp_iter = (getiterfunc)PyObject_SelfIter;
1898 else if (
name ==
"string" ||
name ==
"std::string") {
1906 Utility::AddToClass(pyclass,
"decode", (PyCFunction)STLStringDecode, METH_VARARGS | METH_KEYWORDS);
1908 Utility::AddToClass(pyclass,
"find", (PyCFunction)STLStringFind, METH_VARARGS | METH_KEYWORDS);
1910 Utility::AddToClass(pyclass,
"rfind", (PyCFunction)STLStringRFind, METH_VARARGS | METH_KEYWORDS);
1912 Utility::AddToClass(pyclass,
"replace", (PyCFunction)STLStringReplace, METH_VARARGS | METH_KEYWORDS);
1916 ((PyTypeObject*)pyclass)->tp_hash = (hashfunc)STLStringHash;
1919 else if (
name ==
"basic_string_view<char>" ||
name ==
"std::basic_string_view<char>") {
1921 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)StringViewInit, METH_VARARGS | METH_KEYWORDS);
1924 else if (
name ==
"basic_string<wchar_t,char_traits<wchar_t>,allocator<wchar_t> >" ||
name ==
"std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >") {
1933 else if (
name ==
"complex<double>" ||
name ==
"std::complex<double>") {
1935 PyObject_SetAttrString(pyclass,
"real", PyDescr_NewGetSet((PyTypeObject*)pyclass, &ComplexDReal));
1937 PyObject_SetAttrString(pyclass,
"imag", PyDescr_NewGetSet((PyTypeObject*)pyclass, &ComplexDImag));
1942 else if (IsTemplatedSTLClass(
name,
"complex")) {
1944 PyObject_SetAttrString(pyclass,
"real", PyDescr_NewGetSet((PyTypeObject*)pyclass, &realComplex));
1946 PyObject_SetAttrString(pyclass,
"imag", PyDescr_NewGetSet((PyTypeObject*)pyclass, &imagComplex));
1954 bool bUserOk =
true;
PyObject* res =
nullptr;
1958 bUserOk = (
bool)res;
1962 res = PyObject_CallFunctionObjArgs(func, pyclass, pyname,
nullptr);
1964 bUserOk = (
bool)res;
1978 bool pstatus =
true;
1980 if (!outer_scope.empty()) {
1984 name.substr(outer_scope.size()+2, std::string::npos).c_str());
#define PyInt_FromSsize_t
#define CPyCppyy_PyText_FromStringAndSize
#define CPyCppyy_PySliceCast
#define CPyCppyy_PyText_AsString
static PyObject * PyObject_CallMethodOneArg(PyObject *obj, PyObject *name, PyObject *arg)
#define PyBytes_FromStringAndSize
#define CPyCppyy_PyText_Type
static PyObject * PyObject_CallMethodNoArgs(PyObject *obj, PyObject *name)
#define CPyCppyy_PyText_FromString
#define CPyCppyy_PyText_Check
#define CPPYY_IMPL_STRING_PYTHONIZATION_CMP(type, name)
static bool run_pythonizors(PyObject *pyclass, PyObject *pyname, const std::vector< PyObject * > &v)
#define COMPLEX_METH_GETSET(name, cppname)
#define CPYCPPYY_STRING_FINDMETHOD(name, cppname, pyname)
#define PyObject_LengthHint
void FillVector(std::vector< double > &v, int size, T *a)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Cppyy::TCppType_t ObjectIsA(bool check_smart=true) const
Utility::PyOperators * fOperators
Cppyy::TCppType_t fCppType
void cppscope_to_legalname(std::string &cppscope)
std::string clean_type(const std::string &cppname, bool template_strip=true, bool const_strip=true)
std::string compound(const std::string &name)
std::string extract_namespace(const std::string &name)
Py_ssize_t GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, bool check=true)
bool AddToClass(PyObject *pyclass, const char *label, PyCFunction cfunc, int flags=METH_VARARGS)
PyTypeObject VectorIter_Type
static PyObject * GetAttrDirect(PyObject *pyclass, PyObject *pyname)
bool Pythonize(PyObject *pyclass, const std::string &name)
bool CPPOverload_Check(T *object)
std::map< std::string, std::vector< PyObject * > > gPythonizations
bool CPPScope_Check(T *object)
bool LowLevelView_Check(T *object)
bool CPPInstance_Check(T *object)
PyTypeObject IndexIter_Type
CPYCPPYY_EXTERN Converter * CreateConverter(const std::string &name, cdims_t=0)
std::set< std::string > gIteratorTypes
RPY_EXPORTED size_t SizeOf(TCppType_t klass)
RPY_EXPORTED bool IsDefaultConstructable(TCppType_t type)
RPY_EXPORTED bool IsEnum(const std::string &type_name)
RPY_EXPORTED std::vector< TCppIndex_t > GetMethodIndicesFromName(TCppScope_t scope, const std::string &name)
RPY_EXPORTED TCppIndex_t GetNumDatamembers(TCppScope_t scope, bool accept_namespace=false)
RPY_EXPORTED bool Compile(const std::string &code, bool silent=false)
RPY_EXPORTED std::string ResolveName(const std::string &cppitem_name)
RPY_EXPORTED bool IsAggregate(TCppType_t type)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED bool IsPublicData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED bool IsBuiltin(const std::string &type_name)
RPY_EXPORTED bool IsStaticData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED std::string GetDatamemberType(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED bool IsSmartPtr(TCppType_t type)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
RPY_EXPORTED std::string GetMethodResultType(TCppMethod_t)
RPY_EXPORTED std::string GetDatamemberName(TCppScope_t scope, TCppIndex_t idata)
PyObject_HEAD PyObject * ii_container
Cppyy::TCppType_t vi_klass
CPyCppyy::Converter * vi_converter