STK_Inx.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00042 #include "../include/STK_Inx.h"
00043 #include "../include/STK_Misc.h"
00044
00045 namespace STK
00046 {
00047
00051 Inx::Inx( const Integer& last)
00052 : first_(1)
00053 , last_(last)
00054 , size_(last)
00055 { ;}
00056
00062 Inx::Inx( const Integer& first, const Integer& last)
00063 : first_(first)
00064 , last_(last)
00065 , size_(last-first+1)
00066 { ;}
00067
00068
00072 Inx::Inx( const Inx &I)
00073 : first_(I.first())
00074 , last_(I.last())
00075 , size_(I.size())
00076 { ;}
00077
00078 Inx::~Inx() { ;}
00079
00080
00081
00086 Inx& Inx::set(const Integer& first, const Integer& last)
00087 {
00088 first_ = first;
00089 last_ = last;
00090 size_ = last - first + 1;
00091 return *this;
00092 }
00093
00097 Inx& Inx::shift(const Integer& first)
00098 {
00099 return inc(first - first_);
00100 }
00101
00105 Inx& Inx::inc(const Integer& inc)
00106 {
00107 first_ +=inc;
00108 last_ +=inc;
00109 return *this;
00110 }
00114 Inx& Inx::incFirst(const Integer& inc)
00115 {
00116 first_ +=inc;
00117 size_ -=inc;
00118 return *this;
00119 }
00123 Inx& Inx::incLast(const Integer& inc)
00124 {
00125 last_ +=inc;
00126 size_ +=inc;
00127 return *this;
00128 }
00129
00133 Inx& Inx::dec(const Integer& dec)
00134 {
00135 first_ -=dec;
00136 last_ -=dec;
00137 return *this;
00138 }
00142 Inx& Inx::decFirst(const Integer& dec)
00143 {
00144 first_ -=dec;
00145 size_ +=dec;
00146 return *this;
00147 }
00151 Inx& Inx::decLast(const Integer& dec)
00152 {
00153 last_ -=dec;
00154 size_ -=dec;
00155 return *this;
00156 }
00157
00162 Inx& Inx::sup(const Inx& I)
00163 {
00164 first_ = min(first_, I.first_);
00165 last_ = max(last_, I.last_);
00166 size_ = last_ - first_ +1;
00167 return *this;
00168 }
00169
00174 Inx& Inx::inf(const Inx& I)
00175 {
00176 first_ = max(first_, I.first_);
00177 last_ = min(last_, I.last_);
00178 size_ = last_ - first_ +1;
00179 return *this;
00180 }
00186 Inx Inx::sup(const Inx& I, const Inx& J)
00187 {
00188 return Inx(min(I.first_, J.first_), max(I.last_, J.last_));
00189 }
00190
00196 Inx Inx::inf(const Inx& I, const Inx& J)
00197 {
00198 return Inx(max(I.first_, J.first_), min(I.last_, J.last_));
00199 }
00200
00201
00202
00206 Inx& Inx::operator+=(const Integer& inc)
00207 { first_ += inc; last_ += inc; return *this;}
00208
00212 Inx& Inx::operator-=(const Integer& dec)
00213 { first_ -= dec; last_ -= dec; return *this;}
00214
00219 Inx Inx::operator+(const Integer& inc) const
00220 {return Inx(first_+inc, last_+inc);}
00221
00225 Inx Inx::operator-(const Integer& dec) const
00226 {return Inx(first_-dec, last_-dec);}
00227
00232 ostream& operator<< (ostream& s, const Inx& I)
00233 {
00234 s << I.first_ << ":" << I.last_;
00235 return s;
00236 }
00237
00238 }