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 
9 typedef 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 
25 namespace 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 
34 typedef std::map<Cppyy::TCppObject_t, PyObject*> CppToPyMap_t;
35 namespace Utility { struct PyOperators; }
36 
37 class CPPScope {
38 public:
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 
48 public:
49  PyHeapTypeObject fType;
51  int fFlags;
52  union {
53  CppToPyMap_t* fCppObjects; // classes only
54  std::vector<PyObject*>* fUsing; // namespaces only
55  } fImp;
57  char* fModuleName;
58 
59 private:
60  CPPScope() = delete;
61 };
62 
64 
65 class CPPSmartClass : public CPPClass {
66 public:
69 };
70 
71 
72 //- metatype type and type verification --------------------------------------
73 extern PyTypeObject CPPScope_Type;
74 
75 template<typename T>
76 inline bool CPPScope_Check(T* object)
77 {
78  return object && PyObject_TypeCheck(object, &CPPScope_Type);
79 }
80 
81 template<typename T>
82 inline 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
PyTypeObject CPPScope_Type
Definition: CPPScope.cxx:613
TCppScope_t TCppType_t
Definition: cpp_cppyy.h:19
Cppyy::TCppType_t fCppType
Definition: CPPScope.h:50
CPPScope CPPClass
Definition: CPPScope.h:63
size_t TCppScope_t
Definition: cpp_cppyy.h:18
double T(double x)
Definition: ChebyshevPol.h:34
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
Cppyy::TCppType_t fUnderlyingType
Definition: CPPScope.h:67
Utility::PyOperators * fOperators
Definition: CPPScope.h:56
std::vector< PyObject * > * fUsing
Definition: CPPScope.h:54
union CPyCppyy::CPPScope::@204 fImp
#define Py_TYPE(ob)
Definition: CPyCppyy.h:209
Cppyy::TCppMethod_t fDereferencer
Definition: CPPScope.h:68
char * fModuleName
Definition: CPPScope.h:57
_object PyObject
Definition: PyMethodBase.h:41
bool CPPScope_CheckExact(T *object)
Definition: CPPScope.h:82
intptr_t TCppMethod_t
Definition: cpp_cppyy.h:22
CPPScope * CPPScopeMeta_New(Cppyy::TCppScope_t klass, PyObject *args)
Definition: CPPScope.h:88
PyHeapTypeObject fType
Definition: CPPScope.h:49
int type
Definition: TGX11.cxx:120
bool CPPScope_Check(T *object)
Definition: CPPScope.h:76
CppToPyMap_t * fCppObjects
Definition: CPPScope.h:53
char name[80]
Definition: TGX11.cxx:109