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