00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 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 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your 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, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::SortableList 00026 00027 Description 00028 A list that is sorted upon construction or when explicitly requested 00029 with the sort() method. 00030 00031 Uses the Foam::stableSort() algorithm. 00032 00033 SourceFiles 00034 SortableList.C 00035 00036 \*---------------------------------------------------------------------------*/ 00037 00038 #ifndef SortableList_H 00039 #define SortableList_H 00040 00041 #include <OpenFOAM/labelList.H> 00042 00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00044 00045 namespace Foam 00046 { 00047 00048 /*---------------------------------------------------------------------------*\ 00049 Class SortableList Declaration 00050 \*---------------------------------------------------------------------------*/ 00051 00052 template<class T> 00053 class SortableList 00054 : 00055 public List<T> 00056 { 00057 // Private data 00058 00059 //- Original indices 00060 labelList indices_; 00061 00062 //- Resize, fill and sort the parameter according to the list values 00063 void sortIndices(List<label>&) const; 00064 00065 public: 00066 00067 // Constructors 00068 00069 //- Null constructor, sort later (eg, after assignment or transfer) 00070 SortableList(); 00071 00072 //- Construct from UList, sorting immediately. 00073 explicit SortableList(const UList<T>&); 00074 00075 //- Construct from transferred List, sorting immediately. 00076 explicit SortableList(const Xfer<List<T> >&); 00077 00078 //- Construct given size. Sort later on. 00079 // The indices remain empty until the list is sorted 00080 explicit SortableList(const label size); 00081 00082 //- Construct given size and initial value. Sort later on. 00083 // The indices remain empty until the list is sorted 00084 SortableList(const label size, const T&); 00085 00086 //- Construct as copy. 00087 SortableList(const SortableList<T>&); 00088 00089 00090 // Member Functions 00091 00092 //- Return the list of sorted indices. Updated every sort. 00093 const labelList& indices() const 00094 { 00095 return indices_; 00096 } 00097 00098 //- Return non-const access to the sorted indices. Updated every sort. 00099 labelList& indices() 00100 { 00101 return indices_; 00102 } 00103 00104 //- Clear the list and the indices 00105 void clear(); 00106 00107 //- Clear the indices and return a reference to the underlying List 00108 List<T>& shrink(); 00109 00110 //- (stable) sort the list (if changed after construction time) 00111 // also resizes the indices as required 00112 void sort(); 00113 00114 //- Reverse (stable) sort the list 00115 void reverseSort(); 00116 00117 //- Transfer contents to the Xfer container as a plain List 00118 inline Xfer<List<T> > xfer(); 00119 00120 00121 // Member Operators 00122 00123 //- Assignment of all entries to the given value 00124 inline void operator=(const T&); 00125 00126 //- Assignment from UList operator. Takes linear time. 00127 inline void operator=(const UList<T>&); 00128 00129 //- Assignment operator. Takes linear time. 00130 inline void operator=(const SortableList<T>&); 00131 00132 }; 00133 00134 00135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00136 00137 } // End namespace Foam 00138 00139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00140 00141 #ifdef NoRepository 00142 # include <OpenFOAM/SortableList.C> 00143 #endif 00144 00145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00146 00147 #endif 00148 00149 // ************************ vim: set sw=4 sts=4 et: ************************ //