File indexing completed on 2025-01-30 10:21:53
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/PyResult.h"
0044 #include "CPyCppyy/CommonDefs.h"
0045
0046
0047 #include <string>
0048 #include <vector>
0049
0050
0051 namespace CPyCppyy {
0052
0053
0054
0055 #ifndef CPYCPPYY_PARAMETER
0056 #define CPYCPPYY_PARAMETER
0057
0058 struct Parameter {
0059 union Value {
0060 bool fBool;
0061 int8_t fInt8;
0062 uint8_t fUInt8;
0063 short fShort;
0064 unsigned short fUShort;
0065 int fInt;
0066 unsigned int fUInt;
0067 long fLong;
0068 intptr_t fIntPtr;
0069 unsigned long fULong;
0070 long long fLLong;
0071 unsigned long long fULLong;
0072 int64_t fInt64;
0073 uint64_t fUInt64;
0074 float fFloat;
0075 double fDouble;
0076 long double fLDouble;
0077 void* fVoidp;
0078 } fValue;
0079 void* fRef;
0080 char fTypeCode;
0081 };
0082 #endif
0083
0084
0085 struct CallContext;
0086
0087
0088 #ifndef CPYCPPYY_DIMENSIONS_H
0089 #define CPYCPPYY_DIMENSIONS_H
0090 typedef Py_ssize_t dim_t;
0091
0092 class Dimensions {
0093 dim_t* fDims;
0094
0095 public:
0096 Dimensions(dim_t = 0, dim_t* = nullptr) : fDims(nullptr) {}
0097 ~Dimensions() { delete [] fDims; }
0098
0099 public:
0100 operator bool() const { return (bool)fDims; }
0101 };
0102
0103 typedef Dimensions dims_t;
0104 typedef const dims_t& cdims_t;
0105 #endif
0106
0107
0108 class CPYCPPYY_CLASS_EXTERN Converter {
0109 public:
0110 virtual ~Converter();
0111
0112
0113 virtual bool SetArg(PyObject*, Parameter&, CallContext* = nullptr) = 0;
0114
0115
0116 virtual PyObject* FromMemory(void* address);
0117
0118
0119 virtual bool ToMemory(PyObject* value, void* address, PyObject* ctxt = nullptr);
0120
0121
0122 virtual bool HasState() { return false; }
0123 };
0124
0125
0126 CPYCPPYY_EXTERN Converter* CreateConverter(const std::string& name, cdims_t = 0);
0127
0128
0129 CPYCPPYY_EXTERN void DestroyConverter(Converter* p);
0130
0131
0132 typedef Converter* (*ConverterFactory_t)(cdims_t);
0133 CPYCPPYY_EXTERN bool RegisterConverter(const std::string& name, ConverterFactory_t);
0134
0135
0136 CPYCPPYY_EXTERN bool RegisterConverterAlias(const std::string& name, const std::string& target);
0137
0138
0139 CPYCPPYY_EXTERN bool UnregisterConverter(const std::string& name);
0140
0141
0142
0143 class CPYCPPYY_CLASS_EXTERN Executor {
0144 public:
0145 virtual ~Executor();
0146
0147
0148 virtual PyObject* Execute(
0149 Cppyy::TCppMethod_t, Cppyy::TCppObject_t, CallContext*) = 0;
0150
0151
0152 virtual bool HasState() { return false; }
0153 };
0154
0155
0156 CPYCPPYY_EXTERN Executor* CreateExecutor(const std::string& name, cdims_t = 0);
0157
0158
0159 CPYCPPYY_EXTERN void DestroyConverter(Converter* p);
0160
0161
0162 typedef Executor* (*ExecutorFactory_t)(cdims_t);
0163 CPYCPPYY_EXTERN bool RegisterExecutor(const std::string& name, ExecutorFactory_t);
0164
0165
0166 CPYCPPYY_EXTERN bool RegisterExecutorAlias(const std::string& name, const std::string& target);
0167
0168
0169 CPYCPPYY_EXTERN bool UnregisterExecutor(const std::string& name);
0170
0171
0172 CPYCPPYY_EXTERN void* CallVoidP(Cppyy::TCppMethod_t, Cppyy::TCppObject_t, CallContext*);
0173
0174
0175
0176
0177
0178 CPYCPPYY_EXTERN void* Instance_AsVoidPtr(PyObject* pyobject);
0179
0180
0181 CPYCPPYY_EXTERN PyObject* Instance_FromVoidPtr(
0182 void* addr, const std::string& classname, bool python_owns = false);
0183
0184
0185 CPYCPPYY_EXTERN bool Scope_Check(PyObject* pyobject);
0186 CPYCPPYY_EXTERN bool Scope_CheckExact(PyObject* pyobject);
0187
0188
0189 CPYCPPYY_EXTERN bool Instance_Check(PyObject* pyobject);
0190 CPYCPPYY_EXTERN bool Instance_CheckExact(PyObject* pyobject);
0191
0192
0193 CPYCPPYY_EXTERN bool Sequence_Check(PyObject* pyobject);
0194
0195
0196 CPYCPPYY_EXTERN bool Instance_IsLively(PyObject* pyobject);
0197
0198
0199 CPYCPPYY_EXTERN bool Overload_Check(PyObject* pyobject);
0200 CPYCPPYY_EXTERN bool Overload_CheckExact(PyObject* pyobject);
0201
0202
0203
0204
0205
0206 CPYCPPYY_EXTERN bool Import(const std::string& name);
0207
0208
0209 CPYCPPYY_EXTERN bool Exec(const std::string& cmd);
0210
0211
0212 CPYCPPYY_EXTERN const PyResult Eval(const std::string& expr);
0213
0214
0215 CPYCPPYY_EXTERN void ExecScript(const std::string& name, const std::vector<std::string>& args);
0216
0217
0218 CPYCPPYY_EXTERN void Prompt();
0219
0220 }
0221
0222 #endif