Logo ROOT  
Reference Guide
CPPDataMember.h
Go to the documentation of this file.
1 #ifndef CPYCPPYY_CPPDATAMEMBER_H
2 #define CPYCPPYY_CPPDATAMEMBER_H
3 
4 // Bindings
5 #include "Converters.h"
6 
7 // Standard
8 #include <string>
9 
10 
11 namespace CPyCppyy {
12 
13 class CPPInstance;
14 
16 public:
17  void Set(Cppyy::TCppScope_t scope, Cppyy::TCppIndex_t idata);
18  void Set(Cppyy::TCppScope_t scope, const std::string& name, void* address);
19 
20  std::string GetName() { return CPyCppyy_PyText_AsString(fName); }
21  void* GetAddress(CPPInstance* pyobj /* owner */);
22 
23 public: // public, as the python C-API works with C structs
24  PyObject_HEAD
25  intptr_t fOffset;
30 
31 private: // private, as the python C-API will handle creation
32  CPPDataMember() = delete;
33 };
34 
35 
36 //- property proxy for C++ data members, type and type verification ----------
37 extern PyTypeObject CPPDataMember_Type;
38 
39 template<typename T>
40 inline bool CPPDataMember_Check(T* object)
41 {
42  return object && PyObject_TypeCheck(object, &CPPDataMember_Type);
43 }
44 
45 template<typename T>
46 inline bool CPPDataMember_CheckExact(T* object)
47 {
48  return object && Py_TYPE(object) == &CPPDataMember_Type;
49 }
50 
51 //- creation -----------------------------------------------------------------
54 {
55 // Create an initialize a new property descriptor, given the C++ datum.
56  CPPDataMember* pyprop =
57  (CPPDataMember*)CPPDataMember_Type.tp_new(&CPPDataMember_Type, nullptr, nullptr);
58  pyprop->Set(scope, idata);
59  return pyprop;
60 }
61 
63  Cppyy::TCppScope_t scope, const std::string& name, void* address)
64 {
65 // Create an initialize a new property descriptor, given the C++ datum.
66  CPPDataMember* pyprop =
67  (CPPDataMember*)CPPDataMember_Type.tp_new(&CPPDataMember_Type, nullptr, nullptr);
68  pyprop->Set(scope, name, address);
69  return pyprop;
70 }
71 
72 } // namespace CPyCppyy
73 
74 #endif // !CPYCPPYY_CPPDATAMEMBER_H
CPPDataMember * CPPDataMember_NewConstant(Cppyy::TCppScope_t scope, const std::string &name, void *address)
Definition: CPPDataMember.h:62
size_t TCppScope_t
Definition: cpp_cppyy.h:18
double T(double x)
Definition: ChebyshevPol.h:34
#define Py_TYPE(ob)
Definition: CPyCppyy.h:209
size_t TCppIndex_t
Definition: cpp_cppyy.h:24
bool CPPDataMember_CheckExact(T *object)
Definition: CPPDataMember.h:46
_object PyObject
Definition: PyMethodBase.h:41
PyObject_HEAD intptr_t fOffset
Definition: CPPDataMember.h:25
PyTypeObject CPPDataMember_Type
CPPDataMember * CPPDataMember_New(Cppyy::TCppScope_t scope, Cppyy::TCppIndex_t idata)
Definition: CPPDataMember.h:52
long Long_t
Definition: RtypesCore.h:52
void * GetAddress(CPPInstance *pyobj)
bool CPPDataMember_Check(T *object)
Definition: CPPDataMember.h:40
void Set(Cppyy::TCppScope_t scope, Cppyy::TCppIndex_t idata)
Cppyy::TCppScope_t fEnclosingScope
Definition: CPPDataMember.h:28
char name[80]
Definition: TGX11.cxx:109
#define CPyCppyy_PyText_AsString
Definition: CPyCppyy.h:97