Reverted changes to avoid warnings from the Icc-11 compiler and added a compiler...
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / Lists / FixedList / FixedListI.H
blob1c3fe7131e6f179ad801a0151da2dd93d746c83e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "UList.H"
28 #include "SLList.H"
29 #include "contiguous.H"
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 template<class T, unsigned Size>
34 inline Foam::FixedList<T, Size>::FixedList()
38 template<class T, unsigned Size>
39 inline Foam::FixedList<T, Size>::FixedList(const T v[Size])
41     for (register unsigned i=0; i<Size; i++)
42     {
43         v_[i] = v[i];
44     }
48 template<class T, unsigned Size>
49 inline Foam::FixedList<T, Size>::FixedList(const T& t)
51     for (register unsigned i=0; i<Size; i++)
52     {
53         v_[i] = t;
54     }
58 template<class T, unsigned Size>
59 inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst)
61     checkSize(lst.size());
63     for (register unsigned i=0; i<Size; i++)
64     {
65         v_[i] = lst[i];
66     }
70 template<class T, unsigned Size>
71 inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
73     checkSize(lst.size());
75     register label i = 0;
76     for
77     (
78         typename SLList<T>::const_iterator iter = lst.begin();
79         iter != lst.end();
80         ++iter
81     )
82     {
83         operator[](i++) = iter();
84     }
88 template<class T, unsigned Size>
89 inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst)
91     for (register unsigned i=0; i<Size; i++)
92     {
93         v_[i] = lst[i];
94     }
98 template<class T, unsigned Size>
99 inline Foam::autoPtr< Foam::FixedList<T, Size> >
100 Foam::FixedList<T, Size>::clone() const
102     return autoPtr< FixedList<T, Size> >(new FixedList<T, Size>(*this));
106 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
108 template<class T, unsigned Size>
109 inline const Foam::FixedList<T, Size>& Foam::FixedList<T, Size>::null()
111     return *reinterpret_cast< FixedList<T, Size>* >(0);
115 template<class T, unsigned Size>
116 inline Foam::label Foam::FixedList<T, Size>::fcIndex(const label i) const
118     return (i == Size-1 ? 0 : i+1);
122 template<class T, unsigned Size>
123 inline Foam::label Foam::FixedList<T, Size>::rcIndex(const label i) const
125     return (i ? i-1 : Size-1);
129 // Check start is within valid range (0 ... size-1).
130 template<class T, unsigned Size>
131 inline void Foam::FixedList<T, Size>::checkStart(const label start) const
133     if (start < 0 || (start && unsigned(start) >= Size))
134     {
135         FatalErrorIn("FixedList<T, Size>::checkStart(const label)")
136             << "start " << start << " out of range 0 ... " << (Size-1)
137             << abort(FatalError);
138     }
142 // Check size is within valid range (0 ... size).
143 template<class T, unsigned Size>
144 inline void Foam::FixedList<T, Size>::checkSize(const label size) const
146     if (size < 0 || unsigned(size) > Size)
147     {
148         FatalErrorIn("FixedList<T, Size>::checkSize(const label)")
149             << "size " << size << " out of range 0 ... " << (Size)
150             << abort(FatalError);
151     }
155 // Check index i is within valid range (0 ... size-1)
156 // The check for zero-sized list is already done in static assert
157 template<class T, unsigned Size>
158 inline void Foam::FixedList<T, Size>::checkIndex(const label i) const
160     if (i < 0 || unsigned(i) >= Size)
161     {
162         FatalErrorIn("FixedList<T, Size>::checkIndex(const label)")
163             << "index " << i << " out of range 0 ... " << (Size-1)
164             << abort(FatalError);
165     }
169 template<class T, unsigned Size>
170 inline void Foam::FixedList<T, Size>::resize(const label s)
172 #   ifdef FULLDEBUG
173     checkSize(s);
174 #   endif
177 template<class T, unsigned Size>
178 inline void Foam::FixedList<T, Size>::setSize(const label s)
180 #   ifdef FULLDEBUG
181     checkSize(s);
182 #   endif
185 template<class T, unsigned Size>
186 inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst)
188     for (register unsigned i=0; i<Size; i++)
189     {
190         v_[i] = lst[i];
191     }
195 template<class T, unsigned Size>
196 inline const T*
197 Foam::FixedList<T, Size>::cdata() const
199     return v_;
203 template<class T, unsigned Size>
204 inline T*
205 Foam::FixedList<T, Size>::data()
207     return v_;
211 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
213 // element access
214 template<class T, unsigned Size>
215 inline T& Foam::FixedList<T, Size>::operator[](const label i)
217 #   ifdef FULLDEBUG
218     checkIndex(i);
219 #   endif
220     return v_[i];
224 // const element access
225 template<class T, unsigned Size>
226 inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
228 #   ifdef FULLDEBUG
229     checkIndex(i);
230 #   endif
231     return v_[i];
235 template<class T, unsigned Size>
236 inline void Foam::FixedList<T, Size>::operator=(const T lst[Size])
238     for (register unsigned i=0; i<Size; i++)
239     {
240         v_[i] = lst[i];
241     }
244 template<class T, unsigned Size>
245 inline void Foam::FixedList<T, Size>::operator=(const UList<T>& lst)
247     checkSize(lst.size());
249     for (register unsigned i=0; i<Size; i++)
250     {
251         v_[i] = lst[i];
252     }
255 template<class T, unsigned Size>
256 inline void Foam::FixedList<T, Size>::operator=(const SLList<T>& lst)
258     checkSize(lst.size());
260     register label i = 0;
261     for
262     (
263         typename SLList<T>::const_iterator iter = lst.begin();
264         iter != lst.end();
265         ++iter
266     )
267     {
268         operator[](i++) = iter();
269     }
272 template<class T, unsigned Size>
273 inline void Foam::FixedList<T, Size>::operator=(const T& t)
275     for (register unsigned i=0; i<Size; i++)
276     {
277         v_[i] = t;
278     }
282 // * * * * * * * * * * * * * * STL Member Functions  * * * * * * * * * * * * //
284 template<class T, unsigned Size>
285 inline typename Foam::FixedList<T, Size>::iterator
286 Foam::FixedList<T, Size>::begin()
288     return v_;
292 template<class T, unsigned Size>
293 inline typename Foam::FixedList<T, Size>::const_iterator
294 Foam::FixedList<T, Size>::begin() const
296     return v_;
300 template<class T, unsigned Size>
301 inline typename Foam::FixedList<T, Size>::const_iterator
302 Foam::FixedList<T, Size>::cbegin() const
304     return v_;
308 template<class T, unsigned Size>
309 inline typename Foam::FixedList<T, Size>::iterator
310 Foam::FixedList<T, Size>::end()
312     return &v_[Size];
316 template<class T, unsigned Size>
317 inline typename Foam::FixedList<T, Size>::const_iterator
318 Foam::FixedList<T, Size>::end() const
320     return &v_[Size];
324 template<class T, unsigned Size>
325 inline typename Foam::FixedList<T, Size>::const_iterator
326 Foam::FixedList<T, Size>::cend() const
328     return &v_[Size];
332 template<class T, unsigned Size>
333 inline typename Foam::FixedList<T, Size>::iterator
334 Foam::FixedList<T, Size>::rbegin()
336     return &v_[Size-1];
340 template<class T, unsigned Size>
341 inline typename Foam::FixedList<T, Size>::const_iterator
342 Foam::FixedList<T, Size>::rbegin() const
344     return &v_[Size-1];
348 template<class T, unsigned Size>
349 inline typename Foam::FixedList<T, Size>::const_iterator
350 Foam::FixedList<T, Size>::crbegin() const
352     return &v_[Size-1];
356 template<class T, unsigned Size>
357 inline typename Foam::FixedList<T, Size>::iterator
358 Foam::FixedList<T, Size>::rend()
360     return &v_[-1];
364 template<class T, unsigned Size>
365 inline typename Foam::FixedList<T, Size>::const_iterator
366 Foam::FixedList<T, Size>::rend() const
368     return &v_[-1];
372 template<class T, unsigned Size>
373 inline typename Foam::FixedList<T, Size>::const_iterator
374 Foam::FixedList<T, Size>::crend() const
376     return &v_[-1];
380 template<class T, unsigned Size>
381 inline Foam::label Foam::FixedList<T, Size>::size() const
383     return Size;
387 template<class T, unsigned Size>
388 inline Foam::label Foam::FixedList<T, Size>::max_size() const
390     return Size;
394 template<class T, unsigned Size>
395 inline bool Foam::FixedList<T, Size>::empty() const
397     return false;
401 template<class T, unsigned Size>
402 template<class HashT>
403 inline unsigned Foam::FixedList<T, Size>::Hash<HashT>::operator()
405     const FixedList<T, Size>& lst,
406     unsigned seed
407 ) const
409     if (contiguous<T>())
410     {
411         // hash directly
412         return Hasher(lst.v_, sizeof(lst.v_), seed);
413     }
414     else
415     {
416         // hash incrementally
417         unsigned val = seed;
419         for (register unsigned i=0; i<Size; i++)
420         {
421             val = HashT()(lst[i], val);
422         }
424         return val;
425     }
429 // ************************************************************************* //