Logo ROOT  
Reference Guide
CPPScope.h
Go to the documentation of this file.
1#ifndef CPYCPPYY_CPPSCOPE_H
2#define CPYCPPYY_CPPSCOPE_H
3
4#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2
5
6// In p2.2, PyHeapTypeObject is not yet part of the interface
7#include "structmember.h"
8
9typedef struct {
10 PyTypeObject type;
11 PyNumberMethods as_number;
12 PySequenceMethods as_sequence;
13 PyMappingMethods as_mapping;
14 PyBufferProcs as_buffer;
15 PyObject *name, *slots;
16 PyMemberDef members[1];
17} PyHeapTypeObject;
18
19#endif
20
21// Standard
22#include <map>
23
24
25namespace CPyCppyy {
26
27/** Type object to hold class reference (this is only semantically a presentation
28 of CPPScope instances, not in a C++ sense)
29 @author WLAV
30 @date 07/06/2017
31 @version 2.0
32 */
33
34typedef std::map<Cppyy::TCppObject_t, PyObject*> CppToPyMap_t;
35namespace Utility { struct PyOperators; }
36
37class CPPScope {
38public:
39 enum EFlags {
40 kNone = 0x0,
41 kIsMeta = 0x0001,
42 kIsNamespace = 0x0002,
43 kIsException = 0x0004,
44 kIsSmart = 0x0008,
45 kIsPython = 0x0010,
46 kIsInComplete = 0x0020 };
47
48public:
49 PyHeapTypeObject fType;
51 int fFlags;
52 union {
53 CppToPyMap_t* fCppObjects; // classes only
54 std::vector<PyObject*>* fUsing; // namespaces only
58
59private:
60 CPPScope() = delete;
61};
62
64
65class CPPSmartClass : public CPPClass {
66public:
69};
70
71
72//- metatype type and type verification --------------------------------------
73extern PyTypeObject CPPScope_Type;
74
75template<typename T>
76inline bool CPPScope_Check(T* object)
77{
78 return object && PyObject_TypeCheck(object, &CPPScope_Type);
79}
80
81template<typename T>
82inline bool CPPScope_CheckExact(T* object)
83{
84 return object && Py_TYPE(object) == &CPPScope_Type;
85}
86
87//- creation -----------------------------------------------------------------
89{
90// Create and initialize a new scope meta class
91 CPPScope* pymeta = (CPPScope*)PyType_Type.tp_new(&CPPScope_Type, args, nullptr);
92 if (!pymeta) return pymeta;
93
94// set the klass id, for instances and Python-side derived classes to pick up
95 pymeta->fCppType = klass;
96 pymeta->fFlags = CPPScope::kIsMeta;
97 pymeta->fImp.fCppObjects = nullptr;
98 pymeta->fOperators = nullptr;
99 pymeta->fModuleName = nullptr;
100
101 return pymeta;
102}
103
104} // namespace CPyCppyy
105
106#endif // !CPYCPPYY_CPPSCOPE_H
#define Py_TYPE(ob)
Definition: CPyCppyy.h:217
_object PyObject
Definition: PyMethodBase.h:42
char name[80]
Definition: TGX11.cxx:110
int type
Definition: TGX11.cxx:121
Utility::PyOperators * fOperators
Definition: CPPScope.h:56
char * fModuleName
Definition: CPPScope.h:57
PyHeapTypeObject fType
Definition: CPPScope.h:49
Cppyy::TCppType_t fCppType
Definition: CPPScope.h:50
std::vector< PyObject * > * fUsing
Definition: CPPScope.h:54
union CPyCppyy::CPPScope::@218 fImp
CppToPyMap_t * fCppObjects
Definition: CPPScope.h:53
Cppyy::TCppMethod_t fDereferencer
Definition: CPPScope.h:68
Cppyy::TCppType_t fUnderlyingType
Definition: CPPScope.h:67
Set of helper functions that are invoked from the pythonizors, on the Python side.
std::map< Cppyy::TCppObject_t, PyObject * > CppToPyMap_t
Type object to hold class reference (this is only semantically a presentation of CPPScope instances,...
Definition: CPPScope.h:34
bool CPPScope_Check(T *object)
Definition: CPPScope.h:76
CPPScope * CPPScopeMeta_New(Cppyy::TCppScope_t klass, PyObject *args)
Definition: CPPScope.h:88
CPPScope CPPClass
Definition: CPPScope.h:63
bool CPPScope_CheckExact(T *object)
Definition: CPPScope.h:82
PyTypeObject CPPScope_Type
Definition: CPPScope.cxx:614
intptr_t TCppMethod_t
Definition: cpp_cppyy.h:22
TCppScope_t TCppType_t
Definition: cpp_cppyy.h:19
size_t TCppScope_t
Definition: cpp_cppyy.h:18
double T(double x)
Definition: ChebyshevPol.h:34