Logo ROOT  
Reference Guide
LowLevelViews.h
Go to the documentation of this file.
1 #ifndef CPYCPPYY_LOWLEVELVIEWS_H
2 #define CPYCPPYY_LOWLEVELVIEWS_H
3 
4 #include <complex>
5 #include <stddef.h>
6 
7 #if __cplusplus > 201402L
8 #include <cstddef>
9 #endif
10 
11 
12 namespace CPyCppyy {
13 
14 class Converter;
15 
16 class LowLevelView {
17 public:
18  PyObject_HEAD
19  Py_buffer fBufInfo;
20  void** fBuf;
22 
23 public:
24  void* get_buf() { return fBuf ? *fBuf : fBufInfo.buf; }
25  void set_buf(void** buf) { fBuf = buf; fBufInfo.buf = get_buf(); }
26 };
27 
28 #define CPPYY_DECL_VIEW_CREATOR(type) \
29  PyObject* CreateLowLevelView(type*, Py_ssize_t* shape = nullptr); \
30  PyObject* CreateLowLevelView(type**, Py_ssize_t* shape = nullptr)
31 
33 CPPYY_DECL_VIEW_CREATOR(signed char);
34 CPPYY_DECL_VIEW_CREATOR(unsigned char);
35 #if __cplusplus > 201402L
37 #endif
39 CPPYY_DECL_VIEW_CREATOR(unsigned short);
41 CPPYY_DECL_VIEW_CREATOR(unsigned int);
43 CPPYY_DECL_VIEW_CREATOR(unsigned long);
44 CPPYY_DECL_VIEW_CREATOR(long long);
45 CPPYY_DECL_VIEW_CREATOR(unsigned long long);
48 CPPYY_DECL_VIEW_CREATOR(long double);
49 CPPYY_DECL_VIEW_CREATOR(std::complex<float>);
50 CPPYY_DECL_VIEW_CREATOR(std::complex<double>);
51 CPPYY_DECL_VIEW_CREATOR(std::complex<int>);
52 CPPYY_DECL_VIEW_CREATOR(std::complex<long>);
53 
54 PyObject* CreateLowLevelView(const char**, Py_ssize_t* shape = nullptr);
55 
56 inline PyObject* CreatePointerView(void* ptr, size_t size = (size_t)-1) {
57  Py_ssize_t shape[] = {1, (Py_ssize_t)size};
58  return CreateLowLevelView((uintptr_t*)ptr, shape);
59 }
60 
61 //- low level view type and type verification --------------------------------
62 extern PyTypeObject LowLevelView_Type;
63 
64 template<typename T>
65 inline bool LowLevelView_Check(T* object)
66 {
67  return object && PyObject_TypeCheck(object, &LowLevelView_Type);
68 }
69 
70 template<typename T>
71 inline bool LowLevelView_CheckExact(T* object)
72 {
73  return object && Py_TYPE(object) == &LowLevelView_Type;
74 }
75 
76 } // namespace CPyCppyy
77 
78 #endif // !CPYCPPYY_LOWLEVELVIEWS_H
double T(double x)
Definition: ChebyshevPol.h:34
#define Py_TYPE(ob)
Definition: CPyCppyy.h:209
PyObject_HEAD Py_buffer fBufInfo
Definition: LowLevelViews.h:19
bool LowLevelView_Check(T *object)
Definition: LowLevelViews.h:65
CPPYY_DECL_VIEW_CREATOR(bool)
unsigned char byte
Definition: gifdecode.c:10
_object PyObject
Definition: PyMethodBase.h:41
void set_buf(void **buf)
Definition: LowLevelViews.h:25
int Py_ssize_t
Definition: CPyCppyy.h:228
PyObject * CreateLowLevelView(const char **, Py_ssize_t *shape=nullptr)
PyObject * CreatePointerView(void *ptr, size_t size=(size_t) -1)
Definition: LowLevelViews.h:56
PyTypeObject LowLevelView_Type
bool LowLevelView_CheckExact(T *object)
Definition: LowLevelViews.h:71