|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004-2011 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::TContainer 00027 * Purpose: Define the Abstract templated 2D Container base class. 00028 * Author: Serge Iovleff, serge.iovleff@stkpp.org 00029 * 00030 **/ 00031 00037 #ifndef STK_ITCONTAINER2DBASE_H 00038 #define STK_ITCONTAINER2DBASE_H 00039 00040 #include <stdexcept> 00041 #include "STK_IContainer2D.h" 00042 00043 namespace STK 00044 { 00068 template < class TYPE, class TContainer2D> 00069 class ITContainer2DBase : public IContainerBase<TContainer2D> 00070 , public IContainer2D 00071 { 00072 protected: 00077 ITContainer2DBase( Range const& I = Range(), Range const& J = Range()) 00078 : IContainerBase<TContainer2D>(IContainerBase<TContainer2D>::_2D_) 00079 , IContainer2D(I, J) 00080 { this->ranges_.push_back(&rangeVe_); this->ranges_.push_back(&rangeHo_);} 00081 00085 ITContainer2DBase( const ITContainer2DBase &T) 00086 : IContainerBase<TContainer2D>(IContainerBase<TContainer2D>::_2D_) 00087 , IContainer2D(T) 00088 { this->ranges_.push_back(&rangeVe_); this->ranges_.push_back(&rangeHo_);} 00089 00090 public: 00092 virtual ~ITContainer2DBase() { ;} 00093 00099 inline TYPE& operator()(Integer const& i, const Integer j) 00100 { return this->asLeaf().elt(i,j);} 00101 00107 inline TYPE const& operator()(Integer i, Integer j) const 00108 { return this->asLeaf().elt(i,j);} 00109 00114 TYPE& at(Integer i, Integer j) 00115 { 00116 if (this->firstRow() > i) 00117 { throw std::out_of_range("ITContainer2DBase::at(i, j) " 00118 "this->firstRow() > i"); 00119 } 00120 if (this->lastRow() < i) 00121 { throw std::out_of_range("ITContainer2DBase::at(i, j) " 00122 "this->lastRow() < i"); 00123 } 00124 if (this->firstCol() > j) 00125 { throw std::out_of_range("ITContainer2DBase::at(i, j) " 00126 "this->firstCol() > j"); 00127 } 00128 if (this->lastCol() < j) 00129 { throw std::out_of_range("ITContainer2DBase::at(i, j) " 00130 "this->lastCol() < j"); 00131 } 00132 return this->asLeaf().elt(i, j); 00133 } 00134 00139 TYPE const& at(Integer i, Integer j) const 00140 { 00141 // check bounds 00142 if (this->firstRow() > i) 00143 { throw std::out_of_range("ITContainer2DBase::at(i, j) " 00144 "this->firstRow() > i"); 00145 } 00146 if (this->lastRow() < i) 00147 { throw std::out_of_range("ITContainer2DBase::at(i, j) " 00148 "this->lastRow() < i"); 00149 } 00150 if (this->firstCol() > j) 00151 { throw std::out_of_range("ITContainer2DBase::at(i, j) " 00152 "this->firstCol() > j"); 00153 } 00154 if (this->lastCol() < j) 00155 { throw std::out_of_range("ITContainer2DBase::at(i, j) " 00156 "this->lastCol() < j"); 00157 } 00158 // return element 00159 return this->asLeaf().elt(i, j); 00160 } 00161 }; 00162 00163 } // namespace STK 00164 00165 #endif 00166 // STK_ITCONTAINER2D_H