Lapack++
|
00001 // -*-C++-*- 00002 00003 // Copyright (C) 2004 00004 // Christian Stimming <stimming@tuhh.de> 00005 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public License as 00008 // published by the Free Software Foundation; either version 2, or (at 00009 // your option) any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU Lesser General Public License for more details. 00015 00016 // You should have received a copy of the GNU Lesser General Public License along 00017 // with this library; see the file COPYING. If not, write to the Free 00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00019 // USA. 00020 00021 // LAPACK++ (V. 1.1) 00022 // (C) 1992-1996 All Rights Reserved. 00023 00028 #ifndef _LA_INDEX_H_ 00029 #define _LA_INDEX_H_ 00030 00031 #include <iostream> 00032 #include "arch.h" 00033 00043 class DLLIMPORT LaIndex 00044 { 00045 private: 00046 friend class LaGenMatDouble; 00047 friend class LaGenMatFloat; 00048 friend class LaGenMatInt; 00049 friend class LaGenMatLongInt; 00050 friend class LaGenMatComplex; 00051 int start_; 00052 int inc_; 00053 int end_; 00054 public: 00065 inline LaIndex() 00066 : start_(0) 00067 , inc_(0) 00068 , end_(0) 00069 {} 00070 00076 inline LaIndex(int start) 00077 : start_(start) 00078 , inc_(1) 00079 , end_(start) 00080 {} 00081 00091 LaIndex(int start, int end); 00092 00112 LaIndex(int start, int end, int increment); 00113 00115 inline LaIndex(const LaIndex &s) 00116 : start_(s.start_) 00117 , inc_(s.inc_) 00118 , end_(s.end_) 00119 {} 00120 00121 protected: 00122 // must have multply defined start(), inc() and end() member 00123 // functions for both const and non-const objects because 00124 // compiler complains in LaVector*.h, for example, about 00125 // assignment to const member. (LaVector*.h line 112, 113, 00126 // 114) FIXME: Probably we should return by-value, not 00127 // by-reference! 00132 inline int& start() 00133 { 00134 return start_; 00135 } 00139 inline int& inc() 00140 { 00141 return inc_; 00142 } 00148 inline int& end() 00149 { 00150 return end_; 00151 } 00152 public: 00153 00156 inline int start() const 00157 { 00158 return start_; 00159 } 00160 00162 inline int inc() const 00163 { 00164 return inc_; 00165 } 00166 00175 inline int end() const 00176 { 00177 return end_; 00178 } 00179 00182 inline int length() const 00183 { 00184 return ((end() - start()) / inc() + 1); 00185 } 00186 00189 inline bool null() const 00190 { 00191 return (start() == 0 && 00192 inc() == 0 && end() == 0); 00193 } 00194 00195 protected: 00208 inline LaIndex& operator()(int start, int end) 00209 { 00210 start_ = start; 00211 inc_ = 1; 00212 end_ = end; 00213 return *this; 00214 } 00215 public: 00216 00226 inline LaIndex& set(int start, int end) 00227 { 00228 start_ = start; 00229 inc_ = 1; 00230 end_ = end; 00231 return *this; 00232 } 00233 00255 LaIndex& set(int start, int end, int increment); 00256 00261 inline LaIndex& operator+=(int i) 00262 { 00263 start_ += i; 00264 end_ += i; 00265 return *this; 00266 } 00267 00272 inline LaIndex operator+(int i) 00273 { 00274 LaIndex r(*this); 00275 r.start_ += i; 00276 r.end_ += i; 00277 return r; 00278 } 00279 00281 inline LaIndex& operator=(const LaIndex& i) 00282 { 00283 start_ = i.start_; 00284 inc_ = i.inc_; 00285 end_ = i.end_; 00286 return *this; 00287 } 00288 00290 inline bool operator==(const LaIndex& s) 00291 { 00292 return start_ == s.start_ && inc_ == s.inc_ && end_ == s.end_; 00293 } 00295 inline bool operator!=(const LaIndex& s) 00296 { 00297 return !operator==(s); 00298 } 00299 }; 00300 00301 inline std::ostream& operator<<(std::ostream& s, const LaIndex& i) 00302 { 00303 s << "(" << i.start() << ":" << i.inc() << ":" << i.end() << ")"; 00304 00305 return s; 00306 } 00307 00308 #endif 00309 // LA_INDEX_H_ 00310