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 #include "ListLoopM.H"
31 #include "contiguous.H"
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
36 const Foam::UList<T>& Foam::UList<T>::null()
38 UList<T>* nullPtr = reinterpret_cast<UList<T>*>(NULL);
44 void Foam::UList<T>::assign(const UList<T>& a)
46 if (a.size_ != this->size_)
48 FatalErrorIn("UList<T>::operator=(const UList<T>&)")
49 << "ULists have different sizes: "
50 << this->size_ << " " << a.size_
59 memcpy(this->v_, a.v_, this->byteSize());
64 List_ACCESS(T, (*this), vp);
65 List_CONST_ACCESS(T, a, ap);
66 List_FOR_ALL((*this), i)
67 List_ELEM((*this), vp, i) = List_ELEM(a, ap, i);
74 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
77 void Foam::UList<T>::operator=(const T& t)
79 List_ACCESS(T, (*this), vp);
80 List_FOR_ALL((*this), i)
81 List_ELEM((*this), vp, i) = t;
86 // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
89 void Foam::UList<T>::swap(UList<T>& a)
91 if (a.size_ != this->size_)
93 FatalErrorIn("UList<T>::swap(const UList<T>&)")
94 << "ULists have different sizes: "
95 << this->size_ << " " << a.size_
99 List_ACCESS(T, (*this), vp);
100 List_ACCESS(T, a, ap);
102 List_FOR_ALL((*this), i)
103 tmp = List_ELEM((*this), vp, i);
104 List_ELEM((*this), vp, i) = List_ELEM(a, ap, i);
105 List_ELEM(a, ap, i) = tmp;
110 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 Foam::label Foam::UList<T>::byteSize() const
115 if (!contiguous<T>())
117 FatalErrorIn("UList<T>::byteSize()")
118 << "Cannot return the binary size of a list of "
119 "non-primitive elements"
120 << abort(FatalError);
123 return this->size_*sizeof(T);
127 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
130 bool Foam::UList<T>::operator==(const UList<T>& a) const
132 if (this->size_ != a.size_)
139 List_CONST_ACCESS(T, (*this), vp);
140 List_CONST_ACCESS(T, (a), ap);
142 List_FOR_ALL((*this), i)
143 equal = equal && (List_ELEM((*this), vp, i) == List_ELEM((a), ap, i));
151 bool Foam::UList<T>::operator!=(const UList<T>& a) const
153 return !operator==(a);
158 bool Foam::UList<T>::operator<(const UList<T>& a) const
162 const_iterator vi = begin(), ai = a.begin();
163 vi < end() && ai < a.end();
177 if (this->size_ < a.size_)
189 bool Foam::UList<T>::operator>(const UList<T>& a) const
191 return a.operator<(*this);
196 bool Foam::UList<T>::operator<=(const UList<T>& a) const
198 return !operator>(a);
203 bool Foam::UList<T>::operator>=(const UList<T>& a) const
205 return !operator<(a);
209 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
213 // ************************************************************************* //