|
|
|
SortableList.CGo 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 \*---------------------------------------------------------------------------*/ 00026 00027 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // 00028 00029 template<class T> 00030 void Foam::SortableList<T>::sortIndices(List<label>& order) const 00031 { 00032 // list lengths must be identical 00033 if (order.size() != this->size()) 00034 { 00035 // avoid copying any elements, they are overwritten anyhow 00036 order.clear(); 00037 order.setSize(this->size()); 00038 } 00039 00040 forAll(order, elemI) 00041 { 00042 order[elemI] = elemI; 00043 } 00044 Foam::stableSort(order, typename UList<T>::less(*this)); 00045 } 00046 00047 00048 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // 00049 00050 template<class T> 00051 Foam::SortableList<T>::SortableList() 00052 {} 00053 00054 00055 template<class T> 00056 Foam::SortableList<T>::SortableList(const UList<T>& values) 00057 : 00058 List<T>(values) 00059 { 00060 sort(); 00061 } 00062 00063 00064 template<class T> 00065 Foam::SortableList<T>::SortableList(const Xfer<List<T> >& values) 00066 : 00067 List<T>(values) 00068 { 00069 sort(); 00070 } 00071 00072 00073 template<class T> 00074 Foam::SortableList<T>::SortableList(const label size) 00075 : 00076 List<T>(size) 00077 {} 00078 00079 00080 template<class T> 00081 Foam::SortableList<T>::SortableList(const label size, const T& val) 00082 : 00083 List<T>(size, val) 00084 {} 00085 00086 00087 template<class T> 00088 Foam::SortableList<T>::SortableList(const SortableList<T>& lst) 00089 : 00090 List<T>(lst), 00091 indices_(lst.indices()) 00092 {} 00093 00094 00095 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // 00096 00097 00098 template<class T> 00099 void Foam::SortableList<T>::clear() 00100 { 00101 List<T>::clear(); 00102 indices_.clear(); 00103 } 00104 00105 00106 template<class T> 00107 Foam::List<T>& Foam::SortableList<T>::shrink() 00108 { 00109 indices_.clear(); 00110 return static_cast<List<T>&>(*this); 00111 } 00112 00113 00114 template<class T> 00115 void Foam::SortableList<T>::sort() 00116 { 00117 sortIndices(indices_); 00118 00119 List<T> lst(this->size()); 00120 forAll(indices_, i) 00121 { 00122 lst[i] = this->operator[](indices_[i]); 00123 } 00124 00125 List<T>::transfer(lst); 00126 } 00127 00128 00129 template<class T> 00130 void Foam::SortableList<T>::reverseSort() 00131 { 00132 sortIndices(indices_); 00133 00134 List<T> lst(this->size()); 00135 label endI = indices_.size(); 00136 forAll(indices_, i) 00137 { 00138 lst[--endI] = this->operator[](indices_[i]); 00139 } 00140 00141 List<T>::transfer(lst); 00142 } 00143 00144 00145 template<class T> 00146 Foam::Xfer<Foam::List<T> > Foam::SortableList<T>::xfer() 00147 { 00148 return xferMoveTo<List<T> >(*this); 00149 } 00150 00151 00152 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // 00153 00154 template<class T> 00155 inline void Foam::SortableList<T>::operator=(const T& t) 00156 { 00157 UList<T>::operator=(t); 00158 } 00159 00160 00161 template<class T> 00162 inline void Foam::SortableList<T>::operator=(const UList<T>& rhs) 00163 { 00164 List<T>::operator=(rhs); 00165 indices_.clear(); 00166 } 00167 00168 00169 template<class T> 00170 inline void Foam::SortableList<T>::operator=(const SortableList<T>& rhs) 00171 { 00172 List<T>::operator=(rhs); 00173 indices_ = rhs.indices(); 00174 } 00175 00176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00177 00178 // ************************************************************************* // |