24inline PyMethodDef
method(
const char *pszMethodName,
25 PyCFunction pfnMethod,
27 const char *pszDoc =
nullptr) {
29 record.ml_name =
const_cast<char *
>(pszMethodName);
30 record.ml_meth = pfnMethod;
31 record.ml_flags = nFlags;
32 record.ml_doc =
const_cast<char *
>(pszDoc);
63 mRecords.push_back(
method(
nullptr,
nullptr, 0,
nullptr));
91 add(
const char *pszMethodName, PyCFunction pfnMethod,
const char *pszDoc =
"",
int nFlags = 1) {
92 if (mTable !=
nullptr) {
95 mRecords.insert(mRecords.end() - 1,
method(pszMethodName, pfnMethod, nFlags, pszDoc));
109 if (mTable ==
nullptr) {
110 int nCount =
static_cast<int>(mRecords.size());
111 mTable =
new PyMethodDef[nCount];
112 for (
int i = 0; i < nCount; ++i) {
113 mTable[i] = mRecords[i];
120 std::vector<PyMethodDef> mRecords;
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
PyMethodDef * table()
Flatten the records into an array the interpreter can retain.
Definition methodtable.h:108
MethodTable()
Start with the terminator record alone.
Definition methodtable.h:62
void add(const char *pszMethodName, PyCFunction pfnMethod, const char *pszDoc="", int nFlags=1)
Append one method ahead of the terminator.
Definition methodtable.h:91
virtual ~MethodTable()
Release the flattened table.
Definition methodtable.h:73
Exception for a binding rule broken at run time, mirroring Python's RuntimeError.
Definition runtimeerror.h:20
Configuration header of the PyCXX binding layer.
C++ wrappers for the embedded Python interpreter's objects, types, and extension modules.
Definition attributeerror.h:7
PyMethodDef method(const char *pszMethodName, PyCFunction pfnMethod, int nFlags=1, const char *pszDoc=nullptr)
Build a method record for MethodTable::add().
Definition methodtable.h:24