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) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
11#include <cstddef>
12#endif
13
14
15namespace CPyCppyy {
16
17class Converter;
18
20public:
21 enum EFlags {
22 kDefault = 0x0000,
23 kIsCppArray = 0x0001, // allocated with new[]
24 kIsFixed = 0x0002, // fixed size array (assumed flat)
25 kIsOwner = 0x0004 }; // Python owns
26
27public:
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) || (defined(_MSC_VER) && _MSVC_LANG > 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);
60PyObject* CreateLowLevelView_i16(int16_t**, cdims_t shape);
61PyObject* CreateLowLevelView_i16(uint16_t*, cdims_t shape);
62PyObject* CreateLowLevelView_i16(uint16_t**, cdims_t shape);
64PyObject* CreateLowLevelView_i32(int32_t**, cdims_t shape);
65PyObject* CreateLowLevelView_i32(uint32_t*, cdims_t shape);
66PyObject* CreateLowLevelView_i32(uint32_t**, cdims_t shape);
67
69CPPYY_DECL_VIEW_CREATOR(unsigned short);
71CPPYY_DECL_VIEW_CREATOR(unsigned int);
73CPPYY_DECL_VIEW_CREATOR(unsigned long);
75CPPYY_DECL_VIEW_CREATOR(unsigned long long);
78CPPYY_DECL_VIEW_CREATOR(long double);
79CPPYY_DECL_VIEW_CREATOR(std::complex<float>);
80CPPYY_DECL_VIEW_CREATOR(std::complex<double>);
81CPPYY_DECL_VIEW_CREATOR(std::complex<int>);
82CPPYY_DECL_VIEW_CREATOR(std::complex<long>);
83
85PyObject* CreateLowLevelViewString(const char**, cdims_t shape);
86
87inline PyObject* CreatePointerView(void* ptr, cdims_t shape = 0) {
88 return CreateLowLevelView((uintptr_t*)ptr, shape);
89}
90
91//- low level view type and type verification --------------------------------
93
94template<typename T>
95inline bool LowLevelView_Check(T* object)
96{
97 return object && PyObject_TypeCheck(object, &LowLevelView_Type);
98}
99
100template<typename T>
101inline bool LowLevelView_CheckExact(T* object)
102{
103 return object && Py_TYPE(object) == &LowLevelView_Type;
104}
105
106} // namespace CPyCppyy
107
108#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