Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Dimensions.h
Go to the documentation of this file.
1#ifndef CPYCPPYY_DIMENSIONS_H
2#define CPYCPPYY_DIMENSIONS_H
3
4// Standard
5#include <algorithm>
6#include <initializer_list>
7
8
9namespace CPyCppyy {
10
11static const dim_t UNKNOWN_SIZE = (dim_t)-1;
12
14 dim_t* fDims;
15
16public:
17 Dimensions(dim_t ndim = 0, dim_t* dims = nullptr) : fDims(nullptr) {
18 if (ndim && ndim != UNKNOWN_SIZE) {
19 fDims = new dim_t[ndim+1];
20 fDims[0] = ndim;
21 if (dims) std::copy(dims, dims+ndim, fDims+1);
22 else std::fill_n(fDims+1, ndim, UNKNOWN_SIZE);
23 }
24 }
25 Dimensions(std::initializer_list<dim_t> l) {
26 fDims = new dim_t[l.size()+1];
27 fDims[0] = l.size();
28 std::copy(l.begin(), l.end(), fDims+1);
29 }
30 Dimensions(const Dimensions& d) : fDims(nullptr) {
31 if (d.fDims) {
32 fDims = new dim_t[d.fDims[0]+1];
33 std::copy(d.fDims, d.fDims+d.fDims[0]+1, fDims);
34 }
35 }
36 Dimensions(Dimensions&& d) : fDims(d.fDims) {
37 d.fDims = nullptr;
38 }
40 if (this != &d) {
41 if (!d.fDims) {
42 delete [] fDims;
43 fDims = nullptr;
44 } else {
45 if (!fDims || (fDims && fDims[0] != d.fDims[0])) {
46 delete [] fDims;
47 fDims = new dim_t[d.fDims[0]+1];
48 }
49 std::copy(d.fDims, d.fDims+d.fDims[0]+1, fDims);
50 }
51 }
52 return *this;
53 }
55 delete [] fDims;
56 }
57
58public:
59 operator bool() const { return (bool)fDims; }
60
61 dim_t ndim() const { return fDims ? fDims[0] : UNKNOWN_SIZE; }
62 void ndim(dim_t d) {
63 if (fDims) {
64 if (fDims[0] == d) return;
65 delete [] fDims;
66 }
67
68 fDims = new dim_t[d+1];
69 fDims[0] = d;
70 std::fill_n(fDims+1, d, UNKNOWN_SIZE);
71 }
72
73 dim_t operator[](dim_t i) const { return fDims[i+1]; }
74 dim_t& operator[](dim_t i) { return fDims[i+1]; }
75
76 Dimensions sub() const { return fDims ? Dimensions(fDims[0]-1, fDims+2) : Dimensions(); }
77};
78
79typedef Dimensions dims_t;
80typedef const dims_t& cdims_t;
81
82} // namespace CPyCppyy
83
84#endif // !CPYCPPYY_DIMENSIONS_H
#define d(i)
Definition RSha256.hxx:102
#define CPYCPPYY_CLASS_EXPORT
Definition CommonDefs.h:27
Dimensions(std::initializer_list< dim_t > l)
Definition Dimensions.h:25
Dimensions(dim_t ndim=0, dim_t *dims=nullptr)
Definition Dimensions.h:17
Dimensions(const Dimensions &d)
Definition Dimensions.h:30
Dimensions & operator=(const Dimensions &d)
Definition Dimensions.h:39
Dimensions sub() const
Definition Dimensions.h:76
dim_t & operator[](dim_t i)
Definition Dimensions.h:74
dim_t operator[](dim_t i) const
Definition Dimensions.h:73
Dimensions(Dimensions &&d)
Definition Dimensions.h:36
void ndim(dim_t d)
Definition Dimensions.h:62
dim_t ndim() const
Definition Dimensions.h:61
Py_ssize_t dim_t
Definition API.h:90
Dimensions dims_t
Definition API.h:103
static const dim_t UNKNOWN_SIZE
Definition Dimensions.h:11
const dims_t & cdims_t
Definition API.h:104
TLine l
Definition textangle.C:4