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 std::string fFullType;
31
32private: // private, as the python C-API will handle creation
33 CPPDataMember() = delete;
34};
35
36
37//- property proxy for C++ data members, type and type verification ----------
38extern PyTypeObject CPPDataMember_Type;
39
40template<typename T>
41inline bool CPPDataMember_Check(T* object)
42{
43 return object && PyObject_TypeCheck(object, &CPPDataMember_Type);
44}
45
46template<typename T>
47inline bool CPPDataMember_CheckExact(T* object)
48{
49 return object && Py_TYPE(object) == &CPPDataMember_Type;
50}
51
52//- creation -----------------------------------------------------------------
55{
56// Create an initialize a new property descriptor, given the C++ datum.
57 CPPDataMember* pyprop =
58 (CPPDataMember*)CPPDataMember_Type.tp_new(&CPPDataMember_Type, nullptr, nullptr);
59 pyprop->Set(scope, idata);
60 return pyprop;
61}
62
64 Cppyy::TCppScope_t scope, const std::string& name, void* address)
65{
66// Create an initialize a new property descriptor, given the C++ datum.
67 CPPDataMember* pyprop =
68 (CPPDataMember*)CPPDataMember_Type.tp_new(&CPPDataMember_Type, nullptr, nullptr);
69 pyprop->Set(scope, name, address);
70 return pyprop;
71}
72
73} // namespace CPyCppyy
74
75#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