00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "UList.H"
00028 #include "SLList.H"
00029 #include "contiguous.H"
00030
00031
00032
00033 template<class T, unsigned Size>
00034 inline Foam::FixedList<T, Size>::FixedList()
00035 {}
00036
00037
00038 template<class T, unsigned Size>
00039 inline Foam::FixedList<T, Size>::FixedList(const T v[Size])
00040 {
00041 for (register unsigned i=0; i<Size; i++)
00042 {
00043 v_[i] = v[i];
00044 }
00045 }
00046
00047
00048 template<class T, unsigned Size>
00049 inline Foam::FixedList<T, Size>::FixedList(const T& t)
00050 {
00051 for (register unsigned i=0; i<Size; i++)
00052 {
00053 v_[i] = t;
00054 }
00055 }
00056
00057
00058 template<class T, unsigned Size>
00059 inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst)
00060 {
00061 checkSize(lst.size());
00062
00063 for (register unsigned i=0; i<Size; i++)
00064 {
00065 v_[i] = lst[i];
00066 }
00067 }
00068
00069
00070 template<class T, unsigned Size>
00071 inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
00072 {
00073 checkSize(lst.size());
00074
00075 register label i = 0;
00076 for
00077 (
00078 typename SLList<T>::const_iterator iter = lst.begin();
00079 iter != lst.end();
00080 ++iter
00081 )
00082 {
00083 operator[](i++) = iter();
00084 }
00085 }
00086
00087
00088 template<class T, unsigned Size>
00089 inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst)
00090 {
00091 for (register unsigned i=0; i<Size; i++)
00092 {
00093 v_[i] = lst[i];
00094 }
00095 }
00096
00097
00098 template<class T, unsigned Size>
00099 inline Foam::autoPtr< Foam::FixedList<T, Size> >
00100 Foam::FixedList<T, Size>::clone() const
00101 {
00102 return autoPtr< FixedList<T, Size> >(new FixedList<T, Size>(*this));
00103 }
00104
00105
00106
00107
00108 template<class T, unsigned Size>
00109 inline const Foam::FixedList<T, Size>& Foam::FixedList<T, Size>::null()
00110 {
00111 return *reinterpret_cast< FixedList<T, Size>* >(0);
00112 }
00113
00114
00115 template<class T, unsigned Size>
00116 inline Foam::label Foam::FixedList<T, Size>::fcIndex(const label i) const
00117 {
00118 return (i == Size-1 ? 0 : i+1);
00119 }
00120
00121
00122 template<class T, unsigned Size>
00123 inline Foam::label Foam::FixedList<T, Size>::rcIndex(const label i) const
00124 {
00125 return (i ? i-1 : Size-1);
00126 }
00127
00128
00129
00130 template<class T, unsigned Size>
00131 inline void Foam::FixedList<T, Size>::checkStart(const label start) const
00132 {
00133 if (start < 0 || (start && unsigned(start) >= Size))
00134 {
00135 FatalErrorIn("FixedList<T, Size>::checkStart(const label)")
00136 << "start " << start << " out of range 0 ... " << (Size-1)
00137 << abort(FatalError);
00138 }
00139 }
00140
00141
00142
00143 template<class T, unsigned Size>
00144 inline void Foam::FixedList<T, Size>::checkSize(const label size) const
00145 {
00146 if (size < 0 || unsigned(size) > Size)
00147 {
00148 FatalErrorIn("FixedList<T, Size>::checkSize(const label)")
00149 << "size " << size << " out of range 0 ... " << (Size)
00150 << abort(FatalError);
00151 }
00152 }
00153
00154
00155
00156
00157 template<class T, unsigned Size>
00158 inline void Foam::FixedList<T, Size>::checkIndex(const label i) const
00159 {
00160 if (i < 0 || unsigned(i) >= Size)
00161 {
00162 FatalErrorIn("FixedList<T, Size>::checkIndex(const label)")
00163 << "index " << i << " out of range 0 ... " << (Size-1)
00164 << abort(FatalError);
00165 }
00166 }
00167
00168
00169 template<class T, unsigned Size>
00170 inline void Foam::FixedList<T, Size>::resize(const label s)
00171 {
00172 # ifdef FULLDEBUG
00173 checkSize(s);
00174 # endif
00175 }
00176
00177 template<class T, unsigned Size>
00178 inline void Foam::FixedList<T, Size>::setSize(const label s)
00179 {
00180 # ifdef FULLDEBUG
00181 checkSize(s);
00182 # endif
00183 }
00184
00185 template<class T, unsigned Size>
00186 inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst)
00187 {
00188 for (register unsigned i=0; i<Size; i++)
00189 {
00190 v_[i] = lst[i];
00191 }
00192 }
00193
00194
00195 template<class T, unsigned Size>
00196 inline const T*
00197 Foam::FixedList<T, Size>::cdata() const
00198 {
00199 return v_;
00200 }
00201
00202
00203 template<class T, unsigned Size>
00204 inline T*
00205 Foam::FixedList<T, Size>::data()
00206 {
00207 return v_;
00208 }
00209
00210
00211
00212
00213
00214 template<class T, unsigned Size>
00215 inline T& Foam::FixedList<T, Size>::operator[](const label i)
00216 {
00217 # ifdef FULLDEBUG
00218 checkIndex(i);
00219 # endif
00220 return v_[i];
00221 }
00222
00223
00224
00225 template<class T, unsigned Size>
00226 inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
00227 {
00228 # ifdef FULLDEBUG
00229 checkIndex(i);
00230 # endif
00231 return v_[i];
00232 }
00233
00234
00235 template<class T, unsigned Size>
00236 inline void Foam::FixedList<T, Size>::operator=(const T lst[Size])
00237 {
00238 for (register unsigned i=0; i<Size; i++)
00239 {
00240 v_[i] = lst[i];
00241 }
00242 }
00243
00244 template<class T, unsigned Size>
00245 inline void Foam::FixedList<T, Size>::operator=(const UList<T>& lst)
00246 {
00247 checkSize(lst.size());
00248
00249 for (register unsigned i=0; i<Size; i++)
00250 {
00251 v_[i] = lst[i];
00252 }
00253 }
00254
00255 template<class T, unsigned Size>
00256 inline void Foam::FixedList<T, Size>::operator=(const SLList<T>& lst)
00257 {
00258 checkSize(lst.size());
00259
00260 register label i = 0;
00261 for
00262 (
00263 typename SLList<T>::const_iterator iter = lst.begin();
00264 iter != lst.end();
00265 ++iter
00266 )
00267 {
00268 operator[](i++) = iter();
00269 }
00270 }
00271
00272 template<class T, unsigned Size>
00273 inline void Foam::FixedList<T, Size>::operator=(const T& t)
00274 {
00275 for (register unsigned i=0; i<Size; i++)
00276 {
00277 v_[i] = t;
00278 }
00279 }
00280
00281
00282
00283
00284 template<class T, unsigned Size>
00285 inline typename Foam::FixedList<T, Size>::iterator
00286 Foam::FixedList<T, Size>::begin()
00287 {
00288 return v_;
00289 }
00290
00291
00292 template<class T, unsigned Size>
00293 inline typename Foam::FixedList<T, Size>::const_iterator
00294 Foam::FixedList<T, Size>::begin() const
00295 {
00296 return v_;
00297 }
00298
00299
00300 template<class T, unsigned Size>
00301 inline typename Foam::FixedList<T, Size>::const_iterator
00302 Foam::FixedList<T, Size>::cbegin() const
00303 {
00304 return v_;
00305 }
00306
00307
00308 template<class T, unsigned Size>
00309 inline typename Foam::FixedList<T, Size>::iterator
00310 Foam::FixedList<T, Size>::end()
00311 {
00312 return &v_[Size];
00313 }
00314
00315
00316 template<class T, unsigned Size>
00317 inline typename Foam::FixedList<T, Size>::const_iterator
00318 Foam::FixedList<T, Size>::end() const
00319 {
00320 return &v_[Size];
00321 }
00322
00323
00324 template<class T, unsigned Size>
00325 inline typename Foam::FixedList<T, Size>::const_iterator
00326 Foam::FixedList<T, Size>::cend() const
00327 {
00328 return &v_[Size];
00329 }
00330
00331
00332 template<class T, unsigned Size>
00333 inline typename Foam::FixedList<T, Size>::iterator
00334 Foam::FixedList<T, Size>::rbegin()
00335 {
00336 return &v_[Size-1];
00337 }
00338
00339
00340 template<class T, unsigned Size>
00341 inline typename Foam::FixedList<T, Size>::const_iterator
00342 Foam::FixedList<T, Size>::rbegin() const
00343 {
00344 return &v_[Size-1];
00345 }
00346
00347
00348 template<class T, unsigned Size>
00349 inline typename Foam::FixedList<T, Size>::const_iterator
00350 Foam::FixedList<T, Size>::crbegin() const
00351 {
00352 return &v_[Size-1];
00353 }
00354
00355
00356 template<class T, unsigned Size>
00357 inline typename Foam::FixedList<T, Size>::iterator
00358 Foam::FixedList<T, Size>::rend()
00359 {
00360 return &v_[-1];
00361 }
00362
00363
00364 template<class T, unsigned Size>
00365 inline typename Foam::FixedList<T, Size>::const_iterator
00366 Foam::FixedList<T, Size>::rend() const
00367 {
00368 return &v_[-1];
00369 }
00370
00371
00372 template<class T, unsigned Size>
00373 inline typename Foam::FixedList<T, Size>::const_iterator
00374 Foam::FixedList<T, Size>::crend() const
00375 {
00376 return &v_[-1];
00377 }
00378
00379
00380 template<class T, unsigned Size>
00381 inline Foam::label Foam::FixedList<T, Size>::size() const
00382 {
00383 return Size;
00384 }
00385
00386
00387 template<class T, unsigned Size>
00388 inline Foam::label Foam::FixedList<T, Size>::max_size() const
00389 {
00390 return Size;
00391 }
00392
00393
00394 template<class T, unsigned Size>
00395 inline bool Foam::FixedList<T, Size>::empty() const
00396 {
00397 return false;
00398 }
00399
00400
00401 template<class T, unsigned Size>
00402 template<class HashT>
00403 inline unsigned Foam::FixedList<T, Size>::Hash<HashT>::operator()
00404 (
00405 const FixedList<T, Size>& lst,
00406 unsigned seed
00407 ) const
00408 {
00409 if (contiguous<T>())
00410 {
00411
00412 return Hasher(lst.v_, sizeof(lst.v_), seed);
00413 }
00414 else
00415 {
00416
00417 unsigned val = seed;
00418
00419 for (register unsigned i=0; i<Size; i++)
00420 {
00421 val = HashT()(lst[i], val);
00422 }
00423
00424 return val;
00425 }
00426 }
00427
00428
00429