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// Bindings
5#include "Dimensions.h"
6
7// Standard
8#include <complex>
9#include <stddef.h>
10#if __cplusplus > 201402L
11#include <cstddef>
12#endif
13
14
15namespace CPyCppyy {
16
17class Converter;
18
20public:
21 enum EFlags {
22 kDefault = 0x0000,
23 kIsCppArray = 0x0001,
24 kIsFixed = 0x0002,
25 kIsOwner = 0x0004 };
26
27public:
28 PyObject_HEAD
29 Py_buffer fBufInfo;
30 void** fBuf;
33
34 typedef LowLevelView* (*Creator_t)(void*, cdims_t);
35 Creator_t fCreator; // for slicing, which requires copying
36
37public:
38 void* get_buf() { return fBuf ? *fBuf : fBufInfo.buf; }
39 void set_buf(void** buf) { fBuf = buf; fBufInfo.buf = get_buf(); }
40
41 bool resize(size_t sz);
42};
43
44#define CPPYY_DECL_VIEW_CREATOR(type) \
45 PyObject* CreateLowLevelView(type*, cdims_t shape); \
46 PyObject* CreateLowLevelView(type**, cdims_t shape)
47
50CPPYY_DECL_VIEW_CREATOR(signed char);
51CPPYY_DECL_VIEW_CREATOR(unsigned char);
52#if __cplusplus > 201402L
54#endif
56PyObject* CreateLowLevelView_i8(int8_t**, cdims_t shape);
57PyObject* CreateLowLevelView_i8(uint8_t*, cdims_t shape);
58PyObject* CreateLowLevelView_i8(uint8_t**, cdims_t shape);
60CPPYY_DECL_VIEW_CREATOR(unsigned short);
62CPPYY_DECL_VIEW_CREATOR(unsigned int);
64CPPYY_DECL_VIEW_CREATOR(unsigned long);
66CPPYY_DECL_VIEW_CREATOR(unsigned long long);
69CPPYY_DECL_VIEW_CREATOR(long double);
70CPPYY_DECL_VIEW_CREATOR(std::complex<float>);
71CPPYY_DECL_VIEW_CREATOR(std::complex<double>);
72CPPYY_DECL_VIEW_CREATOR(std::complex<int>);
73CPPYY_DECL_VIEW_CREATOR(std::complex<long>);
74
76PyObject* CreateLowLevelViewString(const char**, cdims_t shape);
77
78inline PyObject* CreatePointerView(void* ptr, cdims_t shape = 0) {
79 return CreateLowLevelView((uintptr_t*)ptr, shape);
80}
81
82//- low level view type and type verification --------------------------------
83extern PyTypeObject LowLevelView_Type;
84
85template<typename T>
86inline bool LowLevelView_Check(T* object)
87{
88 return object && PyObject_TypeCheck(object, &LowLevelView_Type);
89}
90
91template<typename T>
92inline bool LowLevelView_CheckExact(T* object)
93{
94 return object && Py_TYPE(object) == &LowLevelView_Type;
95}
96
97} // namespace CPyCppyy
98
99#endif // !CPYCPPYY_LOWLEVELVIEWS_H
#define Py_TYPE(ob)
Definition CPyCppyy.h:196
#define CPPYY_DECL_VIEW_CREATOR(type)
_object PyObject
void set_buf(void **buf)
LowLevelView *(* Creator_t)(void *, cdims_t)
PyObject_HEAD Py_buffer fBufInfo
PyObject * CreateLowLevelView(bool *, cdims_t shape)
PyObject * CreateLowLevelViewString(char **, cdims_t shape)
bool LowLevelView_CheckExact(T *object)
bool LowLevelView_Check(T *object)
const dims_t & cdims_t
Definition API.h:104
PyObject * CreatePointerView(void *ptr, cdims_t shape=0)
PyObject * CreateLowLevelView_i8(int8_t *, cdims_t shape)
PyTypeObject LowLevelView_Type