00001
00015 #ifndef _DLR_NUMERIC_INDEX2D_H_
00016 #define _DLR_NUMERIC_INDEX2D_H_
00017
00018 #include <iostream>
00019 #include <dlrCommon/exception.h>
00020
00021 namespace dlr {
00022
00023 namespace numeric {
00024
00029 class Index2D {
00030 public:
00031
00035 Index2D()
00036 : m_column(0), m_row(0) {}
00037
00038
00046 Index2D(int row, int column)
00047 : m_column(column), m_row(row) {}
00048
00049
00056 Index2D(const Index2D& other)
00057 : m_column(other.m_column), m_row(other.m_row) {}
00058
00059
00063 ~Index2D() {}
00064
00065
00073 inline void setValue(int row, int column) {
00074 m_column = column; m_row = row;
00075 }
00076
00077
00084 inline int getColumn() const {return m_column;}
00085
00086
00093 inline int getRow() const {return m_row;}
00094
00095
00105 Index2D& operator=(const Index2D& other) {
00106
00107 setValue(other.m_row, other.m_column); return *this;
00108 }
00109
00110
00120 Index2D& operator*=(int scalar) {
00121 m_column *= scalar; m_row *= scalar; return *this;
00122 }
00123
00124
00134 Index2D& operator/=(int scalar) {
00135 if (scalar == 0 ) {
00136 DLR_THROW(ValueException, "Index2D::operator/=()",
00137 "Bad scalar: Divide by Zero\n");
00138 }
00139 m_column /= scalar; m_row /= scalar; return *this;
00140 }
00141
00142
00152 Index2D& operator+=(const Index2D& other) {
00153 m_column += other.m_column; m_row += other.m_row; return *this;
00154 }
00155
00156
00166 Index2D& operator-=(const Index2D& other) {
00167 m_column -= other.m_column; m_row -= other.m_row; return *this;
00168 }
00169
00170
00177 Index2D operator-() {
00178 return Index2D(-m_row, -m_column);
00179 }
00180
00181 private:
00182
00183
00184 int m_column;
00185 int m_row;
00186 };
00187
00188
00189
00190
00201 Index2D
00202 operator+(const Index2D& index0, const Index2D& index1);
00203
00216 Index2D
00217 operator-(const Index2D& index0, const Index2D& index1);
00218
00229 Index2D
00230 operator*(const Index2D& index0, const Index2D& index1);
00231
00243 Index2D
00244 operator/(const Index2D& index0, const Index2D& index1);
00245
00257 Index2D operator+(const Index2D& index0, int scalar0);
00258
00270 Index2D operator-(const Index2D& index0, int scalar0);
00271
00283 Index2D operator*(const Index2D& index0, int scalar0);
00284
00296 Index2D operator/(const Index2D& index0, int scalar0);
00297
00305 bool operator==(const Index2D& index0, const Index2D& index1);
00306
00315 bool operator!=(const Index2D& index0, const Index2D& index1);
00316
00317
00330 Index2D operator+(int scalar0, const Index2D& index0);
00331
00332
00345 Index2D operator*(int scalar0, const Index2D& index0);
00346
00347
00363 std::ostream& operator<<(std::ostream& stream, const Index2D& index0);
00364
00365
00380 std::istream& operator>>(std::istream& stream, Index2D& index0);
00381
00382 }
00383
00384 }
00385
00386
00387
00388
00389 namespace dlr {
00390
00391 using numeric::Index2D;
00392
00393 }
00394
00395
00396
00397
00398 namespace dlr {
00399
00400 namespace numeric {
00401
00402 inline Index2D operator+(int scalar0, const Index2D& index0)
00403 {
00404 return index0 + scalar0;
00405 }
00406
00407 inline Index2D operator*(int scalar0, const Index2D& index0)
00408 {
00409 return index0 * scalar0;
00410 }
00411
00412 }
00413
00414 }
00415
00416 #endif // #ifndef _DLR_NUMERIC_INDEX2D_H_