1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 \*---------------------------------------------------------------------------*/
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 inline Foam::UList<T>::UList()
42 inline Foam::UList<T>::UList(T* __restrict__ v, label size)
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 inline const Foam::UList<T>& Foam::UList<T>::null()
54 return *reinterpret_cast< UList<T>* >(0);
59 inline Foam::label Foam::UList<T>::fcIndex(const label i) const
61 return (i == size()-1 ? 0 : i+1);
66 inline Foam::label Foam::UList<T>::rcIndex(const label i) const
68 return (i ? i-1 : size()-1);
72 // Check start is within valid range (0 ... size-1).
74 inline void Foam::UList<T>::checkStart(const label start) const
76 if (start<0 || (start && start>=size_))
78 FatalErrorIn("UList<T>::checkStart(const label)")
79 << "start " << start << " out of range 0 ... " << max(size_-1, 0)
85 // Check size is within valid range (0 ... size).
87 inline void Foam::UList<T>::checkSize(const label size) const
89 if (size<0 || size>size_)
91 FatalErrorIn("UList<T>::checkSize(const label)")
92 << "size " << size << " out of range 0 ... " << size_
98 // Check index i is within valid range (0 ... size-1).
100 inline void Foam::UList<T>::checkIndex(const label i) const
104 FatalErrorIn("UList<T>::checkIndex(const label)")
105 << "attempt to access element from zero sized list"
106 << abort(FatalError);
108 else if (i<0 || i>=size_)
110 FatalErrorIn("UList<T>::checkIndex(const label)")
111 << "index " << i << " out of range 0 ... " << size_-1
112 << abort(FatalError);
118 inline const T* Foam::UList<T>::cdata() const
125 inline T* Foam::UList<T>::data()
131 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
136 inline T& Foam::UList<T>::operator[](const label i)
148 // Template specialization for bool
150 inline const bool& Foam::UList<bool>::operator[](const label i) const
152 // lazy evaluation - return false for out-of-range
159 return Foam::pTraits<bool>::zero;
163 } // end of namespace Foam
166 // const element access
168 inline const T& Foam::UList<T>::operator[](const label i) const
177 // Allow cast to a const List<T>&
179 inline Foam::UList<T>::operator const Foam::List<T>&() const
181 return *reinterpret_cast<const List<T>*>(this);
185 // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
188 inline typename Foam::UList<T>::iterator
189 Foam::UList<T>::begin()
195 inline typename Foam::UList<T>::const_iterator
196 Foam::UList<T>::begin() const
202 inline typename Foam::UList<T>::const_iterator
203 Foam::UList<T>::cbegin() const
209 inline typename Foam::UList<T>::iterator
210 Foam::UList<T>::end()
216 inline typename Foam::UList<T>::const_iterator
217 Foam::UList<T>::end() const
223 inline typename Foam::UList<T>::const_iterator
224 Foam::UList<T>::cend() const
230 inline typename Foam::UList<T>::iterator
231 Foam::UList<T>::rbegin()
237 inline typename Foam::UList<T>::const_iterator
238 Foam::UList<T>::rbegin() const
244 inline typename Foam::UList<T>::const_iterator
245 Foam::UList<T>::crbegin() const
251 inline typename Foam::UList<T>::iterator
252 Foam::UList<T>::rend()
258 inline typename Foam::UList<T>::const_iterator
259 Foam::UList<T>::rend() const
265 inline typename Foam::UList<T>::const_iterator
266 Foam::UList<T>::crend() const
272 inline Foam::label Foam::UList<T>::size() const
279 inline Foam::label Foam::UList<T>::max_size() const
286 inline bool Foam::UList<T>::empty() const
292 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
295 inline void Foam::reverse(UList<T>& ul, const label n)
297 for (int i=0; i<n/2; i++)
299 Swap(ul[i], ul[n-1-i]);
304 inline void Foam::reverse(UList<T>& ul)
306 reverse(ul, ul.size());
310 // ************************************************************************* //