C:/programs/SCPPNT/src/include/index.h

Go to the documentation of this file.
00001 /*! \file index.h
00002  \brief Definition of Index1D class that represents in index range.
00003  
00004  */
00005 
00006 /*
00007  Simple C++ Numerical Toolkit (SCPPNT)
00008  http://www.smallwaters.com/software/cpp/scppnt.html
00009  This release updates original work contributed by 
00010  Brad Hanson (http://www.b-a-h.com/)
00011 
00012  */
00013 
00014 // Modified from index.h in:
00015 /*
00016  *
00017  * Template Numerical Toolkit (TNT): Linear Algebra Module
00018  *
00019  * Mathematical and Computational Sciences Division
00020  * National Institute of Technology,
00021  * Gaithersburg, MD USA
00022  *
00023  *
00024  * This software was developed at the National Institute of Standards and
00025  * Technology (NIST) by employees of the Federal Government in the course
00026  * of their official duties. Pursuant to title 17 Section 105 of the
00027  * United States Code, this software is not subject to copyright protection
00028  * and is in the public domain.  The Template Numerical Toolkit (TNT) is
00029  * an experimental system.  NIST assumes no responsibility whatsoever for
00030  * its use by other parties, and makes no guarantees, expressed or implied,
00031  * about its quality, reliability, or any other characteristic.
00032  *
00033  * BETA VERSION INCOMPLETE AND SUBJECT TO CHANGE
00034  * see http://math.nist.gov/tnt for latest updates.
00035  *
00036  */
00037 
00038 // Vector/Matrix/Array Index Module  
00039 
00040 #ifndef SCPPNT_INDEX_H
00041 #define SCPPNT_INDEX_H
00042 
00043 #ifdef SCPPNT_NO_DIR_PREFIX
00044 #include "scppnt.h"
00045 #else
00046 #include "scppnt/scppnt.h"
00047 #endif
00048 
00049 namespace SCPPNT
00050 {
00051 
00052   //! Represents a consecutive index range (a 1-offset lower and upper index)
00053   class Index1D
00054   {
00055     Subscript lbound_; //!< Lower bound of range (1-offset)
00056     Subscript ubound_; //!< Upper bound of range (1-offset)
00057 
00058 public:
00059 
00060     Subscript lbound() const
00061     {
00062       return lbound_;
00063     }
00064     Subscript ubound() const
00065     {
00066       return ubound_;
00067     }
00068 
00069     Index1D(const Index1D &D) :
00070       lbound_(D.lbound_), ubound_(D.ubound_)
00071     {
00072     }
00073     Index1D(Subscript i1, Subscript i2) :
00074       lbound_(i1), ubound_(i2)
00075     {
00076     }
00077 
00078     Index1D & operator=(const Index1D &D)
00079     {
00080       lbound_ = D.lbound_;
00081       ubound_ = D.ubound_;
00082       return *this;
00083     }
00084 
00085   };
00086 
00087   //! Increment index range by i (increase both lower and upper limits by i)
00088   inline Index1D operator+(const Index1D &D, Subscript i)
00089   {
00090     return Index1D(i+D.lbound(), i+D.ubound());
00091   }
00092 
00093   //! Increment index range by i (increase both lower and upper limits by i)
00094   inline Index1D operator+(Subscript i, const Index1D &D)
00095   {
00096     return Index1D(i+D.lbound(), i+D.ubound());
00097   }
00098 
00099   //! Decrement index range by i (decrease both lower and upper limits by i)
00100   inline Index1D operator-(Index1D &D, Subscript i)
00101   {
00102     return Index1D(D.lbound()-i, D.ubound()-i);
00103   }
00104 
00105   //! Decrement index range by i (decrease both lower and upper limits by i)
00106   inline Index1D operator-(Subscript i, Index1D &D)
00107   {
00108     return Index1D(i-D.lbound(), i-D.ubound());
00109   }
00110 
00111 } // namespace SCPPNT
00112 
00113 #endif
00114 

Generated on Tue Dec 18 23:34:05 2007 for SCPPNT by  doxygen 1.5.4