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
12namespace CPyCppyy {
13
14class Converter;
15
17public:
18 PyObject_HEAD
19 Py_buffer fBufInfo;
20 void** fBuf;
22
23public:
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
35#if __cplusplus > 201402L
37#endif
45CPPYY_DECL_VIEW_CREATOR(unsigned long long);
49CPPYY_DECL_VIEW_CREATOR(std::complex<float>);
50CPPYY_DECL_VIEW_CREATOR(std::complex<double>);
51CPPYY_DECL_VIEW_CREATOR(std::complex<int>);
52CPPYY_DECL_VIEW_CREATOR(std::complex<long>);
53
54PyObject* CreateLowLevelView(const char**, Py_ssize_t* shape = nullptr);
55
56inline 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 --------------------------------
62extern PyTypeObject LowLevelView_Type;
63
64template<typename T>
65inline bool LowLevelView_Check(T* object)
66{
67 return object && PyObject_TypeCheck(object, &LowLevelView_Type);
68}
69
70template<typename T>
71inline 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
#define Py_TYPE(ob)
Definition: CPyCppyy.h:209
int Py_ssize_t
Definition: CPyCppyy.h:228
_object PyObject
Definition: PyMethodBase.h:41
void set_buf(void **buf)
Definition: LowLevelViews.h:25
PyObject_HEAD Py_buffer fBufInfo
Definition: LowLevelViews.h:19
CPPYY_DECL_VIEW_CREATOR(bool)
PyObject * CreatePointerView(void *ptr, size_t size=(size_t) -1)
Definition: LowLevelViews.h:56
PyObject * CreateLowLevelView(const char **, Py_ssize_t *shape=nullptr)
bool LowLevelView_CheckExact(T *object)
Definition: LowLevelViews.h:71
bool LowLevelView_Check(T *object)
Definition: LowLevelViews.h:65
PyTypeObject LowLevelView_Type
double T(double x)
Definition: ChebyshevPol.h:34
unsigned char byte
Definition: gifdecode.c:10