FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

FixedListI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/UList.H>
00027 #include <OpenFOAM/SLList.H>
00028 #include <OpenFOAM/contiguous.H>
00029 
00030 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00031 
00032 template<class T, unsigned Size>
00033 inline Foam::FixedList<T, Size>::FixedList()
00034 {}
00035 
00036 
00037 template<class T, unsigned Size>
00038 inline Foam::FixedList<T, Size>::FixedList(const T v[Size])
00039 {
00040     for (register unsigned i=0; i<Size; i++)
00041     {
00042         v_[i] = v[i];
00043     }
00044 }
00045 
00046 
00047 template<class T, unsigned Size>
00048 inline Foam::FixedList<T, Size>::FixedList(const T& t)
00049 {
00050     for (register unsigned i=0; i<Size; i++)
00051     {
00052         v_[i] = t;
00053     }
00054 }
00055 
00056 
00057 template<class T, unsigned Size>
00058 inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst)
00059 {
00060     checkSize(lst.size());
00061 
00062     for (register unsigned i=0; i<Size; i++)
00063     {
00064         v_[i] = lst[i];
00065     }
00066 }
00067 
00068 
00069 template<class T, unsigned Size>
00070 inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
00071 {
00072     checkSize(lst.size());
00073 
00074     register label i = 0;
00075     for
00076     (
00077         typename SLList<T>::const_iterator iter = lst.begin();
00078         iter != lst.end();
00079         ++iter
00080     )
00081     {
00082         operator[](i++) = iter();
00083     }
00084 }
00085 
00086 
00087 template<class T, unsigned Size>
00088 inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst)
00089 {
00090     for (register unsigned i=0; i<Size; i++)
00091     {
00092         v_[i] = lst[i];
00093     }
00094 }
00095 
00096 
00097 template<class T, unsigned Size>
00098 inline Foam::autoPtr< Foam::FixedList<T, Size> >
00099 Foam::FixedList<T, Size>::clone() const
00100 {
00101     return autoPtr< FixedList<T, Size> >(new FixedList<T, Size>(*this));
00102 }
00103 
00104 
00105 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00106 
00107 template<class T, unsigned Size>
00108 inline const Foam::FixedList<T, Size>& Foam::FixedList<T, Size>::null()
00109 {
00110     return *reinterpret_cast< FixedList<T, Size>* >(0);
00111 }
00112 
00113 
00114 template<class T, unsigned Size>
00115 inline Foam::label Foam::FixedList<T, Size>::fcIndex(const label i) const
00116 {
00117     return (i == Size-1 ? 0 : i+1);
00118 }
00119 
00120 
00121 template<class T, unsigned Size>
00122 inline Foam::label Foam::FixedList<T, Size>::rcIndex(const label i) const
00123 {
00124     return (i ? i-1 : Size-1);
00125 }
00126 
00127 
00128 // Check start is within valid range (0 ... size-1).
00129 template<class T, unsigned Size>
00130 inline void Foam::FixedList<T, Size>::checkStart(const label start) const
00131 {
00132     if (start < 0 || (start && unsigned(start) >= Size))
00133     {
00134         FatalErrorIn("FixedList<T, Size>::checkStart(const label)")
00135             << "start " << start << " out of range 0 ... " << (Size-1)
00136             << abort(FatalError);
00137     }
00138 }
00139 
00140 
00141 // Check size is within valid range (0 ... size).
00142 template<class T, unsigned Size>
00143 inline void Foam::FixedList<T, Size>::checkSize(const label size) const
00144 {
00145     if (size < 0 || unsigned(size) > Size)
00146     {
00147         FatalErrorIn("FixedList<T, Size>::checkSize(const label)")
00148             << "size " << size << " out of range 0 ... " << (Size)
00149             << abort(FatalError);
00150     }
00151 }
00152 
00153 
00154 // Check index i is within valid range (0 ... size-1)
00155 // The check for zero-sized list is already done in static assert
00156 template<class T, unsigned Size>
00157 inline void Foam::FixedList<T, Size>::checkIndex(const label i) const
00158 {
00159     if (i < 0 || unsigned(i) >= Size)
00160     {
00161         FatalErrorIn("FixedList<T, Size>::checkIndex(const label)")
00162             << "index " << i << " out of range 0 ... " << (Size-1)
00163             << abort(FatalError);
00164     }
00165 }
00166 
00167 
00168 template<class T, unsigned Size>
00169 inline void Foam::FixedList<T, Size>::resize(const label s)
00170 {
00171 #   ifdef FULLDEBUG
00172     checkSize(s);
00173 #   endif
00174 }
00175 
00176 template<class T, unsigned Size>
00177 inline void Foam::FixedList<T, Size>::setSize(const label s)
00178 {
00179 #   ifdef FULLDEBUG
00180     checkSize(s);
00181 #   endif
00182 }
00183 
00184 template<class T, unsigned Size>
00185 inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst)
00186 {
00187     for (register unsigned i=0; i<Size; i++)
00188     {
00189         v_[i] = lst[i];
00190     }
00191 }
00192 
00193 
00194 template<class T, unsigned Size>
00195 inline const T*
00196 Foam::FixedList<T, Size>::cdata() const
00197 {
00198     return v_;
00199 }
00200 
00201 
00202 template<class T, unsigned Size>
00203 inline T*
00204 Foam::FixedList<T, Size>::data()
00205 {
00206     return v_;
00207 }
00208 
00209 
00210 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00211 
00212 // element access
00213 template<class T, unsigned Size>
00214 inline T& Foam::FixedList<T, Size>::operator[](const label i)
00215 {
00216 #   ifdef FULLDEBUG
00217     checkIndex(i);
00218 #   endif
00219     return v_[i];
00220 }
00221 
00222 
00223 // const element access
00224 template<class T, unsigned Size>
00225 inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
00226 {
00227 #   ifdef FULLDEBUG
00228     checkIndex(i);
00229 #   endif
00230     return v_[i];
00231 }
00232 
00233 
00234 template<class T, unsigned Size>
00235 inline void Foam::FixedList<T, Size>::operator=(const T lst[Size])
00236 {
00237     for (register unsigned i=0; i<Size; i++)
00238     {
00239         v_[i] = lst[i];
00240     }
00241 }
00242 
00243 template<class T, unsigned Size>
00244 inline void Foam::FixedList<T, Size>::operator=(const UList<T>& lst)
00245 {
00246     checkSize(lst.size());
00247 
00248     for (register unsigned i=0; i<Size; i++)
00249     {
00250         v_[i] = lst[i];
00251     }
00252 }
00253 
00254 template<class T, unsigned Size>
00255 inline void Foam::FixedList<T, Size>::operator=(const SLList<T>& lst)
00256 {
00257     checkSize(lst.size());
00258 
00259     register label i = 0;
00260     for
00261     (
00262         typename SLList<T>::const_iterator iter = lst.begin();
00263         iter != lst.end();
00264         ++iter
00265     )
00266     {
00267         operator[](i++) = iter();
00268     }
00269 }
00270 
00271 template<class T, unsigned Size>
00272 inline void Foam::FixedList<T, Size>::operator=(const T& t)
00273 {
00274     for (register unsigned i=0; i<Size; i++)
00275     {
00276         v_[i] = t;
00277     }
00278 }
00279 
00280 
00281 // * * * * * * * * * * * * * * STL Member Functions  * * * * * * * * * * * * //
00282 
00283 template<class T, unsigned Size>
00284 inline typename Foam::FixedList<T, Size>::iterator
00285 Foam::FixedList<T, Size>::begin()
00286 {
00287     return v_;
00288 }
00289 
00290 
00291 template<class T, unsigned Size>
00292 inline typename Foam::FixedList<T, Size>::const_iterator
00293 Foam::FixedList<T, Size>::begin() const
00294 {
00295     return v_;
00296 }
00297 
00298 
00299 template<class T, unsigned Size>
00300 inline typename Foam::FixedList<T, Size>::const_iterator
00301 Foam::FixedList<T, Size>::cbegin() const
00302 {
00303     return v_;
00304 }
00305 
00306 
00307 template<class T, unsigned Size>
00308 inline typename Foam::FixedList<T, Size>::iterator
00309 Foam::FixedList<T, Size>::end()
00310 {
00311     return &v_[Size];
00312 }
00313 
00314 
00315 template<class T, unsigned Size>
00316 inline typename Foam::FixedList<T, Size>::const_iterator
00317 Foam::FixedList<T, Size>::end() const
00318 {
00319     return &v_[Size];
00320 }
00321 
00322 
00323 template<class T, unsigned Size>
00324 inline typename Foam::FixedList<T, Size>::const_iterator
00325 Foam::FixedList<T, Size>::cend() const
00326 {
00327     return &v_[Size];
00328 }
00329 
00330 
00331 template<class T, unsigned Size>
00332 inline typename Foam::FixedList<T, Size>::iterator
00333 Foam::FixedList<T, Size>::rbegin()
00334 {
00335     return &v_[Size-1];
00336 }
00337 
00338 
00339 template<class T, unsigned Size>
00340 inline typename Foam::FixedList<T, Size>::const_iterator
00341 Foam::FixedList<T, Size>::rbegin() const
00342 {
00343     return &v_[Size-1];
00344 }
00345 
00346 
00347 template<class T, unsigned Size>
00348 inline typename Foam::FixedList<T, Size>::const_iterator
00349 Foam::FixedList<T, Size>::crbegin() const
00350 {
00351     return &v_[Size-1];
00352 }
00353 
00354 
00355 template<class T, unsigned Size>
00356 inline typename Foam::FixedList<T, Size>::iterator
00357 Foam::FixedList<T, Size>::rend()
00358 {
00359     return &v_[-1];
00360 }
00361 
00362 
00363 template<class T, unsigned Size>
00364 inline typename Foam::FixedList<T, Size>::const_iterator
00365 Foam::FixedList<T, Size>::rend() const
00366 {
00367     return &v_[-1];
00368 }
00369 
00370 
00371 template<class T, unsigned Size>
00372 inline typename Foam::FixedList<T, Size>::const_iterator
00373 Foam::FixedList<T, Size>::crend() const
00374 {
00375     return &v_[-1];
00376 }
00377 
00378 
00379 template<class T, unsigned Size>
00380 inline Foam::label Foam::FixedList<T, Size>::size() const
00381 {
00382     return Size;
00383 }
00384 
00385 
00386 template<class T, unsigned Size>
00387 inline Foam::label Foam::FixedList<T, Size>::max_size() const
00388 {
00389     return Size;
00390 }
00391 
00392 
00393 template<class T, unsigned Size>
00394 inline bool Foam::FixedList<T, Size>::empty() const
00395 {
00396     return false;
00397 }
00398 
00399 
00400 template<class T, unsigned Size>
00401 template<class HashT>
00402 inline unsigned Foam::FixedList<T, Size>::Hash<HashT>::operator()
00403 (
00404     const FixedList<T, Size>& lst,
00405     unsigned seed
00406 ) const
00407 {
00408     if (contiguous<T>())
00409     {
00410         // hash directly
00411         return Hasher(lst.v_, sizeof(lst.v_), seed);
00412     }
00413     else
00414     {
00415         // hash incrementally
00416         unsigned val = seed;
00417 
00418         for (register unsigned i=0; i<Size; i++)
00419         {
00420             val = HashT()(lst[i], val);
00421         }
00422 
00423         return val;
00424     }
00425 }
00426 
00427 
00428 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines