Bridges-C++  3.2.0
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 
7 
8 namespace bridges {
9  namespace datastructure {
42  template <typename E>
43  class Array3D : public Array<E> {
44  private:
45  int num_slices, num_rows, num_cols;
46 
47  //preventing the creation of blank array3d
48  Array3D() {
49  num_slices = num_rows = num_cols = 0;
50  }
51  public:
52 
53 
54  virtual ~Array3D() {
55  }
56 
63  Array3D(int slices, int rows, int columns)
64  : num_slices(slices), num_rows(rows), num_cols(columns) {
65  int dim[] = {slices, rows, columns};
66  this->setSize(3, dim);
67  }
72  int getNumRows () {
73  return num_rows;
74  }
79  int getNumColumns () {
80  return num_cols;
81  }
86  int getNumSlices () {
87  return num_slices;
88  }
89 
100  Element<E>& getElement(int slice, int row, int col) {
101  return Array<E>::getElement(slice * num_cols * num_rows + row * num_cols + col);
102  }
103 
114  Element<E> const & getElement(int slice, int row, int col) const {
115  return Array<E>::getElement(slice * num_cols * num_rows + row * num_rows + col);
116  }
117 
127  void setElement(int slice, int row, int col, Element<E> el) {
128  setElement(slice * num_rows * num_cols + row * num_cols + col, el);
129  }
130 
131 
138  int x;
139  int y;
140  Bracket_helper2(Array3D<E>& a, int x, int y) : arr(a), x(x), y(y) {}
141 
142  E& operator[] (int z) {
143  return arr.getElement(x, y, z).getValue();
144  }
145  };
146 
147 
152  struct Bracket_helper {
154  int x;
155  Bracket_helper(Array3D<E>& a, int x) : arr(a), x(x) {}
156 
158  return Bracket_helper2(arr, x, y);
159  }
160  };
161 
164  return Bracket_helper(*this, index);
165  }
166 
172  Array3D<E> const & arr;
173  int x;
174  int y;
175  Bracket_helper2_const(Array3D<E>& a, int x, int y) : arr(a), x(x), y(y) {}
176 
177  E const & operator[] (int z) const {
178  return arr.getElement(x, y, z).getValue();
179  }
180  };
181 
182 
187  struct Bracket_helper_const {
189  Array3D<E> const& arr;
190  int x;
191  Bracket_helper_const(Array3D<E>& a, int x) : arr(a), x(x) {}
192 
194  return Bracket_helper2(arr, x, y);
195  }
196  };
197 
203  return Bracket_helper_const(*this, index);
204  }
205 
206  }; // Array3D
207  }
208 }// end namespace bridges
209 
210 #endif
Element< E > const & getElement(int slice, int row, int col) const
Definition: Array3D.h:114
This is the fundamental building block for all data structures in BRIDGES.
Definition: Element.h:52
Bracker_helper class to make [][] operators work on array 2d. You should never use it directly...
Definition: Array3D.h:136
Array3D< E > & arr
Definition: Array3D.h:153
Array3D(int slices, int rows, int columns)
Definition: Array3D.h:63
Element< E > & getElement(int slice, int row, int col)
Definition: Array3D.h:100
Array3D< E > const & arr
Definition: Array3D.h:189
The foundation of BRIDGES array types. It is not meant to be used directly by students.
Definition: Array.h:21
int getNumSlices()
Definition: Array3D.h:86
Bracker_helper class to make [] operators work on array 2d. You should never use it directly...
Definition: Array3D.h:152
E & operator[](int z)
Definition: Array3D.h:142
void setElement(int slice, int row, int col, Element< E > el)
Definition: Array3D.h:127
int getNumRows()
Definition: Array3D.h:72
helper2 const class is to make [][] operators work on array 2d. You should never use it directly ...
Definition: Array3D.h:171
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
Bracket_helper2_const(Array3D< E > &a, int x, int y)
Definition: Array3D.h:175
void setSize(int nd, int *dim)
Set the size of the array.
Definition: Array.h:57
Bracket_helper(Array3D< E > &a, int x)
Definition: Array3D.h:155
A BRIDGES array type.
Definition: Array3D.h:43
helper const class is to make [][] operators work on array 2d. You should never use it directly ...
Definition: Array3D.h:188
Element< E > & getElement(int index)
Definition: Array.h:108
virtual ~Array3D()
Definition: Array3D.h:54
Bracket_helper2(Array3D< E > &a, int x, int y)
Definition: Array3D.h:140
Bracket_helper_const(Array3D< E > &a, int x)
Definition: Array3D.h:191
Array3D< E > const & arr
Definition: Array3D.h:172
int getNumColumns()
Definition: Array3D.h:79
Array3D< E > & arr
Definition: Array3D.h:137