File indexing completed on 2026-09-12 09:25:09
0001 #ifndef CPYCPPYY_API_H
0002 #define CPYCPPYY_API_H
0003
0004
0005
0006
0007
0008
0009 #ifdef _WIN32
0010 #pragma warning (disable : 4275)
0011 #pragma warning (disable : 4251)
0012 #pragma warning (disable : 4800)
0013 #endif
0014 #if defined(linux)
0015 #include <stdio.h>
0016 #ifdef _POSIX_C_SOURCE
0017 #undef _POSIX_C_SOURCE
0018 #endif
0019 #ifdef _FILE_OFFSET_BITS
0020 #undef _FILE_OFFSET_BITS
0021 #endif
0022 #ifdef _XOPEN_SOURCE
0023 #undef _XOPEN_SOURCE
0024 #endif
0025 #endif
0026 #include "Python.h"
0027
0028 #define CPYCPPYY_VERSION_HEX 0x010c10
0029
0030
0031 namespace Cppyy {
0032 typedef size_t TCppScope_t;
0033 typedef TCppScope_t TCppType_t;
0034 typedef void* TCppEnum_t;
0035 typedef void* TCppObject_t;
0036 typedef intptr_t TCppMethod_t;
0037
0038 typedef size_t TCppIndex_t;
0039 typedef void* TCppFuncAddr_t;
0040 }
0041
0042
0043 #include "CPyCppyy/CommonDefs.h"
0044
0045
0046 #include <string>
0047 #include <vector>
0048
0049
0050 namespace CPyCppyy {
0051
0052
0053
0054 #ifndef CPYCPPYY_PARAMETER
0055 #define CPYCPPYY_PARAMETER
0056
0057 struct Parameter {
0058 union Value {
0059 bool fBool;
0060 int8_t fInt8;
0061 uint8_t fUInt8;
0062 short fShort;
0063 unsigned short fUShort;
0064 int fInt;
0065 unsigned int fUInt;
0066 long fLong;
0067 intptr_t fIntPtr;
0068 unsigned long fULong;
0069 long long fLLong;
0070 unsigned long long fULLong;
0071 int64_t fInt64;
0072 uint64_t fUInt64;
0073 float fFloat;
0074 double fDouble;
0075 long double fLDouble;
0076 void* fVoidp;
0077 } fValue;
0078 void* fRef;
0079 char fTypeCode;
0080 };
0081 #endif
0082
0083
0084 struct CallContext;
0085
0086
0087 #ifndef CPYCPPYY_DIMENSIONS_H
0088 #define CPYCPPYY_DIMENSIONS_H
0089 typedef Py_ssize_t dim_t;
0090
0091 class Dimensions {
0092 dim_t* fDims;
0093
0094 public:
0095 Dimensions(dim_t = 0, dim_t* = nullptr) : fDims(nullptr) {}
0096 ~Dimensions() { delete [] fDims; }
0097
0098 public:
0099 operator bool() const { return (bool)fDims; }
0100 };
0101
0102 typedef Dimensions dims_t;
0103 typedef const dims_t& cdims_t;
0104 #endif
0105
0106
0107 class CPYCPPYY_CLASS_EXTERN Converter {
0108 public:
0109 virtual ~Converter();
0110
0111
0112 virtual bool SetArg(PyObject*, Parameter&, CallContext* = nullptr) = 0;
0113
0114
0115 virtual PyObject* FromMemory(void* address);
0116
0117
0118 virtual bool ToMemory(PyObject* value, void* address, PyObject* ctxt = nullptr);
0119
0120
0121 virtual bool HasState() { return false; }
0122 };
0123
0124
0125 CPYCPPYY_EXTERN Converter* CreateConverter(const std::string& name, cdims_t = 0);
0126
0127
0128 CPYCPPYY_EXTERN void DestroyConverter(Converter* p);
0129
0130
0131 typedef Converter* (*ConverterFactory_t)(cdims_t);
0132 CPYCPPYY_EXTERN bool RegisterConverter(const std::string& name, ConverterFactory_t);
0133
0134
0135 CPYCPPYY_EXTERN bool RegisterConverterAlias(const std::string& name, const std::string& target);
0136
0137
0138 CPYCPPYY_EXTERN bool UnregisterConverter(const std::string& name);
0139
0140
0141
0142 class CPYCPPYY_CLASS_EXTERN Executor {
0143 public:
0144 virtual ~Executor();
0145
0146
0147 virtual PyObject* Execute(
0148 Cppyy::TCppMethod_t, Cppyy::TCppObject_t, CallContext*) = 0;
0149
0150
0151 virtual bool HasState() { return false; }
0152 };
0153
0154
0155 CPYCPPYY_EXTERN Executor* CreateExecutor(const std::string& name, cdims_t = 0);
0156
0157
0158 CPYCPPYY_EXTERN void DestroyConverter(Converter* p);
0159
0160
0161 typedef Executor* (*ExecutorFactory_t)(cdims_t);
0162 CPYCPPYY_EXTERN bool RegisterExecutor(const std::string& name, ExecutorFactory_t);
0163
0164
0165 CPYCPPYY_EXTERN bool RegisterExecutorAlias(const std::string& name, const std::string& target);
0166
0167
0168 CPYCPPYY_EXTERN bool UnregisterExecutor(const std::string& name);
0169
0170
0171 CPYCPPYY_EXTERN void* CallVoidP(Cppyy::TCppMethod_t, Cppyy::TCppObject_t, CallContext*);
0172
0173
0174
0175
0176
0177
0178 CPYCPPYY_EXTERN std::string Instance_GetScopedFinalName(PyObject* pyobject);
0179
0180
0181 CPYCPPYY_EXTERN void* Instance_AsVoidPtr(PyObject* pyobject);
0182
0183
0184 CPYCPPYY_EXTERN PyObject* Instance_FromVoidPtr(
0185 void* addr, const std::string& classname, bool python_owns = false);
0186
0187
0188 CPYCPPYY_EXTERN bool Scope_Check(PyObject* pyobject);
0189 CPYCPPYY_EXTERN bool Scope_CheckExact(PyObject* pyobject);
0190
0191
0192 CPYCPPYY_EXTERN bool Instance_Check(PyObject* pyobject);
0193 CPYCPPYY_EXTERN bool Instance_CheckExact(PyObject* pyobject);
0194
0195
0196 CPYCPPYY_EXTERN void Instance_SetPythonOwns(PyObject* pyobject);
0197 CPYCPPYY_EXTERN void Instance_SetCppOwns(PyObject* pyobject);
0198
0199
0200 CPYCPPYY_EXTERN bool Sequence_Check(PyObject* pyobject);
0201
0202
0203 CPYCPPYY_EXTERN bool Instance_IsLively(PyObject* pyobject);
0204
0205
0206 CPYCPPYY_EXTERN bool Overload_Check(PyObject* pyobject);
0207 CPYCPPYY_EXTERN bool Overload_CheckExact(PyObject* pyobject);
0208
0209
0210
0211
0212 CPYCPPYY_EXTERN void Instance_SetReduceMethod(PyCFunction reduceMethod);
0213
0214
0215
0216
0217
0218 CPYCPPYY_EXTERN bool Import(const std::string& name);
0219
0220
0221 CPYCPPYY_EXTERN bool Exec(const std::string& cmd);
0222
0223
0224 CPYCPPYY_EXTERN void ExecScript(const std::string& name, const std::vector<std::string>& args);
0225
0226
0227 CPYCPPYY_EXTERN void Prompt();
0228
0229 }
0230
0231 #endif