|
|
|
CompactListList.HGo 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::CompactListList 00027 00028 Description 00029 A packed storage unstructured matrix of objects of type <T> 00030 using an offset table for access. 00031 00032 The offset table is the size of the number of rows whose elements are the 00033 accumulated sizes of the rows, i.e. 00034 - offset[i] gives the index of first element of row i + 1 00035 - offset[i] - offset[i-1] is the number of elements in row i 00036 00037 and for i = 0, offset[i-1] = 0. 00038 00039 Storage is allocated on free-store during construction. 00040 00041 SourceFiles 00042 CompactListList.C 00043 CompactListListI.H 00044 CompactListListIO.C 00045 00046 \*---------------------------------------------------------------------------*/ 00047 00048 #ifndef CompactListList_H 00049 #define CompactListList_H 00050 00051 #include "labelList.H" 00052 00053 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00054 00055 namespace Foam 00056 { 00057 00058 // Forward declaration of friend functions and operators 00059 00060 template<class T> class CompactListList; 00061 00062 template<class T> Istream& operator>>(Istream&, CompactListList<T>&); 00063 template<class T> Ostream& operator<<(Ostream&, const CompactListList<T>&); 00064 00065 00066 /*---------------------------------------------------------------------------*\ 00067 Class CompactListList Declaration 00068 \*---------------------------------------------------------------------------*/ 00069 00070 template<class T> 00071 class CompactListList 00072 { 00073 // Private data 00074 00075 //- Offset table 00076 List<label> offsets_; 00077 00078 //- Packed matrix of data 00079 List<T> m_; 00080 00081 00082 public: 00083 00084 // Static Member Functions 00085 00086 //- Return a null CompactListList 00087 inline static const CompactListList<T>& null(); 00088 00089 // Constructors 00090 00091 //- Null constructor. 00092 inline CompactListList(); 00093 00094 //- Construct by converting given List<List<T> > 00095 CompactListList(const List<List<T> >&); 00096 00097 //- Construct given size of offset table (number of rows) 00098 // and number of data. 00099 inline CompactListList(const label nRows, const label nData); 00100 00101 //- Construct given size of offset table (number of rows), 00102 // the number of data and a value for all elements. 00103 inline CompactListList(const label nRows, const label nData, const T&); 00104 00105 //- Construct given list of row-sizes. 00106 CompactListList(const UList<label>& rowSizes); 00107 00108 //- Construct given list of row-sizes 00109 CompactListList(const UList<label>& rowSizes, const T&); 00110 00111 //- Construct by transferring the parameter contents 00112 CompactListList(const Xfer<CompactListList<T> >&); 00113 00114 //- Construct as copy or re-use as specified. 00115 CompactListList(CompactListList<T>&, bool reUse); 00116 00117 //- Construct from Istream. 00118 CompactListList(Istream&); 00119 00120 //- Clone 00121 inline autoPtr<CompactListList<T> > clone() const; 00122 00123 00124 // Member Functions 00125 00126 // Access 00127 00128 //- Return the primary size, i.e. the number of rows 00129 inline label size() const; 00130 00131 //- Return true if the number of rows is zero 00132 inline bool empty() const; 00133 00134 //- Return the offset table 00135 inline const List<label>& offsets() const; 00136 00137 //- Return non-const access to the offset table 00138 inline List<label>& offsets(); 00139 00140 //- Return the packed matrix of data 00141 inline const List<T>& m() const; 00142 00143 //- Return non-const access to the packed matrix of data 00144 inline List<T>& m(); 00145 00146 00147 // Edit 00148 00149 //- Reset size of CompactListList. 00150 // This form only allows contraction of the CompactListList. 00151 void setSize(const label nRows); 00152 00153 //- Reset size of CompactListList. 00154 void setSize(const label nRows, const label nData); 00155 00156 //- Reset sizes of CompactListList and value for new elements. 00157 void setSize(const label nRows, const label nData, const T&); 00158 00159 //- Reset size of CompactListList. 00160 void setSize(const UList<label>& rowSizes); 00161 00162 //- Reset size of CompactListList. 00163 // This form only allows contraction of the CompactListList. 00164 inline void resize(const label nRows); 00165 00166 //- Reset size of CompactListList. 00167 inline void resize(const label nRows, const label nData); 00168 00169 //- Reset sizes of CompactListList and value for new elements. 00170 inline void resize(const label nRows, const label nData, const T&); 00171 00172 //- Reset size of CompactListList. 00173 inline void resize(const UList<label>& rowSizes); 00174 00175 //- Clear the CompactListList, i.e. set sizes to zero. 00176 void clear(); 00177 00178 //- Return sizes (to be used e.g. for construction) 00179 labelList sizes() const; 00180 00181 //- Transfer the contents of the argument CompactListList 00182 // into this CompactListList and annull the argument list. 00183 void transfer(CompactListList<T>&); 00184 00185 //- Transfer the contents to the Xfer container 00186 inline Xfer<CompactListList<T> > xfer(); 00187 00188 // Other 00189 00190 //- Return index into m 00191 inline label index(const label row, const label col) const; 00192 00193 //- Get row for index into m. 00194 inline label whichRow(const label index) const; 00195 00196 //- Get column index (j) given above row 00197 inline label whichColumn(const label row, const label index) const; 00198 00199 00200 // Member operators 00201 00202 //- Return subscript-checked row as UList. 00203 inline UList<T> operator[](const label i); 00204 00205 //- Return const subscript-checked row as UList. 00206 inline const UList<T> operator[](const label i) const; 00207 00208 //- Return subscript-checked element. 00209 inline T& operator()(const label i, const label j); 00210 00211 //- Return const subscript-checked element. 00212 inline const T& operator()(const label i, const label j) const; 00213 00214 //- Return as List<List<T> > 00215 List<List<T> > operator()() const; 00216 00217 //- Assignment of all entries to the given value 00218 inline void operator=(const T&); 00219 00220 00221 // Istream operator 00222 00223 //- Read CompactListList from Istream, discarding contents 00224 // of existing CompactListList. 00225 friend Istream& operator>> <T>(Istream&, CompactListList<T>&); 00226 00227 // Write CompactListList to Ostream. 00228 friend Ostream& operator<< <T>(Ostream&, const CompactListList<T>&); 00229 }; 00230 00231 00232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00233 00234 } // End namespace Foam 00235 00236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00237 00238 # include "CompactListListI.H" 00239 00240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00241 00242 #ifdef NoRepository 00243 # include "CompactListList.C" 00244 #endif 00245 00246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00247 00248 #endif 00249 00250 // ************************************************************************* // |