![]() |
|
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2005 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 SortableList 00027 00028 Description 00029 00030 SourceFiles 00031 SortableList.C 00032 00033 \*---------------------------------------------------------------------------*/ 00034 00035 #ifndef SortableList_H 00036 #define SortableList_H 00037 00038 #include "labelList.H" 00039 00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00041 00042 namespace Foam 00043 { 00044 00045 /*---------------------------------------------------------------------------*\ 00046 Class SortableList Declaration 00047 \*---------------------------------------------------------------------------*/ 00048 00049 template <class Type> 00050 class SortableList 00051 : 00052 public List<Type> 00053 { 00054 // Private data 00055 00056 //- Original indices 00057 labelList indices_; 00058 00059 00060 public: 00061 00062 // Public classes 00063 00064 //- Less function class used by the sort function 00065 class less 00066 { 00067 const UList<Type>& values_; 00068 00069 public: 00070 00071 less(const UList<Type>& values) 00072 : 00073 values_(values) 00074 {} 00075 00076 bool operator()(const label a, const label b) 00077 { 00078 return values_[a] < values_[b]; 00079 } 00080 }; 00081 00082 00083 // Constructors 00084 00085 //- Construct from List, sorting the elements. Starts with indices set 00086 // to index in argument 00087 SortableList(const List<Type>&); 00088 00089 //- Construct from List, sorting the elements. Starts with indices 00090 // as given 00091 SortableList(const List<Type>&, const labelList&); 00092 00093 //- Construct given size. Sort later on. 00094 SortableList(const label size); 00095 00096 //- Construct given size and initial value. Sort later on. 00097 SortableList(const label size, const Type&); 00098 00099 //- Construct as copy. 00100 SortableList(const SortableList<Type>&); 00101 00102 00103 // Member Functions 00104 00105 //- Return the list of sorted point indices 00106 const labelList& indices() const 00107 { 00108 return indices_; 00109 } 00110 00111 //- Size the list (shrink or grow followed by sort) 00112 void setSize(const label); 00113 00114 //- Sort the list (if changed after construction time) 00115 void sort(); 00116 00117 00118 // Member Operators 00119 00120 void operator=(const SortableList<Type>&); 00121 00122 }; 00123 00124 00125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00126 00127 } // End namespace Foam 00128 00129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00130 00131 #ifdef NoRepository 00132 # include "SortableList.C" 00133 #endif 00134 00135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00136 00137 #endif 00138 00139 // ************************************************************************* //