ndarray
NumPy-friendly multidimensional arrays in C++
Loading...
Searching...
No Matches
ArrayBaseN.h
Go to the documentation of this file.
1// -*- c++ -*-
2/*
3 * Copyright (c) 2010-2012, Jim Bosch
4 * All rights reserved.
5 *
6 * ndarray is distributed under a simple BSD-like license;
7 * see the LICENSE file that should be present in the root
8 * of the source distribution, or alternately available at:
9 * https://github.com/ndarray/ndarray
10 */
11
12#ifndef NDARRAY_ArrayBaseN_h_INCLUDED
13#define NDARRAY_ArrayBaseN_h_INCLUDED
14
21#include "ndarray/ArrayBase.h"
22
23namespace ndarray {
24
28template <typename Derived, int N = ArrayBase<Derived>::ND::value>
29class ArrayBaseN : public ArrayBase< Derived > {
31protected:
32 typedef typename Super::Core Core;
33 typedef typename Super::CorePtr CorePtr;
34public:
35 typedef typename Super::Element Element;
36private:
37 template <typename T_, int N_, int C_> friend class Array;
38 template <typename T_, int N_, int C_> friend class ArrayRef;
39 void operator=(ArrayBaseN const & other) {
40 Super::operator=(other);
41 }
43 ArrayBaseN(Element * data, CorePtr const & core) : Super(data, core) {}
44};
45
46
50template <typename Derived>
51class ArrayBaseN<Derived,1> : public ArrayBase< Derived > {
53protected:
54 typedef typename Super::Core Core;
55 typedef typename Super::CorePtr CorePtr;
56public:
57 typedef typename Super::Element Element;
58
59 Element & operator()(int n0) const {
60 return this->operator[](makeVector(n0));
61 }
62
63private:
64 template <typename T_, int N_, int C_> friend class Array;
65 template <typename T_, int N_, int C_> friend class ArrayRef;
66
67 void operator=(ArrayBaseN const & other) {
68 Super::operator=(other);
69 }
70
71 template <typename Other>
72 ArrayBaseN(ArrayBaseN<Other,1> const & other) : Super(other) {}
73
74 ArrayBaseN(Element * data, CorePtr const & core) : Super(data, core) {}
75};
76
80template <typename Derived>
81class ArrayBaseN<Derived,2> : public ArrayBase< Derived > {
83protected:
84 typedef typename Super::Core Core;
85 typedef typename Super::CorePtr CorePtr;
86public:
87 typedef typename Super::Element Element;
88
89 Element & operator()(int n0, int n1) const {
90 return this->operator[](makeVector(n0, n1));
91 }
92
93private:
94 template <typename T_, int N_, int C_> friend class Array;
95 template <typename T_, int N_, int C_> friend class ArrayRef;
96
97 void operator=(ArrayBaseN const & other) {
98 Super::operator=(other);
99 }
100
101 template <typename Other>
102 ArrayBaseN(ArrayBaseN<Other,2> const & other) : Super(other) {}
103
104 ArrayBaseN(Element * data, CorePtr const & core) : Super(data, core) {}
105};
106
110template <typename Derived>
111class ArrayBaseN<Derived,3> : public ArrayBase< Derived > {
113protected:
114 typedef typename Super::Core Core;
115 typedef typename Super::CorePtr CorePtr;
116public:
117 typedef typename Super::Element Element;
118
119 Element & operator()(int n0, int n1, int n2) const {
120 return this->operator[](makeVector(n0, n1, n2));
121 }
122
123private:
124 template <typename T_, int N_, int C_> friend class Array;
125 template <typename T_, int N_, int C_> friend class ArrayRef;
126
127 void operator=(ArrayBaseN const & other) {
128 Super::operator=(other);
129 }
130
131 template <typename Other>
132 ArrayBaseN(ArrayBaseN<Other,3> const & other) : Super(other) {}
133
134 ArrayBaseN(Element * data, CorePtr const & core) : Super(data, core) {}
135};
136
140template <typename Derived>
141class ArrayBaseN<Derived,4> : public ArrayBase< Derived > {
143protected:
144 typedef typename Super::Core Core;
145 typedef typename Super::CorePtr CorePtr;
146public:
147 typedef typename Super::Element Element;
148
149 Element & operator()(int n0, int n1, int n2, int n3) const {
150 return this->operator[](makeVector(n0, n1, n2, n3));
151 }
152
153private:
154 template <typename T_, int N_, int C_> friend class Array;
155 template <typename T_, int N_, int C_> friend class ArrayRef;
156
157 void operator=(ArrayBaseN const & other) {
158 Super::operator=(other);
159 }
160
161 template <typename Other>
162 ArrayBaseN(ArrayBaseN<Other,4> const & other) : Super(other) {}
163
164 ArrayBaseN(Element * data, CorePtr const & core) : Super(data, core) {}
165};
166
170template <typename Derived>
171class ArrayBaseN<Derived,5> : public ArrayBase< Derived > {
173protected:
174 typedef typename Super::Core Core;
175 typedef typename Super::CorePtr CorePtr;
176public:
177 typedef typename Super::Element Element;
178
179 Element & operator()(int n0, int n1, int n2, int n3, int n4) const {
180 return this->operator[](makeVector(n0, n1, n2, n3, n4));
181 }
182
183private:
184 template <typename T_, int N_, int C_> friend class Array;
185 template <typename T_, int N_, int C_> friend class ArrayRef;
186
187 void operator=(ArrayBaseN const & other) {
188 Super::operator=(other);
189 }
190
191 template <typename Other>
192 ArrayBaseN(ArrayBaseN<Other,5> const & other) : Super(other) {}
193
194 ArrayBaseN(Element * data, CorePtr const & core) : Super(data, core) {}
195};
196
200template <typename Derived>
201class ArrayBaseN<Derived,6> : public ArrayBase< Derived > {
203protected:
204 typedef typename Super::Core Core;
205 typedef typename Super::CorePtr CorePtr;
206public:
207 typedef typename Super::Element Element;
208
209 Element & operator()(int n0, int n1, int n2, int n3, int n4, int n5) const {
210 return this->operator[](makeVector(n0, n1, n2, n3, n4, n5));
211 }
212
213private:
214 template <typename T_, int N_, int C_> friend class Array;
215 template <typename T_, int N_, int C_> friend class ArrayRef;
216
217 void operator=(ArrayBaseN const & other) {
218 Super::operator=(other);
219 }
220
221 template <typename Other>
222 ArrayBaseN(ArrayBaseN<Other,6> const & other) : Super(other) {}
223
224 ArrayBaseN(Element * data, CorePtr const & core) : Super(data, core) {}
225};
226
227} // namespace ndarray
228
229#endif // !NDARRAY_ArrayBaseN_h_INCLUDED
Definitions for ArrayBase.
An intermediate CRTP base class for Array and ArrayRef.
Definition ArrayBaseN.h:29
CRTP implementation for Array and ArrayRef.
Definition ArrayBase.h:43
Reference operator[](Size n) const
Return a single subarray.
Definition ArrayBase.h:75
Traits::Element Element
Data type of array elements.
Definition ArrayBase.h:50
A proxy class for Array with deep assignment operators.
Definition ArrayRef.h:34
A multidimensional strided array.
Definition Array.h:35