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);
533 PyObject* pydata = VectorData(self,
nullptr);
535 PyObject* newarr = PyObject_Call(arrcall, args, kwargs);
545 if (!vi)
return nullptr;
559 vi->
vi_stride = PyLong_AsLong(pyvalue_size);
560 Py_DECREF(pyvalue_size);
583 if (value_type.back() !=
'*')
597 PyObject* pydata = CallPyObjMethod(
v,
"__real_data");
611 Py_XDECREF(pyvalue_type);
614 vi->
ii_len = PySequence_Size(
v);
616 PyObject_GC_Track(vi);
623 if (PySlice_Check(
index)) {
625 PyErr_SetString(PyExc_TypeError,
"unsubscriptable object");
630 PyObject* nseq = PyObject_CallObject(pyclass,
nullptr);
636 if (!AdjustSlice(nlen, start, stop, step))
640 for (
Py_ssize_t i = start; i*sign < stop*sign; i += step) {
643 CallPyObjMethod(nseq,
"push_back", item);
662 PyErr_Format(PyExc_TypeError,
663 "require object of type std::vector<bool>, but %s given",
669 PyErr_SetString(PyExc_TypeError,
"unsubscriptable object");
673 if (PySlice_Check(idx)) {
675 PyObject* nseq = PyObject_CallObject(pyclass,
nullptr);
680 if (!AdjustSlice(nlen, start, stop, step))
684 for (
Py_ssize_t i = start; i*sign < stop*sign; i += step) {
687 CallPyObjMethod(nseq,
"push_back", item);
699 int index = (
int)PyLong_AsLong(pyindex);
703 std::vector<bool>* vb = (std::vector<bool>*)self->
GetObject();
706 if (
bool((*vb)[
index]))
716 PyErr_Format(PyExc_TypeError,
717 "require object of type std::vector<bool>, but %s given",
723 PyErr_SetString(PyExc_TypeError,
"unsubscriptable object");
727 int bval = 0;
PyObject* idx =
nullptr;
728 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"Oi:__setitem__"), &idx, &bval))
735 int index = (
int)PyLong_AsLong(pyindex);
739 std::vector<bool>* vb = (std::vector<bool>*)self->
GetObject();
755 if (args && PyTuple_GET_SIZE(args) == 1 && PySequence_Check(PyTuple_GET_ITEM(args, 0))) {
761 PyObject* items = PyTuple_GET_ITEM(args, 0);
763 if (PySequence_Size(self) != fillsz) {
764 PyErr_Format(PyExc_ValueError,
"received sequence of size %zd where %zd expected",
765 fillsz, PySequence_Size(self));
772 PyObject* item = PySequence_GetItem(items, i);
774 PyObject* sires = PyObject_CallFunctionObjArgs(si_call,
index, item,
nullptr);
811 for (
Py_ssize_t i = 0; i < PySequence_Size(pairs); ++i) {
812 PyObject* pair = PySequence_GetItem(pairs, i);
814 if (pair && PySequence_Check(pair) && PySequence_Size(pair) == 2) {
815 PyObject* key = PySequence_GetItem(pair, 0);
817 sires = PyObject_CallFunctionObjArgs(si_call, key,
value,
nullptr);
825 if (!PyErr_Occurred())
826 PyErr_SetString(PyExc_TypeError,
"Failed to fill map (argument not a dict or sequence of pairs)");
844 if (PyTuple_GET_SIZE(args) == 1 && PyMapping_Check(PyTuple_GET_ITEM(args, 0)) && \
845 !(PyTuple_Check(PyTuple_GET_ITEM(args, 0)) || PyList_Check(PyTuple_GET_ITEM(args, 0)))) {
846 PyObject* assoc = PyTuple_GET_ITEM(args, 0);
847#if PY_VERSION_HEX < 0x03000000
849 PyObject* items = PyObject_CallMethod(assoc, (
char*)
"items",
nullptr);
852 PyObject* items = PyMapping_Items(assoc);
854 if (items && PySequence_Check(items)) {
867 if (PyTuple_GET_SIZE(args) == 1 && PySequence_Check(PyTuple_GET_ITEM(args, 0)))
868 return MapFromPairs(self, PyTuple_GET_ITEM(args, 0));
886 PyObject* iter = CallPyObjMethod(self,
"find", obj);
890 if (!PyObject_RichCompareBool(iter, end, Py_EQ)) {
913 if (PyTuple_GET_SIZE(args) == 1 && PySet_Check(PyTuple_GET_ITEM(args, 0))) {
914 PyObject* pyset = PyTuple_GET_ITEM(args, 0);
921 PyObject* iter = PyObject_GetIter(pyset);
923 PyObject* ins_call = PyObject_GetAttrString(self, (
char*)
"insert");
925 IterItemGetter getter{iter};
930 PyObject* insres = PyObject_CallFunctionObjArgs(ins_call, item,
nullptr);
959static const ptrdiff_t PS_END_ADDR = 7;
960static const ptrdiff_t PS_FLAG_ADDR = 11;
961static const ptrdiff_t PS_COLL_ADDR = 13;
983 PyErr_SetString(PyExc_TypeError,
"unrecognized iterator type for low level views");
999 auto& dmc = ((
CPPInstance*)iter)->GetDatamemberCache();
1000 dmc.push_back(std::make_pair(PS_END_ADDR, end));
1003 Py_INCREF(Py_False);
1004 dmc.push_back(std::make_pair(PS_FLAG_ADDR, Py_False));
1008 dmc.push_back(std::make_pair(PS_COLL_ADDR, self));
1023 if (!ii)
return nullptr;
1028 ii->
ii_len = PySequence_Size(
c);
1030 PyObject_GC_Track(ii);
1068 long idx = PyLong_AsLong(pyindex);
1069 if (idx == -1 && PyErr_Occurred())
1073 PyErr_SetString(PyExc_TypeError,
"unsubscriptable object");
1079 else if ((
int)idx == 1)
1083 PyErr_SetString(PyExc_IndexError,
"out of bounds");
1089 return PyInt_FromLong(2);
1100 Py_DECREF(realInit);
1112#if PY_VERSION_HEX >= 0x03000000
1115 return !PyObject_RichCompareBool(one, other, Py_EQ);
1119PyObject* CPyCppyy_PyString_FromCppString(std::string* s,
bool native=
true) {
1126PyObject* CPyCppyy_PyString_FromCppString(std::wstring* s,
bool native=
true) {
1127 PyObject* pyobj = PyUnicode_FromWideChar(s->data(), s->size());
1128 if (pyobj && native) {
1129 PyObject* pybytes = PyUnicode_AsEncodedString(pyobj,
"UTF-8",
"strict");
1136#define CPPYY_IMPL_STRING_PYTHONIZATION(type, name) \
1138PyObject* name##StringGetData(PyObject* self, bool native=true) \
1140 if (CPyCppyy::CPPInstance_Check(self)) { \
1141 type* obj = ((type*)((CPPInstance*)self)->GetObject()); \
1142 if (obj) return CPyCppyy_PyString_FromCppString(obj, native); \
1144 PyErr_Format(PyExc_TypeError, "object mismatch (%s expected)", #type); \
1148PyObject* name##StringStr(PyObject* self) \
1150 PyObject* pyobj = name##StringGetData(self, false); \
1154 PyObject* pybytes = name##StringGetData(self, true); \
1156 pyobj = PyObject_Str(pybytes); \
1157 Py_DECREF(pybytes); \
1163PyObject* name##StringBytes(PyObject* self) \
1165 return name##StringGetData(self, true); \
1168PyObject* name##StringRepr(PyObject* self) \
1170 PyObject* data = name##StringGetData(self, true); \
1172 PyObject* repr = PyObject_Repr(data); \
1179PyObject* name##StringIsEqual(PyObject* self, PyObject* obj) \
1181 PyObject* data = name##StringGetData(self, PyBytes_Check(obj)); \
1183 PyObject* result = PyObject_RichCompare(data, obj, Py_EQ); \
1190PyObject* name##StringIsNotEqual(PyObject* self, PyObject* obj) \
1192 PyObject* data = name##StringGetData(self, PyBytes_Check(obj)); \
1194 PyObject* result = PyObject_RichCompare(data, obj, Py_NE); \
1202#define CPPYY_IMPL_STRING_PYTHONIZATION_CMP(type, name) \
1203CPPYY_IMPL_STRING_PYTHONIZATION(type, name) \
1204PyObject* name##StringCompare(PyObject* self, PyObject* obj) \
1206 PyObject* data = name##StringGetData(self, PyBytes_Check(obj)); \
1209 result = PyObject_Compare(data, obj); \
1212 if (PyErr_Occurred()) \
1214 return PyInt_FromLong(result); \
1220static inline std::string* GetSTLString(
CPPInstance* self) {
1222 PyErr_SetString(PyExc_TypeError,
"std::string object expected");
1226 std::string* obj = (std::string*)self->
GetObject();
1228 PyErr_SetString(PyExc_ReferenceError,
"attempt to access a null-pointer");
1235 std::string* obj = GetSTLString(self);
1239 char* keywords[] = {(
char*)
"encoding", (
char*)
"errors", (
char*)
nullptr};
1240 const char* encoding =
nullptr;
const char* errors =
nullptr;
1241 if (!PyArg_ParseTupleAndKeywords(args, kwds,
1242 const_cast<char*
>(
"s|s"), keywords, &encoding, &errors))
1245 return PyUnicode_Decode(obj->data(), obj->size(), encoding, errors);
1250 std::string* obj = GetSTLString(self);
1258 if (obj->find(needle) != std::string::npos) {
1267 std::string* obj = GetSTLString(self);
1277 PyObject* meth = PyObject_GetAttrString(pystr, (
char*)
"replace");
1284 PyObject* cppreplace = PyObject_GetAttrString((
PyObject*)self, (
char*)
"__cpp_replace");
1287 Py_DECREF(cppreplace);
1291 PyErr_SetString(PyExc_AttributeError,
"\'std::string\' object has no attribute \'replace\'");
1295#define CPYCPPYY_STRING_FINDMETHOD(name, cppname, pyname) \
1296PyObject* STLString##name(CPPInstance* self, PyObject* args, PyObject* ) \
1298 std::string* obj = GetSTLString(self); \
1302 PyObject* cppmeth = PyObject_GetAttrString((PyObject*)self, (char*)#cppname);\
1304 PyObject* result = PyObject_Call(cppmeth, args, nullptr); \
1305 Py_DECREF(cppmeth); \
1307 if (PyLongOrInt_AsULong64(result) == (PY_ULONG_LONG)std::string::npos) {\
1308 Py_DECREF(result); \
1309 return PyInt_FromLong(-1); \
1316 PyObject* pystr = CPyCppyy_PyText_FromStringAndSize(obj->data(), obj->size());\
1317 PyObject* pymeth = PyObject_GetAttrString(pystr, (char*)#pyname); \
1319 PyObject* result = PyObject_CallObject(pymeth, args); \
1320 Py_DECREF(pymeth); \
1331 std::string* obj = GetSTLString(self);
1349 PyObject* str_res = PyObject_Str(res);
1360 PyObject* str_res = PyObject_Str(res);
1385 PyObject *strbuf =
nullptr, *newArgs =
nullptr;
1386 if (PyTuple_GET_SIZE(args) == 1) {
1387 PyObject* arg0 = PyTuple_GET_ITEM(args, 0);
1388 if (PyUnicode_Check(arg0)) {
1390 strbuf = PyUnicode_AsEncodedString(arg0,
"UTF-8",
"strict");
1391 newArgs = PyTuple_New(1);
1393 PyTuple_SET_ITEM(newArgs, 0, strbuf);
1401 PyObject*
result = PyObject_Call(realInit, newArgs ? newArgs : args, nullptr);
1403 Py_XDECREF(newArgs);
1404 Py_DECREF(realInit);
1408 if (
result && self && strbuf)
1422 bool mustIncrement =
true;
1425 auto& dmc = ((
CPPInstance*)self)->GetDatamemberCache();
1426 for (
auto&
p: dmc) {
1427 if (
p.first == PS_END_ADDR) {
1430 }
else if (
p.first == PS_FLAG_ADDR) {
1431 mustIncrement =
p.second == Py_True;
1432 if (!mustIncrement) {
1433 Py_DECREF(
p.second);
1444 if (!PyObject_RichCompareBool(last, self, Py_EQ)) {
1445 bool iter_valid =
true;
1446 if (mustIncrement) {
1452 static PyObject* dummy = PyInt_FromLong(1l);
1455 iter_valid = iter && PyObject_RichCompareBool(last, self, Py_NE);
1461 if (!next) PyErr_Clear();
1467 if (!next) PyErr_SetString(PyExc_StopIteration,
"");
1473#define COMPLEX_METH_GETSET(name, cppname) \
1474static PyObject* name##ComplexGet(PyObject* self, void*) { \
1475 return PyObject_CallMethodNoArgs(self, cppname); \
1477static int name##ComplexSet(PyObject* self, PyObject* value, void*) { \
1478 PyObject* result = PyObject_CallMethodOneArg(self, cppname, value); \
1480 Py_DECREF(result); \
1485PyGetSetDef name##Complex{(char*)#name, (getter)name##ComplexGet, (setter)name##ComplexSet, nullptr, nullptr};
1492 if (!real)
return nullptr;
1493 double r = PyFloat_AsDouble(real);
1495 if (
r == -1. && PyErr_Occurred())
1499 if (!imag)
return nullptr;
1500 double i = PyFloat_AsDouble(imag);
1502 if (i == -1. && PyErr_Occurred())
1505 return PyComplex_FromDoubles(
r, i);
1510 if (!real)
return nullptr;
1511 double r = PyFloat_AsDouble(real);
1513 if (
r == -1. && PyErr_Occurred())
1517 if (!imag)
return nullptr;
1518 double i = PyFloat_AsDouble(imag);
1520 if (i == -1. && PyErr_Occurred())
1523 std::ostringstream s;
1524 s <<
'(' <<
r <<
'+' << i <<
"j)";
1530 return PyFloat_FromDouble(((std::complex<double>*)self->
GetObject())->real());
1535 double d = PyFloat_AsDouble(
value);
1536 if (
d == -1.0 && PyErr_Occurred())
1538 ((std::complex<double>*)self->
GetObject())->real(
d);
1542PyGetSetDef ComplexDReal{(
char*)
"real", (getter)ComplexDRealGet, (setter)ComplexDRealSet,
nullptr,
nullptr};
1547 return PyFloat_FromDouble(((std::complex<double>*)self->
GetObject())->imag());
1552 double d = PyFloat_AsDouble(
value);
1553 if (
d == -1.0 && PyErr_Occurred())
1555 ((std::complex<double>*)self->
GetObject())->imag(
d);
1559PyGetSetDef ComplexDImag{(
char*)
"imag", (getter)ComplexDImagGet, (setter)ComplexDImagSet,
nullptr,
nullptr};
1563 double r = ((std::complex<double>*)self->
GetObject())->real();
1564 double i = ((std::complex<double>*)self->
GetObject())->imag();
1565 return PyComplex_FromDoubles(
r, i);
1581 Py_INCREF(pyclass); PyTuple_SET_ITEM(args, 0, pyclass);
1582 Py_INCREF(pyname); PyTuple_SET_ITEM(args, 1, pyname);
1584 bool pstatus =
true;
1585 for (
auto pythonizor :
v) {
1620#if PY_VERSION_HEX >= 0x03000000
1621 const char* pybool_name =
"__bool__";
1623 const char* pybool_name =
"__nonzero__";
1632 if (!IsTemplatedSTLClass(
name,
"vector") &&
1633 !((PyTypeObject*)pyclass)->tp_iter) {
1644 if (resname.find(
"iterator") == std::string::npos)
1651 ((PyTypeObject*)pyclass)->tp_iter = (getiterfunc)STLSequenceIter;
1657 if (resolved.back() ==
'*' &&
Cppyy::IsBuiltin(resolved.substr(0, resolved.size()-1))) {
1658 ((PyTypeObject*)pyclass)->tp_iter = (getiterfunc)LLSequenceIter;
1664 if (!((PyTypeObject*)pyclass)->tp_iter &&
1670 ((PyTypeObject*)pyclass)->tp_iter = (getiterfunc)index_iter;
1726 name.compare(0, 6,
"tuple<", 6) != 0) {
1731 std::string rname =
name;
1734 std::ostringstream initdef;
1735 initdef <<
"namespace __cppyy_internal {\n"
1736 <<
"void init_" << rname <<
"(" <<
name <<
"*& self";
1737 bool codegen_ok =
true;
1738 std::vector<std::string> arg_types, arg_names, arg_defaults;
1739 arg_types.reserve(ndata); arg_names.reserve(ndata); arg_defaults.reserve(ndata);
1749 if (res_clean ==
"internal_enum_type_t")
1752 if (res.rfind(
']') == std::string::npos && res.rfind(
')') == std::string::npos) {
1753 if (!cpd.empty()) arg_types.push_back(res_clean+cpd);
1754 else arg_types.push_back(
"const "+res_clean+
"&");
1757 arg_defaults.push_back(
"0");
1768 if (codegen_ok && !arg_types.empty()) {
1769 bool defaults_ok = arg_defaults.size() == arg_types.size();
1770 for (std::vector<std::string>::size_type i = 0; i < arg_types.size(); ++i) {
1771 initdef <<
", " << arg_types[i] <<
" " << arg_names[i];
1772 if (defaults_ok) initdef <<
" = " << arg_defaults[i];
1774 initdef <<
") {\n self = new " <<
name <<
"{";
1775 for (std::vector<std::string>::size_type i = 0; i < arg_names.size(); ++i) {
1776 if (i != 0) initdef <<
", ";
1777 initdef << arg_names[i];
1779 initdef <<
"};\n} }";
1797 if (IsTemplatedSTLClass(
name,
"vector")) {
1801 if (klass->
fCppType == sVectorBoolTypeID) {
1807 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)VectorInit, METH_VARARGS | METH_KEYWORDS);
1814 Utility::AddToClass(pyclass,
"__array__", (PyCFunction)VectorArray, METH_VARARGS | METH_KEYWORDS );
1823 ((PyTypeObject*)pyclass)->tp_iter = (getiterfunc)vector_iter;
1826 Utility::AddToClass(pyclass,
"__iadd__", (PyCFunction)VectorIAdd, METH_VARARGS | METH_KEYWORDS);
1830 if (vtype.rfind(
"value_type") == std::string::npos) {
1833 Py_DECREF(pyvalue_type);
1838 PyObject* pyvalue_size = PyLong_FromSsize_t(typesz);
1840 Py_DECREF(pyvalue_size);
1845 else if (IsTemplatedSTLClass(
name,
"array")) {
1848 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)ArrayInit, METH_VARARGS | METH_KEYWORDS);
1851 else if (IsTemplatedSTLClass(
name,
"map") || IsTemplatedSTLClass(
name,
"unordered_map")) {
1854 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)MapInit, METH_VARARGS | METH_KEYWORDS);
1859 else if (IsTemplatedSTLClass(
name,
"set")) {
1862 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)SetInit, METH_VARARGS | METH_KEYWORDS);
1867 else if (IsTemplatedSTLClass(
name,
"pair")) {
1872 if (IsTemplatedSTLClass(
name,
"shared_ptr") || IsTemplatedSTLClass(
name,
"unique_ptr")) {
1874 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)SmartPtrInit, METH_VARARGS | METH_KEYWORDS);
1877 else if (!((PyTypeObject*)pyclass)->tp_iter && \
1879 ((PyTypeObject*)pyclass)->tp_iternext = (iternextfunc)STLIterNext;
1881 ((PyTypeObject*)pyclass)->tp_iter = (getiterfunc)PyObject_SelfIter;
1885 else if (
name ==
"string" ||
name ==
"std::string") {
1893 Utility::AddToClass(pyclass,
"decode", (PyCFunction)STLStringDecode, METH_VARARGS | METH_KEYWORDS);
1895 Utility::AddToClass(pyclass,
"find", (PyCFunction)STLStringFind, METH_VARARGS | METH_KEYWORDS);
1897 Utility::AddToClass(pyclass,
"rfind", (PyCFunction)STLStringRFind, METH_VARARGS | METH_KEYWORDS);
1899 Utility::AddToClass(pyclass,
"replace", (PyCFunction)STLStringReplace, METH_VARARGS | METH_KEYWORDS);
1903 ((PyTypeObject*)pyclass)->tp_hash = (hashfunc)STLStringHash;
1906 else if (
name ==
"basic_string_view<char>" ||
name ==
"std::basic_string_view<char>") {
1908 Utility::AddToClass(pyclass,
"__init__", (PyCFunction)StringViewInit, METH_VARARGS | METH_KEYWORDS);
1911 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> >") {
1920 else if (
name ==
"complex<double>" ||
name ==
"std::complex<double>") {
1922 PyObject_SetAttrString(pyclass,
"real", PyDescr_NewGetSet((PyTypeObject*)pyclass, &ComplexDReal));
1924 PyObject_SetAttrString(pyclass,
"imag", PyDescr_NewGetSet((PyTypeObject*)pyclass, &ComplexDImag));
1929 else if (IsTemplatedSTLClass(
name,
"complex")) {
1931 PyObject_SetAttrString(pyclass,
"real", PyDescr_NewGetSet((PyTypeObject*)pyclass, &realComplex));
1933 PyObject_SetAttrString(pyclass,
"imag", PyDescr_NewGetSet((PyTypeObject*)pyclass, &imagComplex));
1941 bool bUserOk =
true;
PyObject* res =
nullptr;
1945 bUserOk = (
bool)res;
1949 res = PyObject_CallFunctionObjArgs(func, pyclass, pyname,
nullptr);
1951 bUserOk = (
bool)res;
1965 bool pstatus =
true;
1968 if (!outer_scope.empty()) {
1969 auto p = pyzMap.find(outer_scope);
1970 if (
p != pyzMap.end()) {
1972 name.substr(outer_scope.size()+2, std::string::npos).c_str());
1979 auto p = pyzMap.find(
"");
1980 if (
p != pyzMap.end())
#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
winID h TVirtualViewer3D TVirtualGLPainter p
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 * > > & pythonizations()
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