83 return (pos == 0 || pos == 5) &&
name.find(
"::",
name.rfind(
">")) == std::string::npos;
102 obj,
const_cast<char*
>(
meth),
const_cast<char*
>(
"O"),
arg1);
116 if (idx >=
size || (idx < 0 && idx < -
size)) {
135 if ((step > 0 && stop <= start) || (step < 0 && start <= stop))
138 if (start < 0) start = 0;
142 stop = step > 0 ? std::min(
nlen, stop) : (stop >= 0 ? stop : -1);
233#if PY_VERSION_HEX < 0x03040000
234#define PyObject_LengthHint _PyObject_LengthHint
246struct CountedItemGetter :
public ItemGetter {
251struct TupleItemGetter :
public CountedItemGetter {
252 using CountedItemGetter::CountedItemGetter;
265struct ListItemGetter :
public CountedItemGetter {
266 using CountedItemGetter::CountedItemGetter;
279struct SequenceItemGetter :
public CountedItemGetter {
280 using CountedItemGetter::CountedItemGetter;
292struct IterItemGetter :
public ItemGetter {
293 using ItemGetter::ItemGetter;
298static ItemGetter* GetGetter(
PyObject* args)
301 ItemGetter*
getter =
nullptr;
319 getter =
new SequenceItemGetter(
fi);
323 getter =
new IterItemGetter{iter};
345namespace __cppyy_internal {
352 ptr_iterator(T *c, T *e) : cur(c), end(e) {}
354 T &operator*() const { return *cur; }
355 ptr_iterator &operator++()
360 bool operator==(const ptr_iterator &other) const { return cur == other.cur; }
361 bool operator!=(const ptr_iterator &other) const { return !(*this == other); }
365ptr_iterator<T> make_iter(T *begin, T *end)
370} // namespace __cppyy_internal
372// Note: for const span<T>, T is const-qualified here
374auto __cppyy_internal_begin(T &s) noexcept
376 return __cppyy_internal::make_iter(s.data(), s.data() + s.size());
379// Note: for const span<T>, T is const-qualified here
381auto __cppyy_internal_end(T &s) noexcept
383 // end iterator = begin iterator with cur == end
384 return __cppyy_internal::make_iter(s.data() + s.size(), s.data() + s.size());
399 "'__cppyy_internal_begin' for std::span pythonization");
414 "'__cppyy_internal_end' for std::span pythonization");
472 for (
int i = 0; ; ++i) {
549 ItemGetter*
getter = GetGetter(args);
601 ItemGetter*
getter = GetGetter(args);
681 if (!
vi)
return nullptr;
683 vi->ii_container =
v;
687#if PY_VERSION_HEX >= 0x030e0000
722 vi->vi_converter =
nullptr;
724 if (value_type.back() !=
'*')
733 vi->vi_converter =
nullptr;
745 vi->vi_data =
nullptr;
747 vi->vi_converter =
nullptr;
765 if (!
self->GetObject()) {
804 "require object of type std::vector<bool>, but %s given",
809 if (!
self->GetObject()) {
844 std::vector<bool>*
vb = (std::vector<bool>*)
self->GetObject();
858 "require object of type std::vector<bool>, but %s given",
863 if (!
self->GetObject()) {
880 std::vector<bool>*
vb = (std::vector<bool>*)
self->GetObject();
988#if PY_VERSION_HEX < 0x03000000
1066 IterItemGetter
getter{iter};
1164 if (!
ii)
return nullptr;
1167 ii->ii_container =
c;
1220 else if ((
int)idx == 1)
1253#if PY_VERSION_HEX >= 0x03000000
1277#define CPPYY_IMPL_STRING_PYTHONIZATION(type, name) \
1279PyObject* name##StringGetData(PyObject* self, bool native=true) \
1281 if (CPyCppyy::CPPInstance_Check(self)) { \
1282 type* obj = ((type*)((CPPInstance*)self)->GetObject()); \
1283 if (obj) return CPyCppyy_PyString_FromCppString(*obj, native); \
1285 PyErr_Format(PyExc_TypeError, "object mismatch (%s expected)", #type); \
1289PyObject* name##StringStr(PyObject* self) \
1291 PyObject* pyobj = name##StringGetData(self, false); \
1295 PyObject* pybytes = name##StringGetData(self, true); \
1297 pyobj = PyObject_Str(pybytes); \
1298 Py_DECREF(pybytes); \
1304PyObject* name##StringBytes(PyObject* self) \
1306 return name##StringGetData(self, true); \
1309PyObject* name##StringRepr(PyObject* self) \
1311 PyObject* data = name##StringGetData(self, true); \
1313 PyObject* repr = PyObject_Repr(data); \
1320PyObject* name##StringIsEqual(PyObject* self, PyObject* obj) \
1322 PyObject* data = name##StringGetData(self, PyBytes_Check(obj)); \
1324 PyObject* result = PyObject_RichCompare(data, obj, Py_EQ); \
1331PyObject* name##StringIsNotEqual(PyObject* self, PyObject* obj) \
1333 PyObject* data = name##StringGetData(self, PyBytes_Check(obj)); \
1335 PyObject* result = PyObject_RichCompare(data, obj, Py_NE); \
1343#define CPPYY_IMPL_STRING_PYTHONIZATION_CMP(type, name) \
1344CPPYY_IMPL_STRING_PYTHONIZATION(type, name) \
1345PyObject* name##StringCompare(PyObject* self, PyObject* obj) \
1347 PyObject* data = name##StringGetData(self, PyBytes_Check(obj)); \
1350 result = PyObject_Compare(data, obj); \
1353 if (PyErr_Occurred()) \
1355 return PyInt_FromLong(result); \
1368 std::string* obj = (std::string*)
self->GetObject();
1381 char*
keywords[] = {(
char*)
"encoding", (
char*)
"errors", (
char*)
nullptr};
1382 const char* encoding =
nullptr;
const char*
errors =
nullptr;
1400 if (obj->find(
needle) != std::string::npos) {
1437#define CPYCPPYY_STRING_FINDMETHOD(name, cppname, pyname) \
1438PyObject* STLString##name(CPPInstance* self, PyObject* args, PyObject* ) \
1440 std::string* obj = GetSTLString(self); \
1444 PyObject* cppmeth = PyObject_GetAttrString((PyObject*)self, (char*)#cppname);\
1446 PyObject* result = PyObject_Call(cppmeth, args, nullptr); \
1447 Py_DECREF(cppmeth); \
1449 if (PyLongOrInt_AsULong64(result) == (PY_ULONG_LONG)std::string::npos) {\
1450 Py_DECREF(result); \
1451 return PyInt_FromLong(-1); \
1458 PyObject* pystr = CPyCppyy_PyText_FromStringAndSize(obj->data(), obj->size());\
1459 PyObject* pymeth = PyObject_GetAttrString(pystr, (char*)#pyname); \
1461 PyObject* result = PyObject_CallObject(pymeth, args); \
1462 Py_DECREF(pymeth); \
1568 for (
auto&
p:
dmc) {
1615#define COMPLEX_METH_GETSET(name, cppname) \
1616static PyObject* name##ComplexGet(PyObject* self, void*) { \
1617 return PyObject_CallMethodNoArgs(self, cppname); \
1619static int name##ComplexSet(PyObject* self, PyObject* value, void*) { \
1620 PyObject* result = PyObject_CallMethodOneArg(self, cppname, value); \
1622 Py_DECREF(result); \
1627PyGetSetDef name##Complex{(char*)#name, (getter)name##ComplexGet, (setter)name##ComplexSet, nullptr, nullptr};
1634 if (!
real)
return nullptr;
1641 if (!
imag)
return nullptr;
1652 if (!
real)
return nullptr;
1659 if (!
imag)
return nullptr;
1665 std::ostringstream s;
1666 s <<
'(' <<
r <<
'+' << i <<
"j)";
1680 ((std::complex<double>*)
self->GetObject())->
real(
d);
1697 ((std::complex<double>*)
self->GetObject())->
imag(
d);
1705 double r = ((std::complex<double>*)
self->GetObject())->
real();
1706 double i = ((std::complex<double>*)
self->GetObject())->
imag();
1762#if PY_VERSION_HEX >= 0x03000000
1781 if (
ol->HasMethods() &&
ol->fMethodInfo->fMethods.size() == 1) {
1814 if (
resname.find(
"iterator") == std::string::npos)
1896 name.compare(0, 6,
"tuple<", 6) != 0) {
1905 initdef <<
"namespace __cppyy_internal {\n"
1906 <<
"void init_" <<
rname <<
"(" <<
name <<
"*& self";
1919 if (
res_clean ==
"internal_enum_type_t")
1922 if (res.rfind(
']') == std::string::npos && res.rfind(
')') == std::string::npos) {
1924 else arg_types.push_back(
"const "+
res_clean+
"&");
1940 for (std::vector<std::string>::size_type i = 0; i < arg_types.size(); ++i) {
1945 for (std::vector<std::string>::size_type i = 0; i <
arg_names.size(); ++i) {
2022 if (
vtype.rfind(
"value_type") == std::string::npos) {
2077 else if (
name ==
"string" ||
name ==
"std::string") {
2098 else if (
name ==
"basic_string_view<char,char_traits<char> >" ||
name ==
"std::basic_string_view<char>") {
2113 else if (
name ==
"std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >"
2114 ||
name ==
"basic_string<wchar_t,char_traits<wchar_t>,allocator<wchar_t> >"
2115 ||
name ==
"std::basic_string<wchar_t,char_traits<wchar_t>,allocator<wchar_t> >"
2125 else if (
name ==
"complex<double>" ||
name ==
"std::complex<double>") {
#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
bool PyUnstable_Object_IsUniqueReferencedTemporary(PyObject *pyobject)
#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
std::ios_base::fmtflags fFlags
void FillVector(std::vector< double > &v, int size, T *a)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
const_iterator end() const
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
PyObject * GetScopeProxy(Cppyy::TCppScope_t)
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
const RequestId_t RETURN_TYPE
const FormatId_t AS_STRING
RPY_EXPORTED bool IsIntegerType(const std::string &type_name)
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 TCppScope_t gGlobalScope
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)