index2D.h

Go to the documentation of this file.
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     
00050     class Index2D {
00051     public:
00052 
00056       Index2D()
00057         : m_column(0), m_row(0) {}
00058     
00059 
00067       Index2D(int row, int column)
00068         : m_column(column), m_row(row) {}
00069 
00070 
00077       Index2D(const Index2D& other)
00078         : m_column(other.m_column), m_row(other.m_row) {}
00079 
00080 
00084       ~Index2D() {}
00085 
00086 
00094       inline void setValue(int row, int column) {
00095         m_column = column; m_row = row;
00096       }
00097 
00098 
00105       inline int getColumn() const {return m_column;}
00106 
00107 
00114       inline int getRow() const {return m_row;}
00115 
00116     
00123       inline int getU() const {return this->getColumn();}
00124 
00125 
00132       inline int getV() const {return this->getRow();}
00133 
00134     
00144       Index2D& operator=(const Index2D& other) {
00145         // Self-assignment is OK.
00146         setValue(other.m_row, other.m_column); return *this;
00147       }
00148 
00149 
00173       int operator[](size_t index) const {
00174         switch(index) {
00175         case 0: return this->getColumn(); break;
00176         }
00177         return this->getRow();
00178       }
00179         
00180 
00190       Index2D& operator*=(int scalar) {
00191         m_column *= scalar; m_row *= scalar; return *this;
00192       }
00193 
00194 
00204       Index2D& operator/=(int scalar) {
00205         if (scalar == 0 ) {
00206           DLR_THROW(ValueException, "Index2D::operator/=()",
00207                     "Bad scalar: Divide by Zero\n");
00208         }
00209         m_column /= scalar; m_row /= scalar; return *this;
00210       }
00211 
00212 
00222       Index2D& operator+=(const Index2D& other) {
00223         m_column += other.m_column; m_row += other.m_row; return *this;
00224       }
00225 
00226 
00236       Index2D& operator-=(const Index2D& other) {
00237         m_column -= other.m_column; m_row -= other.m_row; return *this;
00238       }
00239 
00240     
00247       Index2D operator-() {
00248         return Index2D(-m_row, -m_column);
00249       }
00250     
00251     private:
00252 
00253       // Private data members.
00254       int m_column;
00255       int m_row;
00256     }; // class Index2D
00257 
00258 
00259     /* ============== Non-member function declarations ============== */
00260   
00271     Index2D
00272     operator+(const Index2D& index0, const Index2D& index1);
00273 
00286     Index2D
00287     operator-(const Index2D& index0, const Index2D& index1);
00288   
00299     Index2D
00300     operator*(const Index2D& index0, const Index2D& index1);
00301 
00313     Index2D
00314     operator/(const Index2D& index0, const Index2D& index1);
00315 
00327     Index2D operator+(const Index2D& index0, int scalar0);
00328 
00340     Index2D operator-(const Index2D& index0, int scalar0);
00341 
00353     Index2D operator*(const Index2D& index0, int scalar0);
00354 
00366     Index2D operator/(const Index2D& index0, int scalar0);
00367 
00375     bool operator==(const Index2D& index0, const Index2D& index1);
00376 
00385     bool operator!=(const Index2D& index0, const Index2D& index1);
00386 
00387 
00400     Index2D operator+(int scalar0, const Index2D& index0);
00401 
00402 
00415     Index2D operator*(int scalar0, const Index2D& index0);
00416 
00417   
00433     std::ostream& operator<<(std::ostream& stream, const Index2D& index0);
00434 
00435   
00450     std::istream& operator>>(std::istream& stream, Index2D& index0);
00451 
00452   } // namespace numeric
00453 
00454 } // namespace dlr
00455 
00456 
00457 /* ======= Declarations to maintain compatibility with legacy code. ======= */
00458 
00459 namespace dlr {
00460 
00461   using numeric::Index2D;
00462 
00463 } // namespace dlr
00464 
00465 
00466 /* ============ Definitions of inline & template functions ============ */
00467 
00468 namespace dlr {
00469 
00470   namespace numeric {
00471     
00472     inline Index2D operator+(int scalar0, const Index2D& index0)
00473     {
00474       return index0 + scalar0;
00475     }
00476   
00477     inline Index2D operator*(int scalar0, const Index2D& index0)
00478     {
00479       return index0 * scalar0;
00480     }
00481 
00482   } // namespace numeric
00483 
00484 } // namespace dlr
00485 
00486 #endif // #ifndef _DLR_NUMERIC_INDEX2D_H_

Generated on Wed Nov 25 00:42:42 2009 for dlrUtilities Utility Library by  doxygen 1.5.8