29 const std::string&
name, std::vector<PyCallable*>* overloads =
nullptr)
61 for (
auto clb : *overloads) pytmpl->
AdoptMethod(clb);
75 PyErr_SetString(PyExc_TypeError,
"enum values are read-only");
84 return PyType_Type.tp_alloc(meta, nitems);
92 for (
auto pyobj : *scope->
fImp.
fUsing) Py_DECREF(pyobj);
100 return PyType_Type.tp_dealloc((
PyObject*)scope);
121 std::string modname =
157 PyErr_SetString(PyExc_AttributeError,
158 "attribute \'__module__\' of 'cppyy.CPPScope\' objects is not writable");
181 const_cast<char*
>(
"<class cppyy.CPPInstance at %p>"), scope);
185 return PyType_Type.tp_repr((
PyObject*)scope);
234 const char* mp = strstr(subtype->tp_name,
"_meta");
252 if (3 <= PyTuple_GET_SIZE(args)) {
253 PyObject* dct = PyTuple_GET_ITEM(args, 2);
258 if (!PyErr_Occurred())
259 PyErr_Warn(PyExc_RuntimeWarning, (
char*)
"no python-side overrides supported");
265 if (PyObject_SetAttrString((
PyObject*)result,
"__cpp_cross__", bname) == -1)
291 result->fImp.fUsing =
nullptr;
295 if (PyErr_Occurred()) {
316 if (
name.size() >= 2 &&
name.compare(0, 2,
"__") == 0 &&
321 std::vector<Utility::PyError_t> errors;
338 const std::vector<Cppyy::TCppIndex_t> methods =
340 if (!methods.empty()) {
342 std::vector<PyCallable*> overloads;
343 for (
auto idx : methods) {
369 if (resolved != lookup) {
390 PyErr_Format(PyExc_TypeError,
"\'%s\' is not a known C++ template",
name.c_str());
404 PyObject* pymetabases = PyTuple_New(1);
407 PyTuple_SET_ITEM(pymetabases, 0, btype);
409 PyObject* args = Py_BuildValue((
char*)
"sO{}", (
name+
"_meta").c_str(), pymetabases);
410 Py_DECREF(pymetabases);
411 PyObject* pymeta = PyType_Type.tp_new(
Py_TYPE(&PyInt_Type), args,
nullptr);
417 Py_INCREF(&PyInt_Type);
418 PyTuple_SET_ITEM(pybases, 0, (
PyObject*)&PyInt_Type);
440 args = Py_BuildValue((
char*)
"sOO",
name.c_str(), pybases, dct);
443 attr = ((PyTypeObject*)pymeta)->tp_new((PyTypeObject*)pymeta, args,
nullptr);
451 Py_INCREF(&PyInt_Type);
456 PyErr_Format(PyExc_TypeError,
"\'%s\' is not a known C++ enum",
name.c_str());
466 attr = PyType_Type.tp_getattro(pyclass,
pyname);
468 PyType_Type.tp_setattro(pyclass,
pyname, attr);
480 for (
auto pyref : *klass->
fImp.
fUsing) Py_DECREF(pyref);
483 klass->
fImp.
fUsing =
new std::vector<PyObject*>;
486 for (
auto uid : uv) {
490 klass->
fImp.
fUsing->push_back(PyWeakref_NewRef(pyuscope,
nullptr));
493 PyType_Type.tp_setattro(pyclass, llname, pyuscope);
503 PyObject* pyuscope = PyWeakref_GetObject(pyref);
505 attr = PyObject_GetAttr(pyuscope,
pyname);
513 std::for_each(errors.begin(), errors.end(), Utility::PyError_t::Clear);
518 PyObject* sklass = PyObject_Str(pyclass);
551 return PyType_Type.tp_setattro(pyclass,
pyname, pyval);
565 using namespace Cppyy;
568 return PyList_New(0);
571 PyErr_SetString(PyExc_TypeError,
"C++ proxy scope expected");
579 std::set<std::string> cppnames;
583 for (
Py_ssize_t i = 0; i < PyList_GET_SIZE(dirlist); ++i)
587 dirlist = PyList_New(cppnames.size());
591 for (
const auto&
name : cppnames) {
599 {(
char*)
"__dir__", (PyCFunction)
meta_dir, METH_NOARGS,
nullptr},
600 {(
char*)
nullptr,
nullptr, 0,
nullptr}
606 {(
char*)
"__cpp_name__", (getter)
meta_getcppname,
nullptr,
nullptr,
nullptr},
608 {(
char*)
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
615 (
char*)
"cppyy.CPPScope",
633 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
634#
if PY_VERSION_HEX >= 0x03040000
635 | Py_TPFLAGS_TYPE_SUBCLASS
638 (
char*)
"CPyCppyy metatype (internal)",
663#
if PY_VERSION_HEX >= 0x02030000
666#
if PY_VERSION_HEX >= 0x02060000
669#
if PY_VERSION_HEX >= 0x03040000
#define CPyCppyy_PyText_InternFromString
#define CPyCppyy_PyText_AsString
#define CPyCppyy_PyText_GET_SIZE
#define CPyCppyy_PyText_AppendAndDel
#define CPyCppyy_PyText_FromFormat
#define CPyCppyy_PyText_AsStringChecked
#define CPyCppyy_PyText_CheckExact
#define CPyCppyy_PyText_FromString
#define PyVarObject_HEAD_INIT(type, size)
Utility::PyOperators * fOperators
union CPyCppyy::CPPScope::@204 fImp
Cppyy::TCppType_t fCppType
std::vector< PyObject * > * fUsing
CppToPyMap_t * fCppObjects
void AdoptTemplate(PyCallable *pc)
void AdoptMethod(PyCallable *pc)
void cppscope_to_pyscope(std::string &cppscope)
std::string clean_type(const std::string &cppname, bool template_strip=true, bool const_strip=true)
std::string extract_namespace(const std::string &name)
size_t FetchError(std::vector< PyError_t > &)
void SetDetailedException(std::vector< PyError_t > &errors, PyObject *topmsg, PyObject *defexc)
const std::string Compound(const std::string &name)
CPPOverload * CPPOverload_New(const std::string &name, std::vector< PyCallable * > &methods)
PyTypeObject CPPInstance_Type
static PyObject * add_template(PyObject *pyclass, const std::string &name, std::vector< PyCallable * > *overloads=nullptr)
std::map< Cppyy::TCppObject_t, PyObject * > CppToPyMap_t
Type object to hold class reference (this is only semantically a presentation of CPPScope instances,...
PyObject * GetScopeProxy(Cppyy::TCppScope_t)
static int meta_setmodule(CPPScope *scope, PyObject *value, void *)
static PyObject * meta_dir(CPPScope *klass)
static PyObject * meta_alloc(PyTypeObject *meta, Py_ssize_t nitems)
PyTypeObject TypedefPointerToClass_Type
bool InsertDispatcher(CPPScope *klass, PyObject *dct)
static int enum_setattro(PyObject *, PyObject *, PyObject *)
static PyObject * pt_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
bool CPPScope_Check(T *object)
bool TemplateProxy_CheckExact(T *object)
static int meta_setattro(PyObject *pyclass, PyObject *pyname, PyObject *pyval)
static PyObject * meta_getmodule(CPPScope *scope, void *)
CPPDataMember * CPPDataMember_New(Cppyy::TCppScope_t scope, Cppyy::TCppIndex_t idata)
static PyGetSetDef meta_getset[]
static void meta_dealloc(CPPScope *scope)
PyObject * CreateExcScopeProxy(PyObject *pyscope, PyObject *pyname, PyObject *parent)
PyObject * CreateScopeProxy(Cppyy::TCppScope_t)
bool CPPScope_CheckExact(T *object)
static PyMethodDef meta_methods[]
bool CPPDataMember_Check(T *object)
static PyObject * meta_getattro(PyObject *pyclass, PyObject *pyname)
static PyObject * meta_getcppname(CPPScope *scope, void *)
PyTypeObject CPPScope_Type
static PyObject * meta_repr(CPPScope *scope)
TemplateProxy * TemplateProxy_New(const std::string &cppname, const std::string &pyname, PyObject *pyclass)
RPY_EXPORTED std::vector< TCppIndex_t > GetMethodIndicesFromName(TCppScope_t scope, const std::string &name)
RPY_EXPORTED TCppIndex_t GetNumEnumData(TCppEnum_t)
RPY_EXPORTED bool GetSmartPtrInfo(const std::string &, TCppType_t *raw, TCppMethod_t *deref)
RPY_EXPORTED std::vector< TCppScope_t > GetUsingNamespaces(TCppScope_t)
RPY_EXPORTED std::string GetEnumDataName(TCppEnum_t, TCppIndex_t idata)
RPY_EXPORTED bool IsEnum(const std::string &type_name)
RPY_EXPORTED TCppIndex_t GetDatamemberIndex(TCppScope_t scope, const std::string &name)
RPY_EXPORTED TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED std::string GetFinalName(TCppType_t type)
RPY_EXPORTED long long GetEnumDataValue(TCppEnum_t, TCppIndex_t idata)
RPY_EXPORTED bool IsSubtype(TCppType_t derived, TCppType_t base)
RPY_EXPORTED std::string ResolveName(const std::string &cppitem_name)
RPY_EXPORTED std::string GetBaseName(TCppType_t type, TCppIndex_t ibase)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED bool IsNamespace(TCppScope_t scope)
RPY_EXPORTED void GetAllCppNames(TCppScope_t scope, std::set< std::string > &cppnames)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
RPY_EXPORTED bool ExistsMethodTemplate(TCppScope_t scope, const std::string &name)
RPY_EXPORTED TCppScope_t gGlobalScope
RPY_EXPORTED TCppEnum_t GetEnum(TCppScope_t scope, const std::string &enum_name)
PyObject_HEAD Cppyy::TCppType_t fType