Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
33CPPYY_DECL_VIEW_CREATOR(signed char);
34CPPYY_DECL_VIEW_CREATOR(unsigned char);
35#if __cplusplus > 201402L
37#endif
39CPPYY_DECL_VIEW_CREATOR(unsigned short);
41CPPYY_DECL_VIEW_CREATOR(unsigned int);
43CPPYY_DECL_VIEW_CREATOR(unsigned long);
45CPPYY_DECL_VIEW_CREATOR(unsigned long long);
48CPPYY_DECL_VIEW_CREATOR(long double);
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:217
int Py_ssize_t
Definition CPyCppyy.h:236
#define CPPYY_DECL_VIEW_CREATOR(type)
_object PyObject
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
void set_buf(void **buf)
PyObject_HEAD Py_buffer fBufInfo
Set of helper functions that are invoked from the pythonizors, on the Python side.
PyObject * CreatePointerView(void *ptr, size_t size=(size_t) -1)
PyObject * CreateLowLevelView(bool *, Py_ssize_t *shape=nullptr)
bool LowLevelView_CheckExact(T *object)
bool LowLevelView_Check(T *object)
PyTypeObject LowLevelView_Type