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 \*---------------------------------------------------------------------------*/
30 #include "ListLoopM.H"
31 #include "contiguous.H"
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38 void Foam::UList<T>::assign(const UList<T>& a)
40 if (a.size_ != this->size_)
42 FatalErrorIn("UList<T>::assign(const UList<T>&)")
43 << "ULists have different sizes: "
44 << this->size_ << " " << a.size_
53 memcpy(this->v_, a.v_, this->byteSize());
58 List_ACCESS(T, (*this), vp);
59 List_CONST_ACCESS(T, a, ap);
60 List_FOR_ALL((*this), i)
61 List_ELEM((*this), vp, i) = List_ELEM(a, ap, i);
68 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
71 void Foam::UList<T>::operator=(const T& t)
73 List_ACCESS(T, (*this), vp);
74 List_FOR_ALL((*this), i)
75 List_ELEM((*this), vp, i) = t;
80 // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
83 void Foam::UList<T>::swap(UList<T>& a)
85 if (a.size_ != this->size_)
87 FatalErrorIn("UList<T>::swap(const UList<T>&)")
88 << "ULists have different sizes: "
89 << this->size_ << " " << a.size_
93 List_ACCESS(T, (*this), vp);
94 List_ACCESS(T, a, ap);
96 List_FOR_ALL((*this), i)
97 tmp = List_ELEM((*this), vp, i);
98 List_ELEM((*this), vp, i) = List_ELEM(a, ap, i);
99 List_ELEM(a, ap, i) = tmp;
104 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 Foam::label Foam::UList<T>::byteSize() const
109 if (!contiguous<T>())
111 FatalErrorIn("UList<T>::byteSize()")
112 << "Cannot return the binary size of a list of "
113 "non-primitive elements"
114 << abort(FatalError);
117 return this->size_*sizeof(T);
122 void Foam::sort(UList<T>& a)
124 std::sort(a.begin(), a.end());
128 template<class T, class Cmp>
129 void Foam::sort(UList<T>& a, const Cmp& cmp)
131 std::sort(a.begin(), a.end(), cmp);
136 void Foam::stableSort(UList<T>& a)
138 std::stable_sort(a.begin(), a.end());
142 template<class T, class Cmp>
143 void Foam::stableSort(UList<T>& a, const Cmp& cmp)
145 std::stable_sort(a.begin(), a.end(), cmp);
149 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
152 bool Foam::UList<T>::operator==(const UList<T>& a) const
154 if (this->size_ != a.size_)
161 List_CONST_ACCESS(T, (*this), vp);
162 List_CONST_ACCESS(T, (a), ap);
164 List_FOR_ALL((*this), i)
165 equal = equal && (List_ELEM((*this), vp, i) == List_ELEM((a), ap, i));
173 bool Foam::UList<T>::operator!=(const UList<T>& a) const
175 return !operator==(a);
180 bool Foam::UList<T>::operator<(const UList<T>& a) const
184 const_iterator vi = begin(), ai = a.begin();
185 vi < end() && ai < a.end();
199 if (this->size_ < a.size_)
211 bool Foam::UList<T>::operator>(const UList<T>& a) const
213 return a.operator<(*this);
218 bool Foam::UList<T>::operator<=(const UList<T>& a) const
220 return !operator>(a);
225 bool Foam::UList<T>::operator>=(const UList<T>& a) const
227 return !operator<(a);
231 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
235 // ************************************************************************* //