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 \*---------------------------------------------------------------------------*/
27 #include "OSspecific.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 // Construct from List
35 Foam::SortableList<Type>::SortableList(const List<Type>& values)
38 indices_(values.size())
44 // Construct given size. Sort later on.
46 Foam::SortableList<Type>::SortableList(const label size)
53 // Construct given size and initial value. Sort later on.
55 Foam::SortableList<Type>::SortableList(const label size, const Type& val)
57 List<Type>(size, val),
64 Foam::SortableList<Type>::SortableList(const SortableList<Type>& lst)
67 indices_(lst.indices())
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 void Foam::SortableList<Type>::setSize(const label newSize)
76 List<Type>::setSize(newSize);
77 indices_.setSize(newSize);
82 void Foam::SortableList<Type>::sort()
89 Foam::sort(indices_, less(*this));
91 List<Type> tmpValues(this->size());
95 tmpValues[i] = this->operator[](indices_[i]);
98 List<Type>::transfer(tmpValues);
103 template <class Type>
104 void Foam::SortableList<Type>::stableSort()
111 Foam::stableSort(indices_, less(*this));
113 List<Type> tmpValues(this->size());
117 tmpValues[i] = this->operator[](indices_[i]);
120 List<Type>::transfer(tmpValues);
124 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
126 template <class Type>
127 void Foam::SortableList<Type>::operator=(const SortableList<Type>& rhs)
129 List<Type>::operator=(rhs);
130 indices_ = rhs.indices();
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 // ************************************************************************* //