Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
11namespace CPyCppyy {
12
13class CPPInstance;
14
16public:
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();
21 void* GetAddress(CPPInstance* pyobj /* owner */);
22
23public: // public, as the python C-API works with C structs
24 PyObject_HEAD
25 intptr_t fOffset;
26 long fFlags;
31
32 // TODO: data members should have a unique identifier, just like methods,
33 // so that reflection information can be recovered post-initialization
34 std::string fFullType;
35
36private: // private, as the python C-API will handle creation
37 CPPDataMember() = delete;
38};
39
40
41//- property proxy for C++ data members, type and type verification ----------
42extern PyTypeObject CPPDataMember_Type;
43
44template<typename T>
45inline bool CPPDataMember_Check(T* object)
46{
47 return object && PyObject_TypeCheck(object, &CPPDataMember_Type);
48}
49
50template<typename T>
51inline bool CPPDataMember_CheckExact(T* object)
52{
53 return object && Py_TYPE(object) == &CPPDataMember_Type;
54}
55
56//- creation -----------------------------------------------------------------
59{
60// Create an initialize a new property descriptor, given the C++ datum.
61 CPPDataMember* pyprop =
62 (CPPDataMember*)CPPDataMember_Type.tp_new(&CPPDataMember_Type, nullptr, nullptr);
63 pyprop->Set(scope, idata);
64 return pyprop;
65}
66
68 Cppyy::TCppScope_t scope, const std::string& name, void* address)
69{
70// Create an initialize a new property descriptor, given the C++ datum.
71 CPPDataMember* pyprop =
72 (CPPDataMember*)CPPDataMember_Type.tp_new(&CPPDataMember_Type, nullptr, nullptr);
73 pyprop->Set(scope, name, address);
74 return pyprop;
75}
76
77} // namespace CPyCppyy
78
79#endif // !CPYCPPYY_CPPDATAMEMBER_H
#define Py_TYPE(ob)
Definition CPyCppyy.h:196
_object PyObject
char name[80]
Definition TGX11.cxx:110
PyObject_HEAD intptr_t fOffset
Cppyy::TCppScope_t fEnclosingScope
void * GetAddress(CPPInstance *pyobj)
void Set(Cppyy::TCppScope_t scope, Cppyy::TCppIndex_t idata)
CPPDataMember * CPPDataMember_NewConstant(Cppyy::TCppScope_t scope, const std::string &name, void *address)
bool CPPDataMember_CheckExact(T *object)
CPPDataMember * CPPDataMember_New(Cppyy::TCppScope_t scope, Cppyy::TCppIndex_t idata)
bool CPPDataMember_Check(T *object)
PyTypeObject CPPDataMember_Type
size_t TCppIndex_t
Definition cpp_cppyy.h:24
size_t TCppScope_t
Definition cpp_cppyy.h:18