STK_Inx.cpp

Go to the documentation of this file.
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 /* $Id$
00026  *
00027  * Project:  Tcontainer
00028  * Purpose:  implement the Inx class.
00029  * Author:   Serge Iovleff, serge.iovleff@stkpp.org
00030  *
00031  * $Log$
00032  * Revision 1.4  2009/09/14 13:33:38  siovleff
00033  * Refactoring Contant strings
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 /* Manipulation of the index.                                         */
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_); // use the inc method
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 /* Ops on the class Inx.                                              */
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 } // Namespace STK
Generated on Sat Sep 18 17:26:51 2010 for STK++ by  doxygen 1.6.3