index3D.h
Go to the documentation of this file.00001
00015 #ifndef DLR_NUMERIC_INDEX3D_H
00016 #define DLR_NUMERIC_INDEX3D_H
00017
00018 #include <iostream>
00019 #include <dlrCommon/exception.h>
00020
00021 namespace dlr {
00022
00023 namespace numeric {
00031 class Index3D {
00032 public:
00033
00037 Index3D()
00038 : m_column(0), m_row(0), m_slice(0) {}
00039
00040
00050 Index3D(int slice, int row, int column)
00051 : m_column(column), m_row(row), m_slice(slice) {}
00052
00053
00060 Index3D(const Index3D& other)
00061 : m_column(other.m_column), m_row(other.m_row), m_slice(other.m_slice)
00062 {}
00063
00064
00068 ~Index3D() {}
00069
00070
00080 inline void setValue(int slice, int row, int column) {
00081 m_column = column; m_row = row; m_slice = slice;
00082 }
00083
00084
00091 inline int getColumn() const {return m_column;}
00092
00093
00100 inline int getRow() const {return m_row;}
00101
00102
00109 inline int getSlice() const {return m_slice;}
00110
00111
00118 inline int getU() const {return this->getColumn();}
00119
00120
00127 inline int getV() const {return this->getRow();}
00128
00129
00137 inline int getW() const {return this->getSlice();}
00138
00139
00149 Index3D& operator=(const Index3D& other) {
00150
00151 this->setValue(other.m_slice, other.m_row, other.m_column);
00152 return *this;
00153 }
00154
00155
00156
00166 int operator[](size_t index) const {
00167 switch(index) {
00168 case 0: return this->getColumn(); break;
00169 case 1: return this->getRow(); break;
00170 }
00171 return this->getSlice();
00172 }
00173
00174
00184 Index3D& operator*=(int scalar) {
00185 m_column *= scalar; m_row *= scalar; m_slice *= scalar; return *this;
00186 }
00187
00188
00198 Index3D& operator/=(int scalar) {
00199 if (scalar == 0 ) {
00200 DLR_THROW(ValueException, "Index3D::operator/=()",
00201 "Bad scalar: Divide by Zero\n");
00202 }
00203 m_column /= scalar; m_row /= scalar; m_slice /= scalar; return *this;
00204 }
00205
00206
00216 Index3D& operator+=(const Index3D& other) {
00217 m_column += other.m_column; m_row += other.m_row;
00218 m_slice += other.m_slice; return *this;
00219 }
00220
00221
00231 Index3D& operator-=(const Index3D& other) {
00232 m_column -= other.m_column; m_row -= other.m_row;
00233 m_slice -= other.m_slice; return *this;
00234 }
00235
00236
00243 Index3D operator-() {
00244 return Index3D(-m_row, -m_column, -m_slice);
00245 }
00246
00247 private:
00248
00249
00250 int m_column;
00251 int m_row;
00252 int m_slice;
00253 };
00254
00255
00256
00257
00268 Index3D
00269 operator+(const Index3D& index0, const Index3D& index1);
00270
00283 Index3D
00284 operator-(const Index3D& index0, const Index3D& index1);
00285
00296 Index3D
00297 operator*(const Index3D& index0, const Index3D& index1);
00298
00310 Index3D
00311 operator/(const Index3D& index0, const Index3D& index1);
00312
00324 Index3D operator+(const Index3D& index0, int scalar0);
00325
00337 Index3D operator-(const Index3D& index0, int scalar0);
00338
00350 Index3D operator*(const Index3D& index0, int scalar0);
00351
00363 Index3D operator/(const Index3D& index0, int scalar0);
00364
00372 bool operator==(const Index3D& index0, const Index3D& index1);
00373
00382 bool operator!=(const Index3D& index0, const Index3D& index1);
00383
00384
00397 Index3D operator+(int scalar0, const Index3D& index0);
00398
00399
00412 Index3D operator*(int scalar0, const Index3D& index0);
00413
00414
00430 std::ostream& operator<<(std::ostream& stream, const Index3D& index0);
00431
00432
00447 std::istream& operator>>(std::istream& stream, Index3D& index0);
00448
00449 }
00450
00451 }
00452
00453
00454
00455
00456 namespace dlr {
00457
00458 namespace numeric {
00459
00460 inline Index3D operator+(int scalar0, const Index3D& index0)
00461 {
00462 return index0 + scalar0;
00463 }
00464
00465 inline Index3D operator*(int scalar0, const Index3D& index0)
00466 {
00467 return index0 * scalar0;
00468 }
00469
00470 }
00471
00472 }
00473
00474 #endif // #ifndef DLR_NUMERIC_INDEX3D_H