Bridges-C++  3.1.1
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 
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  }
77  int getNumColumns () {
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 
129 
132  int x;
133  int y;
134  Bracket_helper2(Array3D<E>& a, int x, int y) : arr(a), x(x), y(y) {}
135 
136  E& operator[] (int z) {
137  return arr.getElement(x, y, z).getValue();
138  }
139  };
140 
141 
143  struct Bracket_helper {
145  int x;
146  Bracket_helper(Array3D<E>& a, int x) : arr(a), x(x) {}
147 
149  return Bracket_helper2(arr, x, y);
150  }
151  };
152 
155  return Bracket_helper(*this, index);
156  }
157 
159  Array3D<E> const & arr;
160  int x;
161  int y;
162  Bracket_helper2_const(Array3D<E>& a, int x, int y) : arr(a), x(x), y(y) {}
163 
164  E const & operator[] (int z) const {
165  return arr.getElement(x, y, z).getValue();
166  }
167  };
168 
169 
172  Array3D<E> const& arr;
173  int x;
174  Bracket_helper_const(Array3D<E>& a, int x) : arr(a), x(x) {}
175 
177  return Bracket_helper2(arr, x, y);
178  }
179  };
180 
183  return Bracket_helper_const(*this, index);
184  }
185 
186  }; // Array3D
187  }
188 }// end namespace bridges
189 
190 #endif
Element< E > const & getElement(int slice, int row, int col) const
Definition: Array3D.h:112
This is the fundamental building block for all data structures in BRIDGES.
Definition: Element.h:44
Array3D< E > & arr
Definition: Array3D.h:144
Array3D(int slices, int rows, int columns)
Definition: Array3D.h:61
Element< E > & getElement(int slice, int row, int col)
Definition: Array3D.h:98
Array3D< E > const & arr
Definition: Array3D.h:172
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:84
helper class to make [][] operators work on array 2d. You should never use it directly ...
Definition: Array3D.h:143
E & operator[](int z)
Definition: Array3D.h:136
void setElement(int slice, int row, int col, Element< E > el)
Definition: Array3D.h:125
int getNumRows()
Definition: Array3D.h:70
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:162
void setSize(int nd, int *dim)
Set the size of the array.
Definition: Array.h:55
Bracket_helper(Array3D< E > &a, int x)
Definition: Array3D.h:146
A BRIDGES array type.
Definition: Array3D.h:43
helper class to make [][] operators work on array 2d. You should never use it directly ...
Definition: Array3D.h:171
Element< E > & getElement(int index)
Definition: Array.h:106
virtual ~Array3D()
Definition: Array3D.h:54
Bracket_helper2(Array3D< E > &a, int x, int y)
Definition: Array3D.h:134
Bracket_helper_const(Array3D< E > &a, int x)
Definition: Array3D.h:174
Array3D< E > const & arr
Definition: Array3D.h:159
int getNumColumns()
Definition: Array3D.h:77
Array3D< E > & arr
Definition: Array3D.h:131