Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

CTBvector.icc

Go to the documentation of this file.
00001 
00006 /*----------------------------------------------------------------------------*/
00007 /* C Tool Box: Designed and implemented by:                                   */
00008 /*    Walter F.J. Mueller   Gesellschaft fuer Schwerionenforschung (GSI)      */
00009 /*                          Planckstrasse 1, D-64291 Darmstadt, Germany       */
00010 /*                  Email:  W.F.J.Mueller@gsi.de                              */
00011 /*                  WWW:    http://www-kp3.gsi.de/www/kp3/people/mueller.html */
00012 /*------------------------------------------+---------------------------------*/
00013 
00014 #include "CTBexceptionIndexRange.hxx"
00015 
00016 //------------------------------------------+-----------------------------------
00018 
00019 template <class T>
00020 inline CTBvector<T>::CTBvector()
00021   : m_rbuf(),
00022     mi_nuse(0)
00023 {}
00024 
00025 //------------------------------------------+-----------------------------------
00027 
00028 template <class T>
00029 inline CTBvector<T>::CTBvector(CTBvector<T>& rhs, bool )
00030   : m_rbuf(rhs.m_rbuf,true),
00031     mi_nuse(rhs.mi_nuse)
00032 {
00033   rhs.mi_nuse = 0;
00034 }
00035 
00036 //------------------------------------------+-----------------------------------
00038 
00039 template <class T>
00040 inline CTBvector<T>::CTBvector(CTBvector<T>::RetObj& rhs)
00041   : m_rbuf(rhs.m_rbuf,true),
00042     mi_nuse(rhs.mi_nuse)
00043 {
00044   rhs.mi_nuse = 0;
00045 }
00046 
00047 //------------------------------------------+-----------------------------------
00049 
00050 template <class T>
00051 inline CTBint CTBvector<T>::Size() const
00052 {
00053   return mi_nuse;
00054 }
00055 
00056 //------------------------------------------+-----------------------------------
00058 
00059 template <class T>
00060 inline CTBint CTBvector<T>::Capacity() const
00061 {
00062   return m_rbuf.Capacity();
00063 }
00064 
00065 //------------------------------------------+-----------------------------------
00067 
00068 template <class T>
00069 inline CTBvectorDsc<T> CTBvector<T>::Reverse()
00070 {
00071   return CTBvectorDsc<T>(m_rbuf+mi_nuse-1,mi_nuse,-1);
00072 }
00073 
00074 //------------------------------------------+-----------------------------------
00076 
00077 template <class T>
00078 inline CTBvectorCDsc<T> CTBvector<T>::Reverse() const
00079 {
00080   return CTBvectorCDsc<T>(m_rbuf+mi_nuse-1,mi_nuse,-1);
00081 }
00082 
00083 //------------------------------------------+-----------------------------------
00085 
00086 template <class T>
00087 inline void CTBvector<T>::Remove(CTBint i_ind, T& rhs)
00088 {
00089   rhs = m_rbuf[i_ind];
00090   Delete(i_ind);
00091   return;
00092 }
00093 
00094 //------------------------------------------+-----------------------------------
00096 
00097 template <class T>
00098 inline void CTBvector<T>::InsertHead(const T& rhs)
00099 {
00100   Insert(0,rhs);
00101   return;
00102 }
00103 
00104 //------------------------------------------+-----------------------------------
00106 
00112 template <class T>
00113 inline bool CTBvector<T>::RemoveHead(T& rhs)
00114 {
00115   bool b_ok = mi_nuse > 0;
00116   if (b_ok) Remove(0,rhs);
00117   return b_ok;
00118 }
00119 
00120 //------------------------------------------+-----------------------------------
00122 
00123 template <class T>
00124 inline void CTBvector<T>::InsertTail(const T& rhs)
00125 {
00126   if (mi_nuse+1 > Capacity()) IncreaseCapacity(mi_nuse+1); // double if needed
00127   m_rbuf.Construct(mi_nuse,rhs);
00128   mi_nuse += 1;
00129   return;
00130 }
00131 
00132 // Note:
00133 //  1. This equivalent to Insert(mi_nuse,rhs), but fully inlined and thus
00134 //     potentially faster. For types with an inlined copy ctor this executes
00135 //     without call overhead unless a reallocation is needed.
00136 
00137 //------------------------------------------+-----------------------------------
00139 
00145 template <class T>
00146 inline bool CTBvector<T>::RemoveTail(T& rhs)
00147 {
00148   if (mi_nuse == 0) return false;
00149   m_rbuf.GrabDestruct(mi_nuse-1,rhs);
00150   mi_nuse -= 1;
00151   return true;
00152 }
00153 
00154 // Note:
00155 //  1. This roughly equivalent to 
00156 //              if (mi_nuse>0) Remove(mi_nuse-1,rhs);
00157 //     but fully inlined and thus potentially faster.
00158 
00159 //------------------------------------------+-----------------------------------
00161 
00162 template <class T>
00163 inline void CTBvector<T>::EnsureCapacity(CTBint i_cap)
00164 {
00165   if (i_cap > Capacity()) ChangeCapacity(i_cap);
00166   return;
00167 }
00168 
00169 //------------------------------------------+-----------------------------------
00171 
00172 template <class T>
00173 inline void CTBvector<T>::TrimCapacity()
00174 {
00175   if (Size() < Capacity()) ChangeCapacity(Size());
00176   return;
00177 }
00178 
00179 //------------------------------------------+-----------------------------------
00181 
00186 template <class T>
00187 inline const T* CTBvector<T>::Data() const
00188 {
00189   return *this;
00190 }
00191 
00192 //------------------------------------------+-----------------------------------
00194 
00199 template <class T>
00200 inline CTBint CTBvector<T>::Stride() const
00201 {
00202   return 1;
00203 }
00204 
00205 //------------------------------------------+-----------------------------------
00207 
00208 template <class T>
00209 inline T& CTBvector<T>::operator[](CTBint i_ind)
00210 {
00211 #ifndef CTB__IndexCheck
00212   return m_rbuf[i_ind];
00213 #else
00214   return At(i_ind);
00215 #endif
00216 }
00217 
00218 //------------------------------------------+-----------------------------------
00220 
00221 template <class T>
00222 inline const T& CTBvector<T>::operator[](CTBint i_ind) const
00223 {
00224 #ifndef CTB__IndexCheck
00225   return m_rbuf[i_ind];
00226 #else
00227   return At(i_ind);
00228 #endif
00229 }
00230 
00231 //------------------------------------------+-----------------------------------
00233 
00234 template <class T>
00235 inline T& CTBvector<T>::operator()(CTBint i_ind)
00236 {
00237 #ifndef CTB__IndexCheck
00238   return m_rbuf[i_ind];
00239 #else
00240   return At(i_ind);
00241 #endif
00242 }
00243 
00244 //------------------------------------------+-----------------------------------
00246 
00247 template <class T>
00248 inline const T& CTBvector<T>::operator()(CTBint i_ind) const
00249 {
00250 #ifndef CTB__IndexCheck
00251   return m_rbuf[i_ind];
00252 #else
00253   return At(i_ind);
00254 #endif
00255 }
00256 
00257 //------------------------------------------+-----------------------------------
00259 
00260 template <class T>
00261 inline CTBvectorDsc<T> CTBvector<T>::operator()(const CTBrange& ran)
00262 {
00263 #ifndef CTB__IndexCheck
00264   CTBindexRangeCheck(ran,mi_nuse,"CTBvector<T>::operator()");
00265 #endif
00266   return CTBvectorDsc<T>(m_rbuf,ran);
00267 }
00268 
00269 //------------------------------------------+-----------------------------------
00271 
00272 template <class T>
00273 inline CTBvectorCDsc<T> CTBvector<T>::operator()(const CTBrange& ran) const
00274 {
00275 #ifndef CTB__IndexCheck
00276   CTBindexRangeCheck(ran,mi_nuse,"CTBvector<T>::operator()");
00277 #endif
00278   return CTBvectorCDsc<T>(m_rbuf,ran);
00279 }
00280 
00281 //------------------------------------------+-----------------------------------
00283 
00284 template <class T>
00285 inline bool CTBvector<T>::operator !() const
00286 {
00287   return mi_nuse == 0;
00288 }
00289 
00290 //------------------------------------------+-----------------------------------
00292 
00293 template <class T>
00294 inline CTBvector<T>::operator T*()
00295 {
00296   return (mi_nuse > 0) ? (T*) m_rbuf : 0;
00297 }
00298 
00299 //------------------------------------------+-----------------------------------
00301 
00302 template <class T>
00303 inline CTBvector<T>::operator const T*() const
00304 {
00305   return (mi_nuse > 0) ? (const T*) m_rbuf : 0;
00306 }
00307 
00308 //------------------------------------------+-----------------------------------
00310 
00311 template <class T>
00312 inline CTBvector<T>::operator CTBvectorDsc<T>()
00313 {
00314   return CTBvectorDsc<T>(m_rbuf,mi_nuse);
00315 }
00316 
00317 //------------------------------------------+-----------------------------------
00319 
00320 template <class T>
00321 inline CTBvector<T>::operator CTBvectorCDsc<T>() const
00322 {
00323   return CTBvectorCDsc<T>(m_rbuf,mi_nuse);
00324 }
00325 
00326 //------------------------------------------+-----------------------------------
00328 
00329 template <class T>
00330 inline CTBvector<T>& CTBvector<T>::operator=(CTBvector<T>::RetObj& rhs)
00331 {
00332   Grab(rhs);
00333   return *this;
00334 }
00335 
00336 //------------------------------------------+-----------------------------------
00338 
00339 template <class T>
00340 inline CTBvector<T>& CTBvector<T>::operator<<(const T& rhs)
00341 {
00342   InsertTail(rhs);
00343   return *this;
00344 }
00345 
00346 //------------------------------------------+-----------------------------------
00348 
00349 template <class T>
00350 inline CTBvector<T>& CTBvector<T>::operator>>(T& rhs)
00351 {
00352   RemoveTail(rhs);
00353   return *this;
00354 }
00355 
00356 //------------------------------------------+-----------------------------------
00362 template <class T>
00363 inline ostream& operator<<(ostream& os, const CTBvector<T>& obj)
00364 {
00365   int i_width = os.width();
00366 
00367   os << setw(0) << "{";
00368   for (CTBint i = 0; i < obj.Size(); i++) {
00369     if (i > 0) os << ",";
00370     os << setw(i_width) << obj(i);
00371   }
00372   os << "}";
00373   return os;
00374 }

Generated at Fri Oct 24 18:11:30 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001