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#include <cstddef>
11
12
13namespace CPyCppyy {
14
15class Converter;
16
18public:
19 enum EFlags {
20 kDefault = 0x0000,
21 kIsCppArray = 0x0001, // allocated with new[]
22 kIsFixed = 0x0002, // fixed size array (assumed flat)
23 kIsOwner = 0x0004 }; // Python owns
24
25public:
28 void** fBuf;
31
32 typedef LowLevelView* (*Creator_t)(void*, cdims_t);
33 Creator_t fCreator; // for slicing, which requires copying
34
35public:
36 void* get_buf() { return fBuf ? *fBuf : fBufInfo.buf; }
37 void set_buf(void** buf) { fBuf = buf; fBufInfo.buf = get_buf(); }
38
39 bool resize(size_t sz);
40};
41
42#define CPPYY_DECL_VIEW_CREATOR(type) \
43 PyObject* CreateLowLevelView(type*, cdims_t shape); \
44 PyObject* CreateLowLevelView(type**, cdims_t shape)
45
48CPPYY_DECL_VIEW_CREATOR(signed char);
49CPPYY_DECL_VIEW_CREATOR(unsigned char);
52PyObject* CreateLowLevelView_i8(int8_t**, cdims_t shape);
53PyObject* CreateLowLevelView_i8(uint8_t*, cdims_t shape);
54PyObject* CreateLowLevelView_i8(uint8_t**, cdims_t shape);
56PyObject* CreateLowLevelView_i16(int16_t**, cdims_t shape);
57PyObject* CreateLowLevelView_i16(uint16_t*, cdims_t shape);
58PyObject* CreateLowLevelView_i16(uint16_t**, cdims_t shape);
60PyObject* CreateLowLevelView_i32(int32_t**, cdims_t shape);
61PyObject* CreateLowLevelView_i32(uint32_t*, cdims_t shape);
62PyObject* CreateLowLevelView_i32(uint32_t**, cdims_t shape);
63
65CPPYY_DECL_VIEW_CREATOR(unsigned short);
67CPPYY_DECL_VIEW_CREATOR(unsigned int);
69CPPYY_DECL_VIEW_CREATOR(unsigned long);
71CPPYY_DECL_VIEW_CREATOR(unsigned long long);
74CPPYY_DECL_VIEW_CREATOR(long double);
75CPPYY_DECL_VIEW_CREATOR(std::complex<float>);
76CPPYY_DECL_VIEW_CREATOR(std::complex<double>);
77CPPYY_DECL_VIEW_CREATOR(std::complex<int>);
78CPPYY_DECL_VIEW_CREATOR(std::complex<long>);
79
81PyObject* CreateLowLevelViewString(const char**, cdims_t shape);
82
83inline PyObject* CreatePointerView(void* ptr, cdims_t shape = 0) {
84 return CreateLowLevelView((uintptr_t*)ptr, shape);
85}
86
87//- low level view type and type verification --------------------------------
89
90template<typename T>
91inline bool LowLevelView_Check(T* object)
92{
93 return object && PyObject_TypeCheck(object, &LowLevelView_Type);
94}
95
96template<typename T>
97inline bool LowLevelView_CheckExact(T* object)
98{
99 return object && Py_TYPE(object) == &LowLevelView_Type;
100}
101
102} // namespace CPyCppyy
103
104#endif // !CPYCPPYY_LOWLEVELVIEWS_H
#define Py_TYPE(ob)
Definition CPyCppyy.h:196
#define CPPYY_DECL_VIEW_CREATOR(type)
_object PyObject
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 * CreateLowLevelView_i16(int16_t *, cdims_t shape)
PyObject * CreatePointerView(void *ptr, cdims_t shape=0)
PyObject * CreateLowLevelView_i8(int8_t *, cdims_t shape)
PyObject * CreateLowLevelView_i32(int32_t *, cdims_t shape)
PyTypeObject LowLevelView_Type