range.h
00001 /* Copyright (C) 2003-2005  Martin Förg
00002 
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Lesser General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2.1 of the License, or (at your option) any later version.
00007  * 
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Lesser General Public License for more details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public
00014  * License along with this library; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00016  *
00017  * Contact:
00018  *   martin.o.foerg@googlemail.com
00019  *
00020  */
00021 
00022 #ifndef range_h
00023 #define range_h
00024 
00025 //#include "matrix.h"
00026 #include "types.h"
00027 
00028 namespace fmatvec {
00029 
00035   template <class Row, class Col> class Range {
00036     private:
00037   };
00038 
00044   template <> class Range<Var, Var> {
00045     private:
00046       
00048 
00049     int i1, i2;
00050 
00052 
00053     public:
00054 
00059       inline Range() { i1 = i2 = 0;}
00060 
00066       inline Range(int i1_) : i1(i1_), i2(i1_) { 
00067 #ifndef FMATVEC_NO_BOUNDS_CHECK
00068         assert(i1>=0);
00069 #endif
00070       }
00071 
00078       inline Range(int i1_, int i2_) : i1(i1_), i2(i2_) {
00079 #ifndef FMATVEC_NO_BOUNDS_CHECK
00080         assert(i1>=0);
00081         assert(i2>=i1-1);
00082 #endif
00083       }
00084 
00089       int start() const {return i1;}
00090 
00095       int end() const {return i2;}
00096 
00101       int size() const {return i2-i1+1;}
00102   };
00103 
00104 
00110   template <int I1, int I2> class Range<Fixed<I1>, Fixed<I2> > {
00111     private:
00112       
00113     public:
00114 
00119       int start() const {return I1;}
00120 
00125       int end() const {return I2;}
00126   };
00127 
00133   inline bool operator==(const Range<Var,Var> &I, const Range<Var,Var> &J) {
00134     if(I.start() == J.start() && I.end() == J.end())
00135       return true;
00136     else
00137       return false;
00138   }
00139 
00140   typedef Range<Var,Var> Index;
00141 
00142 }
00143 
00144 #endif