1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 \*---------------------------------------------------------------------------*/
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 inline Foam::UList<T>::UList()
41 inline Foam::UList<T>::UList(T* __restrict__ v, label size)
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51 inline Foam::label Foam::UList<T>::fcIndex(const label i) const
53 return (i == size()-1 ? 0 : i+1);
58 inline Foam::label Foam::UList<T>::rcIndex(const label i) const
60 return (i == 0 ? size()-1 : i-1);
64 // Check start is within valid range (0 ... size-1).
66 inline void Foam::UList<T>::checkStart(const label start) const
68 if (start<0 || (start && start>=size_))
70 FatalErrorIn("UList<T>::checkStart(const label)")
71 << "start " << start << " out of range 0 ... " << max(size_-1, 0)
77 // Check size is within valid range (0 ... size).
79 inline void Foam::UList<T>::checkSize(const label size) const
81 if (size<0 || size>size_)
83 FatalErrorIn("UList<T>::checkSize(const label)")
84 << "size " << size << " out of range 0 ... " << size_
90 // Check index i is within valid range (0 ... size-1).
92 inline void Foam::UList<T>::checkIndex(const label i) const
96 FatalErrorIn("UList<T>::checkIndex(const label)")
97 << "attempt to access element from zero sized list"
100 else if (i<0 || i>=size_)
102 FatalErrorIn("UList<T>::checkIndex(const label)")
103 << "index " << i << " out of range 0 ... " << size_-1
104 << abort(FatalError);
109 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
111 // Return subscript-checked element access
113 inline T& Foam::UList<T>::operator[](const label i)
122 // Return subscript-checked const element access
124 inline const T& Foam::UList<T>::operator[](const label i) const
133 // Allow cast to a const List<T>&
135 inline Foam::UList<T>::operator const Foam::List<T>&() const
137 return *reinterpret_cast<const List<T>*>(this);
141 // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
144 inline typename Foam::UList<T>::iterator
145 Foam::UList<T>::begin()
151 inline typename Foam::UList<T>::const_iterator
152 Foam::UList<T>::begin() const
158 inline typename Foam::UList<T>::iterator
159 Foam::UList<T>::end()
165 inline typename Foam::UList<T>::const_iterator
166 Foam::UList<T>::end() const
172 inline typename Foam::UList<T>::iterator
173 Foam::UList<T>::rbegin()
179 inline typename Foam::UList<T>::const_iterator
180 Foam::UList<T>::rbegin() const
186 inline typename Foam::UList<T>::iterator
187 Foam::UList<T>::rend()
193 inline typename Foam::UList<T>::const_iterator
194 Foam::UList<T>::rend() const
200 inline Foam::label Foam::UList<T>::size() const
207 inline Foam::label Foam::UList<T>::max_size() const
214 inline bool Foam::UList<T>::empty() const
220 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
223 inline void Foam::reverse(UList<T>& ul, const label n)
225 for (int i=0; i<n/2; i++)
227 Swap(ul[i], ul[n-1-i]);
232 inline void Foam::reverse(UList<T>& ul)
234 reverse(ul, ul.size());
238 // ************************************************************************* //