1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A packed storage unstructured matrix of objects of type \<T\>
30 using an offset table for access.
32 The offset table is the size of the number of rows whose elements are the
33 accumulated sizes of the rows, i.e.
34 - offset[i] gives the index of first element of row i + 1
35 - offset[i] - offset[i-1] is the number of elements in row i
37 and for i = 0, offset[i-1] = 0.
39 Storage is allocated on free-store during construction.
46 \*---------------------------------------------------------------------------*/
48 #ifndef CompactListList_H
49 #define CompactListList_H
51 #include "labelList.H"
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 // Forward declaration of friend functions and operators
60 template<class T> class CompactListList;
62 template<class T> Istream& operator>>(Istream&, CompactListList<T>&);
63 template<class T> Ostream& operator<<(Ostream&, const CompactListList<T>&);
66 /*---------------------------------------------------------------------------*\
67 Class CompactListList Declaration
68 \*---------------------------------------------------------------------------*/
78 //- Packed matrix of data
84 // Static Member Functions
86 //- Return a null CompactListList
87 inline static const CompactListList<T>& null();
92 inline CompactListList();
94 //- Construct by converting given List<List<T> >
95 CompactListList(const List<List<T> >&);
97 //- Construct given size of offset table (number of rows)
98 // and number of data.
99 inline CompactListList(const label nRows, const label nData);
101 //- Construct given size of offset table (number of rows),
102 // the number of data and a value for all elements.
103 inline CompactListList(const label nRows, const label nData, const T&);
105 //- Construct given list of row-sizes.
106 CompactListList(const UList<label>& rowSizes);
108 //- Construct given list of row-sizes
109 CompactListList(const UList<label>& rowSizes, const T&);
111 //- Construct by transferring the parameter contents
112 CompactListList(const Xfer<CompactListList<T> >&);
114 //- Construct as copy or re-use as specified.
115 CompactListList(CompactListList<T>&, bool reUse);
117 //- Construct from Istream.
118 CompactListList(Istream&);
121 inline autoPtr<CompactListList<T> > clone() const;
128 //- Return the primary size, i.e. the number of rows
129 inline label size() const;
131 //- Return true if the number of rows is zero
132 inline bool empty() const;
134 //- Return the offset table
135 inline const List<label>& offsets() const;
137 //- Return non-const access to the offset table
138 inline List<label>& offsets();
140 //- Return the packed matrix of data
141 inline const List<T>& m() const;
143 //- Return non-const access to the packed matrix of data
149 //- Reset size of CompactListList.
150 // This form only allows contraction of the CompactListList.
151 void setSize(const label nRows);
153 //- Reset size of CompactListList.
154 void setSize(const label nRows, const label nData);
156 //- Reset sizes of CompactListList and value for new elements.
157 void setSize(const label nRows, const label nData, const T&);
159 //- Reset size of CompactListList.
160 void setSize(const UList<label>& rowSizes);
162 //- Reset size of CompactListList.
163 // This form only allows contraction of the CompactListList.
164 inline void resize(const label nRows);
166 //- Reset size of CompactListList.
167 inline void resize(const label nRows, const label nData);
169 //- Reset sizes of CompactListList and value for new elements.
170 inline void resize(const label nRows, const label nData, const T&);
172 //- Reset size of CompactListList.
173 inline void resize(const UList<label>& rowSizes);
175 //- Clear the CompactListList, i.e. set sizes to zero.
178 //- Return sizes (to be used e.g. for construction)
179 labelList sizes() const;
181 //- Transfer the contents of the argument CompactListList
182 // into this CompactListList and annull the argument list.
183 void transfer(CompactListList<T>&);
185 //- Transfer the contents to the Xfer container
186 inline Xfer<CompactListList<T> > xfer();
190 //- Return index into m
191 inline label index(const label row, const label col) const;
193 //- Get row for index into m.
194 inline label whichRow(const label index) const;
196 //- Get column index (j) given above row
197 inline label whichColumn(const label row, const label index) const;
202 //- Return subscript-checked row as UList.
203 inline UList<T> operator[](const label i);
205 //- Return const subscript-checked row as UList.
206 inline const UList<T> operator[](const label i) const;
208 //- Return subscript-checked element.
209 inline T& operator()(const label i, const label j);
211 //- Return const subscript-checked element.
212 inline const T& operator()(const label i, const label j) const;
214 //- Return as List<List<T> >
215 List<List<T> > operator()() const;
217 //- Assignment of all entries to the given value
218 inline void operator=(const T&);
223 //- Read CompactListList from Istream, discarding contents
224 // of existing CompactListList.
225 friend Istream& operator>> <T>(Istream&, CompactListList<T>&);
227 // Write CompactListList to Ostream.
228 friend Ostream& operator<< <T>(Ostream&, const CompactListList<T>&);
232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 } // End namespace Foam
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 # include "CompactListListI.H"
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 # include "CompactListList.C"
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 // ************************************************************************* //