Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CPPDataMember.h
Go to the documentation of this file.
1#ifndef CPYRT_CPPDATAMEMBER_H
2#define CPYRT_CPPDATAMEMBER_H
3
4// Bindings
5#include "Converters.h"
6
7// Standard
8#include <string>
9
10namespace cppjit::cpyrt {
11
12class CPPInstance;
13
15public:
17 void Set(interop::TCppScope_t scope, const std::string& name, void* address);
18
19 std::string GetName();
20 void* GetAddress(CPPInstance* pyobj /* owner */);
21
22public: // public, as the python C-API works with C structs
23 PyObject_HEAD intptr_t fOffset;
24 long fFlags;
30
31 // TODO: data members should have a unique identifier, just like methods,
32 // so that reflection information can be recovered post-initialization
33 std::string fFullType;
34
35private: // private, as the python C-API will handle creation
36 CPPDataMember() = delete;
37};
38
39//- property proxy for C++ data members, type and type verification ----------
40extern PyTypeObject CPPDataMember_Type;
41
42template <typename T> inline bool CPPDataMember_Check(T* object) {
43 return object && PyObject_TypeCheck(object, &CPPDataMember_Type);
44}
45
46template <typename T> inline bool CPPDataMember_CheckExact(T* object) {
47 return object && Py_TYPE(object) == &CPPDataMember_Type;
48}
49
50//- creation -----------------------------------------------------------------
53 // Create an initialize a new property descriptor, given the C++ datum.
55 &CPPDataMember_Type, nullptr, nullptr);
56 pyprop->Set(scope, var);
57 return pyprop;
58}
59
61 const std::string& name,
62 void* address) {
63 // Create an initialize a new property descriptor, given the C++ datum.
65 &CPPDataMember_Type, nullptr, nullptr);
66 pyprop->Set(scope, name, address);
67 return pyprop;
68}
69
70} // namespace cppjit::cpyrt
71
72#endif // !CPYRT_CPPDATAMEMBER_H
_object PyObject
char name[80]
Definition TGX11.cxx:142
PyObject_HEAD intptr_t fOffset
void Set(interop::TCppScope_t scope, interop::TCppScope_t var)
interop::TCppScope_t fEnclosingScope
void * GetAddress(CPPInstance *pyobj)
interop::TCppScope_t fScope
PyTypeObject CPPDataMember_Type
bool CPPDataMember_CheckExact(T *object)
CPPDataMember * CPPDataMember_NewConstant(interop::TCppScope_t scope, const std::string &name, void *address)
bool CPPDataMember_Check(T *object)
CPPDataMember * CPPDataMember_New(interop::TCppScope_t scope, interop::TCppScope_t var)
Cpp::DeclRef TCppScope_t
Definition API.h:41