Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CPPScope.h
Go to the documentation of this file.
1#ifndef CPYRT_CPPSCOPE_H
2#define CPYRT_CPPSCOPE_H
3
4#include "Python.h"
5#include "cppjit_interop.h"
6#include <unordered_map>
7
8#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2
9
10// In p2.2, PyHeapTypeObject is not yet part of the interface
11#include "structmember.h"
12
13typedef struct {
14 PyTypeObject type;
15 PyNumberMethods as_number;
16 PySequenceMethods as_sequence;
17 PyMappingMethods as_mapping;
18 PyBufferProcs as_buffer;
19 PyObject *name, *slots;
20 PyMemberDef members[1];
21} PyHeapTypeObject;
22
23#endif
24
25// Standard
26#include <map>
27#include <vector>
28
29namespace cppjit::cpyrt {
30
31/** Type object to hold class reference (this is only semantically a
32 presentation of CPPScope instances, not in a C++ sense)
33 @author WLAV
34 @date 07/06/2017
35 @version 2.0
36 */
37
38typedef std::unordered_map<interop::TCppObject_t, PyObject*> CppToPyMap_t;
39namespace Utility {
40struct PyOperators;
41}
42
43class CPPScope {
44public:
45 enum EFlags {
46 kNone = 0x0,
47 kIsMeta = 0x0001,
48 kIsNamespace = 0x0002,
49 kIsException = 0x0004,
50 kIsSmart = 0x0008,
51 kIsPython = 0x0010,
52 kIsMultiCross = 0x0020,
53 kIsInComplete = 0x0040,
57 kNoPrettyPrint = 0x0400
58 };
59
60public:
61 PyHeapTypeObject fType;
63 uint32_t fFlags;
64 union {
65 CppToPyMap_t* fCppObjects; // classes only
66 std::vector<PyObject*>* fUsing; // namespaces only
70
71private:
72 CPPScope() = delete;
73};
74
76
82
83//- metatype type and type verification --------------------------------------
84extern PyTypeObject CPPScope_Type;
85
86template <typename T> inline bool CPPScope_Check(T* object) {
87 // Short-circuit the type check by checking tp_new which all generated
88 // subclasses of CPPScope inherit.
89 return object && (Py_TYPE(object)->tp_new == CPPScope_Type.tp_new ||
90 PyObject_TypeCheck(object, &CPPScope_Type));
91}
92
93template <typename T> inline bool CPPScope_CheckExact(T* object) {
94 return object && Py_TYPE(object) == &CPPScope_Type;
95}
96
97//- creation -----------------------------------------------------------------
99 // Create and initialize a new scope meta class
100 CPPScope* pymeta =
101 (CPPScope*)PyType_Type.tp_new(&CPPScope_Type, args, nullptr);
102 if (!pymeta)
103 return pymeta;
104
105 // set the klass id, for instances and Python-side derived classes to pick up
106 pymeta->fCppType = klass;
107 pymeta->fFlags = CPPScope::kIsMeta;
108 pymeta->fImp.fCppObjects = nullptr;
109 pymeta->fOperators = nullptr;
110 pymeta->fModuleName = nullptr;
111
112 return pymeta;
113}
114
115} // namespace cppjit::cpyrt
116
117#endif // !CPYRT_CPPSCOPE_H
_object PyObject
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:142
Utility::PyOperators * fOperators
Definition CPPScope.h:68
std::vector< PyObject * > * fUsing
Definition CPPScope.h:66
union cppjit::cpyrt::CPPScope::@183 fImp
CppToPyMap_t * fCppObjects
Definition CPPScope.h:65
interop::TCppScope_t fCppType
Definition CPPScope.h:62
PyHeapTypeObject fType
Definition CPPScope.h:61
interop::TCppMethod_t fDereferencer
Definition CPPScope.h:80
interop::TCppScope_t fUnderlyingType
Definition CPPScope.h:79
CPPScope * CPPScopeMeta_New(interop::TCppScope_t klass, PyObject *args)
Definition CPPScope.h:98
PyTypeObject CPPScope_Type
Definition CPPScope.cxx:686
CPPScope CPPClass
Definition CPPScope.h:75
bool CPPScope_CheckExact(T *object)
Definition CPPScope.h:93
std::unordered_map< interop::TCppObject_t, PyObject * > CppToPyMap_t
Type object to hold class reference (this is only semantically a presentation of CPPScope instances,...
Definition CPPScope.h:38
bool CPPScope_Check(T *object)
Definition CPPScope.h:86
Cpp::FuncRef TCppMethod_t
Definition API.h:44
Cpp::DeclRef TCppScope_t
Definition API.h:41