STK++ 1.0
STK_IContainer2D.h
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------*/
00002 /*     Copyright (C) 2004-2007  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::Sdk::TContainer
00027  * Purpose:  Define the interface 2D Container classes.
00028  * Author:   Serge Iovleff, serge.iovleff@stkpp.org
00029  *
00030  **/
00031 
00041 #ifndef STK_ICONTAINER2D_H
00042 #define STK_ICONTAINER2D_H
00043 
00044 #include "../../STKernel/include/STK_Range.h"
00045 
00046 namespace STK
00047 {
00067 class IContainer2D
00068 {
00069   protected:
00074     IContainer2D( Range const& I = Range(), Range const& J =  Range())
00075                 : rangeHo_(J)
00076                 , rangeVe_(I)
00077     { ;}
00078 
00082     IContainer2D( const IContainer2D &T)
00083                 : rangeHo_(T.rangeHo_)
00084                 , rangeVe_(T.rangeVe_)
00085     { ;}
00086 
00088     ~IContainer2D() { ;}
00089 
00090   public:
00094     inline Integer const& firstCol() const { return rangeHo_.first();}
00098     inline Integer const& lastCol() const { return rangeHo_.last();}
00102     inline Integer const& sizeHo() const { return rangeHo_.size();}
00106     inline Range const& rangeHo() const { return rangeHo_;};
00110     inline Integer const& firstRow() const { return rangeVe_.first();}
00114     inline Integer const& lastRow() const { return rangeVe_.last();}
00118     inline Integer const& sizeVe() const { return rangeVe_.size();}
00122     inline Range const& rangeVe() const { return rangeVe_;}
00126     inline bool empty() const { return (rangeHo_.empty() || rangeVe_.empty());}
00127 
00137     void resize( Range const& I, Range const& J)
00138     {
00139       // check if there is something to do
00140       if ((rangeVe_ == I) && (rangeHo_ == J)) return;
00141       //  translate beg
00142       shift(I.first(), J.first());
00143       // number of rows to del or add
00144       Integer rinc = I.last() - lastRow();
00145       // number of cols to del or add
00146       Integer cinc = J.last() - lastCol();
00147       // check if we add cols
00148       if (cinc >=0)   // work first on rows
00149       {
00150         if (rinc < 0) popBackRows(-rinc); // less rows
00151         else          pushBackRows(rinc); // more rows
00152         pushBackCols(cinc); // add columns
00153       }
00154       else // work first on columns
00155       {
00156         popBackCols(-cinc); // remove columns
00157         if (rinc < 0) popBackRows(-rinc); // less rows
00158         else          pushBackRows(rinc); // more rows
00159       }
00160     }
00161 
00166      virtual void eraseCols(Integer const& pos, Integer const& n = 1) =0;
00167 
00172      virtual void eraseRows(Integer const& pos, Integer const& n=1) =0;
00173 
00177      virtual void popBackCols( Integer const& n =1) =0;
00178 
00182     virtual void popBackRows( Integer const& n =1) =0;
00183 
00184   protected:
00185     Range rangeHo_;    
00186     Range rangeVe_;    
00187 
00192     inline void setRange(Range const& I = Range(), Range const& J = Range())
00193     {
00194       setRangeVe(I);
00195       setRangeHo(J);
00196     }
00200     inline void setRangeVe( Range const& I = Range())
00201     { rangeVe_ = I;}
00205     inline void incRangeVe( Integer const& inc)
00206     { rangeVe_.inc(inc);}
00210     inline void decRangeVe( Integer const& dec)
00211     { rangeVe_.dec(dec);}
00215     inline void setFirstVe( Integer const& beg)
00216     { rangeVe_.shift(beg);}
00220     inline void incFirstVe( Integer const& inc)
00221     { rangeVe_.incFirst(inc);}
00225     inline void decFirstVe( Integer const& dec)
00226     { rangeVe_.decFirst(dec);}
00230     inline void incLastVe( Integer const& inc)
00231     { rangeVe_.incLast(inc);}
00235     inline void decLastVe( Integer const& dec)
00236     { rangeVe_.decLast(dec);}
00241     inline void setRangeHo( Range const& J = Range())
00242     { rangeHo_ = J;}
00246     inline void incRangeHo( Integer const& inc)
00247     { rangeHo_.inc(inc);}
00251     inline void decRangeHo( Integer const& dec)
00252     { rangeHo_.dec(dec);}
00256     inline void setFirstHo( Integer const& beg)
00257     { rangeHo_.shift(beg);}
00261     inline void incFirstHo( Integer const& inc)
00262     { rangeHo_.incFirst(inc);}
00266     inline void decFirstHo( Integer const& dec)
00267     { rangeHo_.decFirst(dec);}
00271     inline void incLastHo( Integer const& inc)
00272     { rangeHo_.incLast(inc);}
00276     inline void decLastHo( Integer const& dec)
00277     { rangeHo_.decLast(dec);}
00278 
00282      inline void swap(IContainer2D& T)
00283      {
00284        // get ranges of this
00285        Range range_ho(rangeHo());
00286        Range range_ve(rangeVe());
00287        // set range of T to this
00288        setRange(T.rangeVe(), T.rangeHo());
00289        // set range of this to T
00290        T.setRange(range_ve, range_ho);
00291      }
00292 
00293   private:
00298     virtual void shift( Integer const& rbeg, Integer const& cbeg) =0;
00299 
00303     virtual void pushBackCols( Integer const& n =1) =0;
00304 
00308     virtual void pushBackRows( Integer const& n =1) =0;
00309 };
00310 
00311 } // namespace STK
00312 
00313 #endif // STK_ICONTAINER2D_H