Bridges-C++ 3.5.0-dev2-1-ge3e57bf
Bridges(C++ API)
Array3D.h
Go to the documentation of this file.
1#ifndef ARRAY_3D_H
2#define ARRAY_3D_H
3
4#include "Element.h"
5#include "Array.h"
6
7namespace bridges {
8 namespace datastructure {
41 template <typename E>
42 class Array3D : public Array<E> {
43 private:
44 int num_slices, num_rows, num_cols;
45
46 //preventing the creation of blank array3d
47 Array3D() {
48 num_slices = num_rows = num_cols = 0;
49 }
50 public:
51
52 virtual ~Array3D() {
53 }
54
61 Array3D(int slices, int rows, int columns)
62 : num_slices(slices), num_rows(rows), num_cols(columns) {
63 int dim[] = {slices, rows, columns};
64 this->setSize(3, dim);
65 }
70 int getNumRows () {
71 return num_rows;
72 }
78 return num_cols;
79 }
84 int getNumSlices () {
85 return num_slices;
86 }
87
98 Element<E>& getElement(int slice, int row, int col) {
99 return Array<E>::getElement(slice * num_cols * num_rows + row * num_cols + col);
100 }
101
112 Element<E> const & getElement(int slice, int row, int col) const {
113 return Array<E>::getElement(slice * num_cols * num_rows + row * num_rows + col);
114 }
115
125 void setElement(int slice, int row, int col, Element<E> el) {
126 setElement(slice * num_rows * num_cols + row * num_cols + col, el);
127 }
128
135 int x;
136 int y;
137 Bracket_helper2(Array3D<E>& a, int x, int y) : arr(a), x(x), y(y) {}
138
139 E& operator[] (int z) {
140 return arr.getElement(x, y, z).getValue();
141 }
142 };
143
150 int x;
151 Bracket_helper(Array3D<E>& a, int x) : arr(a), x(x) {}
152
154 return Bracket_helper2(arr, x, y);
155 }
156 };
157
160 return Bracket_helper(*this, index);
161 }
162
169 int x;
170 int y;
171 Bracket_helper2_const(Array3D<E>& a, int x, int y) : arr(a), x(x), y(y) {}
172
173 E const & operator[] (int z) const {
174 return arr.getElement(x, y, z).getValue();
175 }
176 };
177
185 int x;
187
189 return Bracket_helper2(arr, x, y);
190 }
191 };
192
198 return Bracket_helper_const(*this, index);
199 }
200
201 }; // Array3D
202 }
203}// end namespace bridges
204
205#endif
A BRIDGES array type.
Definition: Array3D.h:42
Bracket_helper operator[](int index)
enables using the bracket [] operator
Definition: Array3D.h:159
int getNumRows()
Definition: Array3D.h:70
Element< E > & getElement(int slice, int row, int col)
Definition: Array3D.h:98
Element< E > const & getElement(int slice, int row, int col) const
Definition: Array3D.h:112
void setElement(int slice, int row, int col, Element< E > el)
Definition: Array3D.h:125
int getNumColumns()
Definition: Array3D.h:77
int getNumSlices()
Definition: Array3D.h:84
Array3D(int slices, int rows, int columns)
Definition: Array3D.h:61
virtual ~Array3D()
Definition: Array3D.h:52
The foundation of BRIDGES array types. It is not meant to be used directly by students.
Definition: Array.h:21
void setSize(int nd, int *dim)
Set the size of the array.
Definition: Array.h:57
Element< E > & getElement(int index)
Definition: Array.h:108
This is the fundamental building block for all data structures in BRIDGES.
Definition: Element.h:51
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
helper2 const class is to make [][] operators work on array 2d. You should never use it directly
Definition: Array3D.h:167
Bracket_helper2_const(Array3D< E > &a, int x, int y)
Definition: Array3D.h:171
Array3D< E > const & arr
Definition: Array3D.h:168
E const & operator[](int z) const
Definition: Array3D.h:173
Bracker_helper class to make [][] operators work on array 2d. You should never use it directly.
Definition: Array3D.h:133
E & operator[](int z)
Definition: Array3D.h:139
Array3D< E > & arr
Definition: Array3D.h:134
Bracket_helper2(Array3D< E > &a, int x, int y)
Definition: Array3D.h:137
helper const class is to make [][] operators work on array 2d. You should never use it directly
Definition: Array3D.h:183
Bracket_helper2_const operator[](int y) const
Definition: Array3D.h:188
Bracket_helper_const(Array3D< E > &a, int x)
Definition: Array3D.h:186
Array3D< E > const & arr
Definition: Array3D.h:184
Bracker_helper class to make [] operators work on array 2d. You should never use it directly.
Definition: Array3D.h:148
Bracket_helper(Array3D< E > &a, int x)
Definition: Array3D.h:151
Array3D< E > & arr
Definition: Array3D.h:149
Bracket_helper2 operator[](int y)
Definition: Array3D.h:153