1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
28 #include "contiguous.H"
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 template<class T, unsigned Size>
33 inline Foam::FixedList<T, Size>::FixedList()
37 template<class T, unsigned Size>
38 inline Foam::FixedList<T, Size>::FixedList(const T v[Size])
40 for (register unsigned i=0; i<Size; i++)
47 template<class T, unsigned Size>
48 inline Foam::FixedList<T, Size>::FixedList(const T& t)
50 for (register unsigned i=0; i<Size; i++)
57 template<class T, unsigned Size>
58 inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst)
60 checkSize(lst.size());
62 for (register unsigned i=0; i<Size; i++)
69 template<class T, unsigned Size>
70 inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
72 checkSize(lst.size());
77 typename SLList<T>::const_iterator iter = lst.begin();
82 operator[](i++) = iter();
87 template<class T, unsigned Size>
88 inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst)
90 for (register unsigned i = 0; i < Size; i++)
97 template<class T, unsigned Size>
98 inline Foam::autoPtr< Foam::FixedList<T, Size> >
99 Foam::FixedList<T, Size>::clone() const
101 return autoPtr< FixedList<T, Size> >(new FixedList<T, Size>(*this));
105 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 template<class T, unsigned Size>
108 inline const Foam::FixedList<T, Size>& Foam::FixedList<T, Size>::null()
114 template<class T, unsigned Size>
115 inline Foam::label Foam::FixedList<T, Size>::fcIndex(const label i) const
117 return (i == Size-1 ? 0 : i+1);
121 template<class T, unsigned Size>
122 inline Foam::label Foam::FixedList<T, Size>::rcIndex(const label i) const
124 return (i ? i-1 : Size-1);
128 // Check start is within valid range (0 ... size-1).
129 template<class T, unsigned Size>
130 inline void Foam::FixedList<T, Size>::checkStart(const label start) const
132 if (start < 0 || (start && unsigned(start) >= Size))
134 FatalErrorIn("FixedList<T, Size>::checkStart(const label)")
135 << "start " << start << " out of range 0 ... " << (Size-1)
136 << abort(FatalError);
141 // Check size is within valid range (0 ... size).
142 template<class T, unsigned Size>
143 inline void Foam::FixedList<T, Size>::checkSize(const label size) const
145 if (size < 0 || unsigned(size) > Size)
147 FatalErrorIn("FixedList<T, Size>::checkSize(const label)")
148 << "size " << size << " out of range 0 ... " << (Size)
149 << abort(FatalError);
154 // Check index i is within valid range (0 ... size-1)
155 // The check for zero-sized list is already done in static assert
156 template<class T, unsigned Size>
157 inline void Foam::FixedList<T, Size>::checkIndex(const label i) const
159 if (i < 0 || unsigned(i) >= Size)
161 FatalErrorIn("FixedList<T, Size>::checkIndex(const label)")
162 << "index " << i << " out of range 0 ... " << (Size-1)
163 << abort(FatalError);
168 template<class T, unsigned Size>
169 inline void Foam::FixedList<T, Size>::resize(const label s)
176 template<class T, unsigned Size>
177 inline void Foam::FixedList<T, Size>::setSize(const label s)
184 template<class T, unsigned Size>
185 inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst)
187 for (register unsigned i=0; i<Size; i++)
194 template<class T, unsigned Size>
196 Foam::FixedList<T, Size>::cdata() const
202 template<class T, unsigned Size>
204 Foam::FixedList<T, Size>::data()
210 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
213 template<class T, unsigned Size>
214 inline T& Foam::FixedList<T, Size>::operator[](const label i)
223 // const element access
224 template<class T, unsigned Size>
225 inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
234 template<class T, unsigned Size>
235 inline void Foam::FixedList<T, Size>::operator=(const T lst[Size])
237 for (register unsigned i=0; i<Size; i++)
243 template<class T, unsigned Size>
244 inline void Foam::FixedList<T, Size>::operator=(const UList<T>& lst)
246 checkSize(lst.size());
248 for (register unsigned i=0; i<Size; i++)
254 template<class T, unsigned Size>
255 inline void Foam::FixedList<T, Size>::operator=(const SLList<T>& lst)
257 checkSize(lst.size());
259 register label i = 0;
262 typename SLList<T>::const_iterator iter = lst.begin();
267 operator[](i++) = iter();
271 template<class T, unsigned Size>
272 inline void Foam::FixedList<T, Size>::operator=(const T& t)
274 for (register unsigned i=0; i<Size; i++)
281 // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
283 template<class T, unsigned Size>
284 inline typename Foam::FixedList<T, Size>::iterator
285 Foam::FixedList<T, Size>::begin()
291 template<class T, unsigned Size>
292 inline typename Foam::FixedList<T, Size>::const_iterator
293 Foam::FixedList<T, Size>::begin() const
299 template<class T, unsigned Size>
300 inline typename Foam::FixedList<T, Size>::const_iterator
301 Foam::FixedList<T, Size>::cbegin() const
307 template<class T, unsigned Size>
308 inline typename Foam::FixedList<T, Size>::iterator
309 Foam::FixedList<T, Size>::end()
315 template<class T, unsigned Size>
316 inline typename Foam::FixedList<T, Size>::const_iterator
317 Foam::FixedList<T, Size>::end() const
323 template<class T, unsigned Size>
324 inline typename Foam::FixedList<T, Size>::const_iterator
325 Foam::FixedList<T, Size>::cend() const
331 template<class T, unsigned Size>
332 inline typename Foam::FixedList<T, Size>::iterator
333 Foam::FixedList<T, Size>::rbegin()
339 template<class T, unsigned Size>
340 inline typename Foam::FixedList<T, Size>::const_iterator
341 Foam::FixedList<T, Size>::rbegin() const
347 template<class T, unsigned Size>
348 inline typename Foam::FixedList<T, Size>::const_iterator
349 Foam::FixedList<T, Size>::crbegin() const
355 template<class T, unsigned Size>
356 inline typename Foam::FixedList<T, Size>::iterator
357 Foam::FixedList<T, Size>::rend()
363 template<class T, unsigned Size>
364 inline typename Foam::FixedList<T, Size>::const_iterator
365 Foam::FixedList<T, Size>::rend() const
371 template<class T, unsigned Size>
372 inline typename Foam::FixedList<T, Size>::const_iterator
373 Foam::FixedList<T, Size>::crend() const
379 template<class T, unsigned Size>
380 inline Foam::label Foam::FixedList<T, Size>::size() const
386 template<class T, unsigned Size>
387 inline Foam::label Foam::FixedList<T, Size>::max_size() const
393 template<class T, unsigned Size>
394 inline bool Foam::FixedList<T, Size>::empty() const
400 template<class T, unsigned Size>
401 template<class HashT>
402 inline unsigned Foam::FixedList<T, Size>::Hash<HashT>::operator()
404 const FixedList<T, Size>& lst,
411 return Hasher(lst.v_, sizeof(lst.v_), seed);
415 // hash incrementally
418 for (register unsigned i=0; i<Size; i++)
420 val = HashT()(lst[i], val);
428 // ************************************************************************* //