C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
lx_ivector.inl
00001 /*
00002 **  CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
00003 **
00004 **  Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
00005 **                          Universitaet Karlsruhe, Germany
00006 **            (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
00007 **                          Universitaet Wuppertal, Germany   
00008 **
00009 **  This library is free software; you can redistribute it and/or
00010 **  modify it under the terms of the GNU Library General Public
00011 **  License as published by the Free Software Foundation; either
00012 **  version 2 of the License, or (at your option) any later version.
00013 **
00014 **  This library is distributed in the hope that it will be useful,
00015 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 **  Library General Public License for more details.
00018 **
00019 **  You should have received a copy of the GNU Library General Public
00020 **  License along with this library; if not, write to the Free
00021 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 /* CVS $Id: lx_ivector.inl,v 1.9 2014/01/30 17:23:47 cxsc Exp $ */
00025 
00026 namespace cxsc {
00027         
00031         inline lx_ivector::lx_ivector () throw():dat(NULL),l(1),u(0),size(0)
00032         { }
00033         
00039         inline lx_ivector::lx_ivector(int i) throw():l(1),u(i),size(i)
00040         {
00041                 dat=new lx_interval[i];
00042         }
00043         
00050         inline lx_ivector::lx_ivector(int i1, int i2)
00051 #if(CXSC_INDEX_CHECK)
00052                 throw(ERROR_IVECTOR_WRONG_BOUNDARIES,ERROR_IVECTOR_NO_MORE_MEMORY):
00053                                                                     l(i1),u(i2),size(i2-i1+1)
00054 #else
00055                 throw():l(i1),u(i2),size(i2-i1+1)
00056 #endif
00057         {
00058 #if(CXSC_INDEX_CHECK)
00059                 if(i1>i2) cxscthrow(ERROR_IVECTOR_WRONG_BOUNDARIES(
00060                                         "lx_ivector(const int &i1,const int &i2)"));
00061 #endif
00062                 dat=new lx_interval[size];
00063         }
00064                         
00065         inline lx_ivector::lx_ivector(const lx_interval &r) throw():l(1),u(1),size(1)
00066         {
00067                 dat=new lx_interval[1];
00068                 *dat=r;
00069         }
00070         
00071         inline lx_ivector::lx_ivector(const l_interval &r) throw():l(1),u(1),size(1)
00072         {
00073                 dat=new lx_interval[1];
00074                 *dat=r;
00075         }       
00076         
00077         inline lx_ivector::lx_ivector(const interval &r) throw():l(1),u(1),size(1)
00078         {
00079                 dat=new lx_interval[1];
00080                 *dat=r;
00081         }
00082                 
00083         inline lx_ivector::lx_ivector(const lx_real &r) throw():l(1),u(1),size(1)
00084         {
00085                 dat=new lx_interval[1];
00086                 *dat=r;
00087         }
00088                 
00089         inline lx_ivector::lx_ivector(const l_real &r) throw():l(1),u(1),size(1)
00090         {
00091                 dat=new lx_interval[1];
00092                 *dat=r;
00093         }
00094                 
00095         inline lx_ivector::lx_ivector(const real &r) throw():l(1),u(1),size(1)
00096         {
00097                 dat=new lx_interval[1];
00098                 *dat=r;
00099         }       
00100 
00101         inline lx_ivector::lx_ivector(const lx_ivector &v)
00102                                                            throw():l(v.l),u(v.u),size(v.size)
00103         {
00104                 dat=new lx_interval[size];
00105                 for (int i=0;i<size;i++)
00106                         dat[i]=v.dat[i];
00107         }
00108         
00109         inline lx_ivector &lx_ivector::operator =(const lx_ivector &rv) throw()
00110         { 
00111                 l = rv.l; u = rv.u; size = rv.size;
00112                 dat=new lx_interval[size];
00113                 for (int i=0;i<size;i++)
00114                         dat[i]=rv.dat[i];
00115                 return *this;
00116         }
00117         
00118         inline lx_ivector &lx_ivector::operator =(const lx_interval &r) throw()
00119         {
00120                 lx_interval *newdat = new lx_interval[size];
00121                 for (int i=0;i<size;i++)
00122                         newdat[i] = r;
00123                 delete [] dat;
00124                 dat = newdat;
00125                 return *this;
00126         }
00127         
00128         inline lx_ivector &lx_ivector::operator =(const l_interval &r) throw()
00129         {
00130                 lx_interval *newdat = new lx_interval[size];
00131                 for (int i=0;i<size;i++)
00132                         newdat[i] = r;
00133                 delete [] dat;
00134                 dat = newdat;
00135                 return *this;
00136         }
00137         
00138         inline lx_ivector &lx_ivector::operator =(const interval &r) throw()
00139         {
00140                 lx_interval *newdat = new lx_interval[size];
00141                 for (int i=0;i<size;i++)
00142                         newdat[i] = r;
00143                 delete [] dat;
00144                 dat = newdat;
00145                 return *this;
00146         }
00147         
00148         inline lx_ivector &lx_ivector::operator =(const lx_real &r) throw()
00149         {
00150                 lx_interval *newdat = new lx_interval[size];
00151                 for (int i=0;i<size;i++)
00152                         newdat[i] = r;
00153                 delete [] dat;
00154                 dat = newdat;
00155                 return *this;
00156         }
00157         
00158         inline lx_ivector &lx_ivector::operator =(const l_real &r) throw()
00159         {
00160                 lx_interval *newdat = new lx_interval[size];
00161                 for (int i=0;i<size;i++)
00162                         newdat[i] = r;
00163                 delete [] dat;
00164                 dat = newdat;
00165                 return *this;
00166         }
00167         
00168         inline lx_ivector &lx_ivector::operator =(const real &r) throw()
00169         {
00170                 lx_interval *newdat = new lx_interval[size];
00171                 for (int i=0;i<size;i++)
00172                         newdat[i] = r;
00173                 delete [] dat;
00174                 dat = newdat;
00175                 return *this;
00176         }
00177         
00178         inline lx_interval & lx_ivector::operator [](const int &i)
00179 #if(CXSC_INDEX_CHECK)
00180                 throw(ERROR_IVECTOR_ELEMENT_NOT_IN_VEC)
00181 #else
00182                 throw()
00183 #endif
00184         {
00185 #if(CXSC_INDEX_CHECK)
00186                 if(i<l||i>u) cxscthrow(ERROR_IVECTOR_ELEMENT_NOT_IN_VEC(
00187                                         "lx_interval & lx_ivector::operator [](const int &i)"));
00188 #endif
00189                 return dat[i-l];
00190         }
00191                 
00192         inline const lx_interval & lx_ivector::operator [](const int &i) const
00193 #if(CXSC_INDEX_CHECK)
00194                         throw(ERROR_IVECTOR_ELEMENT_NOT_IN_VEC)
00195 #else
00196                         throw()
00197 #endif
00198         {
00199 #if(CXSC_INDEX_CHECK)
00200                 if(i<l || i>u) cxscthrow(ERROR_IVECTOR_ELEMENT_NOT_IN_VEC(
00201                         "lx_interval & lx_ivector::operator [](const int &i)"));
00202 #endif
00203                 return dat[i-l];
00204         }       
00205 
00206 inline void Resize(lx_ivector &rv, int len)
00207 #if(CXSC_INDEX_CHECK)
00208                         throw(ERROR__WRONG_BOUNDARIES<lx_ivector>);
00209 #else
00210         throw()
00211 #endif
00212         {
00213                 if (rv.size == len)
00214                         SetLb(rv,1);
00215                 else
00216                 {
00217 #if(CXSC_INDEX_CHECK)   
00218                         if (len<0) 
00219                                 cxscthrow(ERROR__WRONG_BOUNDARIES(
00220                                                          "Resize(lx_ivector &rv, int len)"));
00221 #endif
00222                         lx_interval *ndat = new lx_interval[len];
00223                         int beg, end;
00224                         beg = (rv.l>1)? rv.l : 1;
00225                         end = (rv.u<len)? rv.u : len;
00226                         for(int i=beg-1;i<end;i++)
00227                                 ndat[i]=rv.dat[i-rv.l+1];
00228                         delete [] rv.dat;
00229                         rv.dat=ndat;
00230                         rv.size=rv.u=len;
00231                         rv.l=1;
00232                 }
00233         }
00234         
00235 inline void Resize(lx_ivector &rv, int lb, int ub)
00236 #if(CXSC_INDEX_CHECK)
00237                         throw(ERROR__WRONG_BOUNDARIES<lx_ivector>)
00238 #else
00239                         throw()
00240 #endif
00241 { 
00242         if (rv.size == ub-lb+1)
00243                 SetUb(rv,ub);
00244         else
00245         {
00246                 rv.size = ub-lb+1;
00247 #if(CXSC_INDEX_CHECK)
00248         if (rv.size<0)
00249                 cxscthrow(ERROR__WRONG_BOUNDARIES(
00250                                          "Resize(lx_ivector &rv, int lb, int ub)"));
00251 #endif
00252                 lx_interval *ndat = new lx_interval[rv.size];
00253                 int beg, end;
00254                 beg = (rv.l>lb)? rv.l : lb;
00255                 end = (rv.u<ub)? rv.u : ub;
00256                 for(int i=0;i<=rv.size-1;i++)
00257                         ndat[i]=interval(0);
00258                 for(int i=beg;i<=end;i++)
00259                         ndat[i-lb]=rv.dat[i-rv.l];
00260                 delete [] rv.dat;
00261                 rv.dat=ndat;
00262                 rv.l=lb;
00263                 rv.u=ub;
00264         }
00265 }
00266 
00267 inline void DoubleSize(lx_ivector& x) throw()
00268 {
00269         int n = Lb(x);
00270         Resize(x,n,2*Ub(x)-n+1);
00271 }
00272 
00273 } // namespace cxsc