OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

SortableList.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::SortableList
00027 
00028 Description
00029     A list that is sorted upon construction or when explicitly requested
00030     with the sort() method.
00031 
00032     Uses the Foam::stableSort() algorithm.
00033 
00034 SourceFiles
00035     SortableList.C
00036 
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef SortableList_H
00040 #define SortableList_H
00041 
00042 #include "labelList.H"
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 /*---------------------------------------------------------------------------*\
00050                         Class SortableList Declaration
00051 \*---------------------------------------------------------------------------*/
00052 
00053 template<class T>
00054 class SortableList
00055 :
00056     public List<T>
00057 {
00058     // Private data
00059 
00060         //- Original indices
00061         labelList indices_;
00062 
00063         //- Resize, fill and sort the parameter according to the list values
00064         void sortIndices(List<label>&) const;
00065 
00066 public:
00067 
00068     // Constructors
00069 
00070         //- Null constructor, sort later (eg, after assignment or transfer)
00071         SortableList();
00072 
00073         //- Construct from UList, sorting immediately.
00074         explicit SortableList(const UList<T>&);
00075 
00076         //- Construct from transferred List, sorting immediately.
00077         explicit SortableList(const Xfer<List<T> >&);
00078 
00079         //- Construct given size. Sort later on.
00080         //  The indices remain empty until the list is sorted
00081         explicit SortableList(const label size);
00082 
00083         //- Construct given size and initial value. Sort later on.
00084         //  The indices remain empty until the list is sorted
00085         SortableList(const label size, const T&);
00086 
00087         //- Construct as copy.
00088         SortableList(const SortableList<T>&);
00089 
00090 
00091     // Member Functions
00092 
00093         //- Return the list of sorted indices. Updated every sort.
00094         const labelList& indices() const
00095         {
00096             return indices_;
00097         }
00098 
00099         //- Return non-const access to the sorted indices. Updated every sort.
00100         labelList& indices()
00101         {
00102             return indices_;
00103         }
00104 
00105         //- Clear the list and the indices
00106         void clear();
00107 
00108         //- Clear the indices and return a reference to the underlying List
00109         List<T>& shrink();
00110 
00111         //- (stable) sort the list (if changed after construction time)
00112         //  also resizes the indices as required
00113         void sort();
00114 
00115         //- Reverse (stable) sort the list
00116         void reverseSort();
00117 
00118         //- Transfer contents to the Xfer container as a plain List
00119         inline Xfer<List<T> > xfer();
00120 
00121 
00122     // Member Operators
00123 
00124         //- Assignment of all entries to the given value
00125         inline void operator=(const T&);
00126 
00127         //- Assignment from UList operator. Takes linear time.
00128         inline void operator=(const UList<T>&);
00129 
00130         //- Assignment operator. Takes linear time.
00131         inline void operator=(const SortableList<T>&);
00132 
00133 };
00134 
00135 
00136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00137 
00138 } // End namespace Foam
00139 
00140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00141 
00142 #ifdef NoRepository
00143 #   include "SortableList.C"
00144 #endif
00145 
00146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00147 
00148 #endif
00149 
00150 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd