|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004-2009 Serge Iovleff 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as 00006 published by the Free Software Foundation; either version 2 of the 00007 License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this program; if not, write to the 00016 Free Software Foundation, Inc., 00017 59 Temple Place, 00018 Suite 330, 00019 Boston, MA 02111-1307 00020 USA 00021 00022 Contact : Serge.Iovleff@stkpp.org 00023 */ 00024 00025 /* 00026 * Project: stkpp::STKernel::Base 00027 * Purpose: Define the Range class. 00028 * Author: Serge Iovleff, serge.iovleff@stkpp.org 00029 * 00030 **/ 00031 00037 #ifndef STK_RANGE_H 00038 #define STK_RANGE_H 00039 00040 #include "STK_Integer.h" 00041 #include "STK_Stream.h" 00042 00043 namespace STK 00044 { 00062 class Range 00063 { 00064 private: 00065 Integer first_; 00066 Integer last_; 00067 Integer size_; 00068 00069 public: 00073 Range(Integer const& last =0); 00074 00079 Range(Integer const& first, Integer const& last); 00080 00084 Range(Range const& I); 00085 00087 ~Range(); 00088 00092 inline Integer const& first() const { return first_;}; 00096 inline Integer const& last() const { return last_;}; 00100 inline Integer const& size() const { return size_;}; 00104 inline bool empty() const { return size_<=0;}; 00109 inline bool isIn(Range const& I) const 00110 { return ((first_>= I.first_)&&(last_<=I.last_));} 00115 inline bool isContaining(Range const& I) const 00116 { return ((first_<= I.first_)&&(last_>=I.last_));} 00121 inline bool isContaining(Integer const& i) const 00122 { return ((first_<=i)&&(last_>=i));} 00127 inline bool operator==(Range const& I) const 00128 { return ((first_ == I.first()) && (last_ == I.last()));} 00133 inline bool operator!=(Range const& I) const 00134 { return ((first_ != I.first()) || (last_ != I.last()));} 00135 00137 Range& set(Integer const& first =1, Integer const& last =0); 00139 Range& shift(Integer const& first =1); 00141 Range& inc(Integer const& inc =1); 00143 Range& incFirst(Integer const& inc =1); 00145 Range& incLast(Integer const& inc =1); 00147 Range& dec(Integer const& dec =1); 00149 Range& decFirst(Integer const& dec =1); 00151 Range& decLast(Integer const& dec =1); 00153 Range& sup(Range const& I); 00155 Range& inf(Range const& I); 00157 Range& operator+=(Integer const& inc); 00159 Range& operator-=(Integer const& dec); 00160 00162 Range plus(Integer const& inc =1); 00164 Range minus(Integer const& dec =1); 00165 00167 static Range sup(Range const& I, Range const& J); 00169 static Range inf(Range const& I, Range const& J); 00172 friend ostream& operator<< (ostream& s, Range const& I); 00175 friend istream& operator>> (istream& s, Range& I); 00176 }; 00177 00182 Range operator-(Range const& I, Integer const& dec); 00183 00188 Range operator+(Range const& I, Integer const& inc); 00189 00190 } // Namespace STK 00191 00192 #endif // STK_RANGE_H