22 code <<
" " << retType <<
" " << mtCppName <<
"(";
26 std::vector<std::string> argtypes; argtypes.reserve(nArgs);
29 if (i != 0) code <<
", ";
30 code << argtypes.back() <<
" arg" << i;
40#if PY_VERSION_HEX < 0x03000000
41 code <<
" PyObject* mtPyName = PyString_FromString(\"" << mtCppName <<
"\");\n"
43 code <<
" PyObject* mtPyName = PyUnicode_FromString(\"" << mtCppName <<
"\");\n"
45 " PyObject* pyresult = PyObject_CallMethodObjArgs((PyObject*)m_self, mtPyName";
47 code <<
", pyargs[" << i <<
"]";
48 code <<
", NULL);\n Py_DECREF(mtPyName);\n";
60 PyErr_Format(PyExc_TypeError,
66 PyErr_Format(PyExc_TypeError,
79 static int counter = 0;
80 std::ostringstream osname;
81 osname <<
"Dispatcher" << ++counter;
82 const std::string& derivedName = osname.str();
85 std::ostringstream code;
88 code <<
"namespace __cppyy_internal {\n"
89 <<
"class " << derivedName <<
" : public ::" << baseNameScoped <<
" {\n"
90 " CPyCppyy::DispatchPtr m_self;\n"
94 code <<
" virtual ~" << derivedName <<
"() {}\n";
100 for (
Py_ssize_t i = 0; i < PyList_GET_SIZE(items); ++i) {
101 PyObject* value = PyTuple_GET_ITEM(PyList_GET_ITEM(items, i), 1);
102 if (PyCallable_Check(value))
103 PyDict_SetItem(clbs, PyTuple_GET_ITEM(PyList_GET_ITEM(items, i), 0), value);
111 std::vector<std::string> protected_names;
114 bool has_default =
false;
115 bool has_cctor =
false;
116 bool has_constructors =
false;
122 has_constructors =
true;
126 else if (!has_cctor && nreq == 1) {
136 int contains = PyDict_Contains(dct, key);
137 if (contains == -1) PyErr_Clear();
143 protected_names.push_back(mtCppName);
144 code <<
" using " << baseName <<
"::" << mtCppName <<
";\n";
152 if (PyDict_DelItem(clbs, key) != 0)
158 if (PyDict_Size(clbs)) {
160 for (
size_t ibase = 0; ibase < nbases; ++ibase) {
165 for (
Py_ssize_t i = 0; i < PyList_GET_SIZE(keys); ++i) {
167 PyObject* key = PyList_GET_ITEM(keys, i);
173 if (PyDict_DelItem(clbs, key) != 0) PyErr_Clear();
182 code <<
" using " << baseName <<
"::" << baseName <<
";\n";
187 if (has_default || !has_constructors)
188 code <<
" " << derivedName <<
"() {}\n";
189 if (has_default || has_cctor || !has_constructors) {
190 code <<
" " << derivedName <<
"(const " << derivedName <<
"& other) : ";
192 code << baseName <<
"(other), ";
193 code <<
"m_self(other.m_self, this) {}\n";
200 if (nData) code <<
"public:\n";
204 code <<
" using " << baseName <<
"::" << protected_names.back() <<
";\n";
210 <<
"static size_t _dispatchptr_offset() { return (size_t)&(("
211 << derivedName <<
"*)(0x0))->m_self; }";
223 if (!disp)
return false;
234 for (
const auto&
name : protected_names) {
236 PyObject* pyf = PyMapping_GetItemString(disp_dct, (
char*)
name.c_str());
238 PyObject_SetAttrString((
PyObject*)klass, (
char*)
name.c_str(), pyf);
244 Py_XDECREF(disp_proxy);
#define CPyCppyy_PyText_AsString
#define CPyCppyy_PyText_FromString
static void InjectMethod(Cppyy::TCppMethod_t method, const std::string &mtCppName, std::ostringstream &code)
Cppyy::TCppType_t fCppType
std::string template_base(const std::string &cppname)
std::string clean_type(const std::string &cppname, bool template_strip=true, bool const_strip=true)
void ConstructCallbackPreamble(const std::string &retType, const std::vector< std::string > &argtypes, std::ostringstream &code)
void ConstructCallbackReturn(const std::string &retType, int nArgs, std::ostringstream &code)
const std::string Compound(const std::string &name)
bool InsertDispatcher(CPPScope *klass, PyObject *dct)
PyObject * CreateScopeProxy(Cppyy::TCppScope_t)
RPY_EXPORTED std::vector< TCppIndex_t > GetMethodIndicesFromName(TCppScope_t scope, const std::string &name)
RPY_EXPORTED bool Compile(const std::string &code)
RPY_EXPORTED bool IsProtectedMethod(TCppMethod_t method)
RPY_EXPORTED bool IsProtectedData(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED std::string GetDatamemberName(TCppScope_t scope, TCppIndex_t idata)
RPY_EXPORTED bool IsConstructor(TCppMethod_t method)
RPY_EXPORTED TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED std::string GetFinalName(TCppType_t type)
RPY_EXPORTED bool IsPublicMethod(TCppMethod_t method)
RPY_EXPORTED TCppIndex_t GetMethodReqArgs(TCppMethod_t)
RPY_EXPORTED std::string GetMethodName(TCppMethod_t)
RPY_EXPORTED TCppIndex_t GetNumBases(TCppType_t type)
RPY_EXPORTED bool IsConstMethod(TCppMethod_t)
RPY_EXPORTED std::string GetBaseName(TCppType_t type, TCppIndex_t ibase)
RPY_EXPORTED TCppIndex_t GetMethodNumArgs(TCppMethod_t)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED bool IsNamespace(TCppScope_t scope)
RPY_EXPORTED TCppIndex_t GetNumDatamembers(TCppScope_t scope)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
RPY_EXPORTED std::string GetMethodResultType(TCppMethod_t)
RPY_EXPORTED bool HasVirtualDestructor(TCppType_t type)
RPY_EXPORTED std::string GetMethodArgType(TCppMethod_t, TCppIndex_t iarg)
RPY_EXPORTED TCppIndex_t GetNumMethods(TCppScope_t scope)