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 \*---------------------------------------------------------------------------*/
30 // * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
33 const Foam::UList<T> Foam::UList<T>::zero;
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 inline Foam::UList<T>::UList()
47 inline Foam::UList<T>::UList(T* __restrict__ v, label size)
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 inline const Foam::UList<T>& Foam::UList<T>::null()
63 // Reset in slicing. HJ. 19/Oct/2008
65 inline void Foam::UList<T>::reset(T* __restrict__ v, label size)
73 inline Foam::label Foam::UList<T>::fcIndex(const label i) const
75 return (i == size()-1 ? 0 : i+1);
80 inline Foam::label Foam::UList<T>::rcIndex(const label i) const
82 return (i ? i-1 : size()-1);
86 // Check start is within valid range (0 ... size-1).
88 inline void Foam::UList<T>::checkStart(const label start) const
90 if (start<0 || (start && start>=size_))
92 FatalErrorIn("UList<T>::checkStart(const label)")
93 << "start " << start << " out of range 0 ... " << max(size_-1, 0)
99 // Check size is within valid range (0 ... size).
101 inline void Foam::UList<T>::checkSize(const label size) const
103 if (size<0 || size>size_)
105 FatalErrorIn("UList<T>::checkSize(const label)")
106 << "size " << size << " out of range 0 ... " << size_
107 << abort(FatalError);
112 // Check index i is within valid range (0 ... size-1).
114 inline void Foam::UList<T>::checkIndex(const label i) const
118 FatalErrorIn("UList<T>::checkIndex(const label)")
119 << "attempt to access element from zero sized list"
120 << abort(FatalError);
122 else if (i<0 || i>=size_)
124 FatalErrorIn("UList<T>::checkIndex(const label)")
125 << "index " << i << " out of range 0 ... " << size_-1
126 << abort(FatalError);
132 inline T& Foam::UList<T>::first()
134 return this->operator[](0);
139 inline const T& Foam::UList<T>::first() const
141 return this->operator[](0);
146 inline T& Foam::UList<T>::last()
148 return this->operator[](this->size()-1);
153 inline const T& Foam::UList<T>::last() const
155 return this->operator[](this->size()-1);
160 inline const T* Foam::UList<T>::cdata() const
167 inline T* Foam::UList<T>::data()
173 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
178 inline T& Foam::UList<T>::operator[](const label i)
190 // Template specialization for bool
192 inline const bool& UList<bool>::operator[](const label i) const
194 // lazy evaluation - return false for out-of-range
201 return pTraits<bool>::zero;
205 } // end of namespace Foam
208 // const element access
210 inline const T& Foam::UList<T>::operator[](const label i) const
219 // Allow cast to a const List<T>&
221 inline Foam::UList<T>::operator const Foam::List<T>&() const
223 return *reinterpret_cast<const List<T>*>(this);
227 // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
230 inline typename Foam::UList<T>::iterator
231 Foam::UList<T>::begin()
237 inline typename Foam::UList<T>::const_iterator
238 Foam::UList<T>::begin() const
244 inline typename Foam::UList<T>::const_iterator
245 Foam::UList<T>::cbegin() const
251 inline typename Foam::UList<T>::iterator
252 Foam::UList<T>::end()
258 inline typename Foam::UList<T>::const_iterator
259 Foam::UList<T>::end() const
265 inline typename Foam::UList<T>::const_iterator
266 Foam::UList<T>::cend() const
272 inline typename Foam::UList<T>::iterator
273 Foam::UList<T>::rbegin()
279 inline typename Foam::UList<T>::const_iterator
280 Foam::UList<T>::rbegin() const
286 inline typename Foam::UList<T>::const_iterator
287 Foam::UList<T>::crbegin() const
293 inline typename Foam::UList<T>::iterator
294 Foam::UList<T>::rend()
300 inline typename Foam::UList<T>::const_iterator
301 Foam::UList<T>::rend() const
307 inline typename Foam::UList<T>::const_iterator
308 Foam::UList<T>::crend() const
314 inline Foam::label Foam::UList<T>::size() const
321 inline Foam::label Foam::UList<T>::max_size() const
328 inline bool Foam::UList<T>::empty() const
334 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
337 inline void Foam::reverse(UList<T>& ul, const label n)
339 for (int i=0; i<n/2; i++)
341 Swap(ul[i], ul[n-1-i]);
346 inline void Foam::reverse(UList<T>& ul)
348 reverse(ul, ul.size());
352 // ************************************************************************* //