Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 kIsMultiCross = 0x0020,
47 kIsInComplete = 0x0040,
48 kNoImplicit = 0x0080,
51 kNoPrettyPrint = 0x0400 };
52
53public:
54 PyHeapTypeObject fType;
56 uint32_t fFlags;
57 union {
58 CppToPyMap_t* fCppObjects; // classes only
59 std::vector<PyObject*>* fUsing; // namespaces only
63
64private:
65 CPPScope() = delete;
66};
67
69
70class CPPSmartClass : public CPPClass {
71public:
74};
75
76
77//- metatype type and type verification --------------------------------------
78extern PyTypeObject CPPScope_Type;
79
80template<typename T>
81inline bool CPPScope_Check(T* object)
82{
83// Short-circuit the type check by checking tp_new which all generated subclasses
84// of CPPScope inherit.
85 return object && \
86 (Py_TYPE(object)->tp_new == CPPScope_Type.tp_new || \
87 PyObject_TypeCheck(object, &CPPScope_Type));
88}
89
90template<typename T>
91inline bool CPPScope_CheckExact(T* object)
92{
93 return object && Py_TYPE(object) == &CPPScope_Type;
94}
95
96//- creation -----------------------------------------------------------------
98{
99// Create and initialize a new scope meta class
100 CPPScope* pymeta = (CPPScope*)PyType_Type.tp_new(&CPPScope_Type, args, nullptr);
101 if (!pymeta) return pymeta;
102
103// set the klass id, for instances and Python-side derived classes to pick up
104 pymeta->fCppType = klass;
105 pymeta->fFlags = CPPScope::kIsMeta;
106 pymeta->fImp.fCppObjects = nullptr;
107 pymeta->fOperators = nullptr;
108 pymeta->fModuleName = nullptr;
109
110 return pymeta;
111}
112
113} // namespace CPyCppyy
114
115#endif // !CPYCPPYY_CPPSCOPE_H
#define Py_TYPE(ob)
Definition CPyCppyy.h:196
_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:110
uint32_t fFlags
Definition CPPScope.h:56
Utility::PyOperators * fOperators
Definition CPPScope.h:61
union CPyCppyy::CPPScope::@206 fImp
PyHeapTypeObject fType
Definition CPPScope.h:54
Cppyy::TCppType_t fCppType
Definition CPPScope.h:55
std::vector< PyObject * > * fUsing
Definition CPPScope.h:59
CppToPyMap_t * fCppObjects
Definition CPPScope.h:58
Cppyy::TCppMethod_t fDereferencer
Definition CPPScope.h:73
Cppyy::TCppType_t fUnderlyingType
Definition CPPScope.h:72
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:81
CPPScope * CPPScopeMeta_New(Cppyy::TCppScope_t klass, PyObject *args)
Definition CPPScope.h:97
CPPScope CPPClass
Definition CPPScope.h:68
bool CPPScope_CheckExact(T *object)
Definition CPPScope.h:91
PyTypeObject CPPScope_Type
Definition CPPScope.cxx:645
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