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() { return CPyCppyy_PyText_AsString(fName); }
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;
30
31private: // 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 ----------
37extern PyTypeObject CPPDataMember_Type;
38
39template<typename T>
40inline bool CPPDataMember_Check(T* object)
41{
42 return object && PyObject_TypeCheck(object, &CPPDataMember_Type);
43}
44
45template<typename T>
46inline 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
#define Py_TYPE(ob)
Definition CPyCppyy.h:217
#define CPyCppyy_PyText_AsString
Definition CPyCppyy.h:97
_object PyObject
long Long_t
Definition RtypesCore.h:54
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)
Set of helper functions that are invoked from the pythonizors, on the Python side.
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