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
CPyCppyy
Definition: TPython.cxx:99
CPyCppyy::CPPScopeMeta_New
CPPScope * CPPScopeMeta_New(Cppyy::TCppScope_t klass, PyObject *args)
Definition: CPPScope.h:88
CPyCppyy::CPPScope_Type
PyTypeObject CPPScope_Type
Definition: CPPScope.cxx:613
CPyCppyy::CPPScope::fOperators
Utility::PyOperators * fOperators
Definition: CPPScope.h:56
CPyCppyy::CPPScope::fFlags
int fFlags
Definition: CPPScope.h:51
PyObject
_object PyObject
Definition: PyMethodBase.h:41
CPyCppyy::CPPScope::fModuleName
char * fModuleName
Definition: CPPScope.h:57
CPyCppyy::CPPScope::kNone
@ kNone
Definition: CPPScope.h:40
Cppyy::TCppScope_t
size_t TCppScope_t
Definition: cpp_cppyy.h:18
CPyCppyy::CPPSmartClass::fDereferencer
Cppyy::TCppMethod_t fDereferencer
Definition: CPPScope.h:68
CPyCppyy::Utility::PyOperators
Definition: Utility.h:56
CPyCppyy::CPPSmartClass::fUnderlyingType
Cppyy::TCppType_t fUnderlyingType
Definition: CPPScope.h:67
CPyCppyy::CPPScope::fCppType
Cppyy::TCppType_t fCppType
Definition: CPPScope.h:50
CPyCppyy::CPPScope::fUsing
std::vector< PyObject * > * fUsing
Definition: CPPScope.h:54
CPyCppyy::CPPScope::kIsException
@ kIsException
Definition: CPPScope.h:43
CPyCppyy::CPPScope::kIsPython
@ kIsPython
Definition: CPPScope.h:45
CPyCppyy::CPPScope_Check
bool CPPScope_Check(T *object)
Definition: CPPScope.h:76
CPyCppyy::CPPSmartClass
Definition: CPPScope.h:65
CPyCppyy::CppToPyMap_t
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
CPyCppyy::CPPScope::kIsMeta
@ kIsMeta
Definition: CPPScope.h:41
CPyCppyy::CPPScope_CheckExact
bool CPPScope_CheckExact(T *object)
Definition: CPPScope.h:82
CPyCppyy::CPPScope::fCppObjects
CppToPyMap_t * fCppObjects
Definition: CPPScope.h:53
CPyCppyy::CPPScope::kIsNamespace
@ kIsNamespace
Definition: CPPScope.h:42
CPyCppyy::CPPScope::fImp
union CPyCppyy::CPPScope::@204 fImp
CPyCppyy::CPPScope
Definition: CPPScope.h:37
Cppyy::TCppType_t
TCppScope_t TCppType_t
Definition: cpp_cppyy.h:19
CPyCppyy::CPPScope::CPPScope
CPPScope()=delete
Cppyy::TCppMethod_t
intptr_t TCppMethod_t
Definition: cpp_cppyy.h:22
CPyCppyy::CPPClass
CPPScope CPPClass
Definition: CPPScope.h:63
CPyCppyy::CPPScope::EFlags
EFlags
Definition: CPPScope.h:39
name
char name[80]
Definition: TGX11.cxx:109
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
CPyCppyy::CPPScope::kIsSmart
@ kIsSmart
Definition: CPPScope.h:44
type
int type
Definition: TGX11.cxx:120
Py_TYPE
#define Py_TYPE(ob)
Definition: CPyCppyy.h:209
CPyCppyy::CPPScope::fType
PyHeapTypeObject fType
Definition: CPPScope.h:49
CPyCppyy::CPPScope::kIsInComplete
@ kIsInComplete
Definition: CPPScope.h:46