1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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 \*---------------------------------------------------------------------------*/
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++)
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++)
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++)
70 template<class T, unsigned Size>
71 inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
73 checkSize(lst.size());
78 typename SLList<T>::const_iterator iter = lst.begin();
83 operator[](i++) = iter();
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++)
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))
135 FatalErrorIn("FixedList<T, Size>::checkStart(const label)")
136 << "start " << start << " out of range 0 ... " << (Size-1)
137 << abort(FatalError);
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)
148 FatalErrorIn("FixedList<T, Size>::checkSize(const label)")
149 << "size " << size << " out of range 0 ... " << (Size)
150 << abort(FatalError);
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)
162 FatalErrorIn("FixedList<T, Size>::checkIndex(const label)")
163 << "index " << i << " out of range 0 ... " << (Size-1)
164 << abort(FatalError);
169 template<class T, unsigned Size>
170 inline void Foam::FixedList<T, Size>::resize(const label s)
177 template<class T, unsigned Size>
178 inline void Foam::FixedList<T, Size>::setSize(const label s)
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++)
195 template<class T, unsigned Size>
197 Foam::FixedList<T, Size>::cdata() const
203 template<class T, unsigned Size>
205 Foam::FixedList<T, Size>::data()
211 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
214 template<class T, unsigned Size>
215 inline T& Foam::FixedList<T, Size>::operator[](const label i)
224 // const element access
225 template<class T, unsigned Size>
226 inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
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++)
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++)
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;
263 typename SLList<T>::const_iterator iter = lst.begin();
268 operator[](i++) = iter();
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++)
282 // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
284 template<class T, unsigned Size>
285 inline typename Foam::FixedList<T, Size>::iterator
286 Foam::FixedList<T, Size>::begin()
292 template<class T, unsigned Size>
293 inline typename Foam::FixedList<T, Size>::const_iterator
294 Foam::FixedList<T, Size>::begin() const
300 template<class T, unsigned Size>
301 inline typename Foam::FixedList<T, Size>::const_iterator
302 Foam::FixedList<T, Size>::cbegin() const
308 template<class T, unsigned Size>
309 inline typename Foam::FixedList<T, Size>::iterator
310 Foam::FixedList<T, Size>::end()
316 template<class T, unsigned Size>
317 inline typename Foam::FixedList<T, Size>::const_iterator
318 Foam::FixedList<T, Size>::end() const
324 template<class T, unsigned Size>
325 inline typename Foam::FixedList<T, Size>::const_iterator
326 Foam::FixedList<T, Size>::cend() const
332 template<class T, unsigned Size>
333 inline typename Foam::FixedList<T, Size>::iterator
334 Foam::FixedList<T, Size>::rbegin()
340 template<class T, unsigned Size>
341 inline typename Foam::FixedList<T, Size>::const_iterator
342 Foam::FixedList<T, Size>::rbegin() const
348 template<class T, unsigned Size>
349 inline typename Foam::FixedList<T, Size>::const_iterator
350 Foam::FixedList<T, Size>::crbegin() const
356 template<class T, unsigned Size>
357 inline typename Foam::FixedList<T, Size>::iterator
358 Foam::FixedList<T, Size>::rend()
364 template<class T, unsigned Size>
365 inline typename Foam::FixedList<T, Size>::const_iterator
366 Foam::FixedList<T, Size>::rend() const
372 template<class T, unsigned Size>
373 inline typename Foam::FixedList<T, Size>::const_iterator
374 Foam::FixedList<T, Size>::crend() const
380 template<class T, unsigned Size>
381 inline Foam::label Foam::FixedList<T, Size>::size() const
387 template<class T, unsigned Size>
388 inline Foam::label Foam::FixedList<T, Size>::max_size() const
394 template<class T, unsigned Size>
395 inline bool Foam::FixedList<T, Size>::empty() const
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,
412 return Hasher(lst.v_, sizeof(lst.v_), seed);
416 // hash incrementally
419 for (register unsigned i=0; i<Size; i++)
421 val = HashT()(lst[i], val);
429 // ************************************************************************* //