1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 A packed storage unstructured matrix of objects of type \<T\>
29 using an offset table for access.
31 The offset table is the size of the number of rows whose elements are the
32 accumulated sizes of the rows, i.e.
33 - offset[i] gives the index of first element of row i + 1
34 - offset[i] - offset[i-1] is the number of elements in row i
36 and for i = 0, offset[i-1] = 0.
38 Storage is allocated on free-store during construction.
45 \*---------------------------------------------------------------------------*/
47 #ifndef CompactListList_H
48 #define CompactListList_H
50 #include "labelList.H"
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 // Forward declaration of friend functions and operators
59 template<class T> class CompactListList;
61 template<class T> Istream& operator>>(Istream&, CompactListList<T>&);
62 template<class T> Ostream& operator<<(Ostream&, const CompactListList<T>&);
65 /*---------------------------------------------------------------------------*\
66 Class CompactListList Declaration
67 \*---------------------------------------------------------------------------*/
77 //- Packed matrix of data
83 // Static Member Functions
85 //- Return a null CompactListList
86 inline static const CompactListList<T>& null();
91 inline CompactListList();
93 //- Construct by converting given List<List<T> >
94 CompactListList(const List<List<T> >&);
96 //- Construct given size of offset table (number of rows)
97 // and number of data.
98 inline CompactListList(const label nRows, const label nData);
100 //- Construct given size of offset table (number of rows),
101 // the number of data and a value for all elements.
102 inline CompactListList(const label nRows, const label nData, const T&);
104 //- Construct given list of row-sizes.
105 CompactListList(const UList<label>& rowSizes);
107 //- Construct given list of row-sizes
108 CompactListList(const UList<label>& rowSizes, const T&);
110 //- Construct by transferring the parameter contents
111 CompactListList(const Xfer<CompactListList<T> >&);
113 //- Construct as copy or re-use as specified.
114 CompactListList(CompactListList<T>&, bool reUse);
116 //- Construct from Istream.
117 CompactListList(Istream&);
120 inline autoPtr<CompactListList<T> > clone() const;
127 //- Return the primary size, i.e. the number of rows
128 inline label size() const;
130 //- Return true if the number of rows is zero
131 inline bool empty() const;
133 //- Return the offset table
134 inline const List<label>& offsets() const;
136 //- Return non-const access to the offset table
137 inline List<label>& offsets();
139 //- Return the packed matrix of data
140 inline const List<T>& m() const;
142 //- Return non-const access to the packed matrix of data
148 //- Reset size of CompactListList.
149 // This form only allows contraction of the CompactListList.
150 void setSize(const label nRows);
152 //- Reset size of CompactListList.
153 void setSize(const label nRows, const label nData);
155 //- Reset sizes of CompactListList and value for new elements.
156 void setSize(const label nRows, const label nData, const T&);
158 //- Reset size of CompactListList.
159 void setSize(const UList<label>& rowSizes);
161 //- Reset size of CompactListList.
162 // This form only allows contraction of the CompactListList.
163 inline void resize(const label nRows);
165 //- Reset size of CompactListList.
166 inline void resize(const label nRows, const label nData);
168 //- Reset sizes of CompactListList and value for new elements.
169 inline void resize(const label nRows, const label nData, const T&);
171 //- Reset size of CompactListList.
172 inline void resize(const UList<label>& rowSizes);
174 //- Clear the CompactListList, i.e. set sizes to zero.
177 //- Return sizes (to be used e.g. for construction)
178 labelList sizes() const;
180 //- Transfer the contents of the argument CompactListList
181 // into this CompactListList and annull the argument list.
182 void transfer(CompactListList<T>&);
184 //- Transfer the contents to the Xfer container
185 inline Xfer<CompactListList<T> > xfer();
189 //- Return index into m
190 inline label index(const label row, const label col) const;
192 //- Get row for index into m.
193 inline label whichRow(const label index) const;
195 //- Get column index (j) given above row
196 inline label whichColumn(const label row, const label index) const;
201 //- Return subscript-checked row as UList.
202 inline UList<T> operator[](const label i);
204 //- Return const subscript-checked row as UList.
205 inline const UList<T> operator[](const label i) const;
207 //- Return subscript-checked element.
208 inline T& operator()(const label i, const label j);
210 //- Return const subscript-checked element.
211 inline const T& operator()(const label i, const label j) const;
213 //- Return as List<List<T> >
214 List<List<T> > operator()() const;
216 //- Assignment of all entries to the given value
217 inline void operator=(const T&);
222 //- Read CompactListList from Istream, discarding contents
223 // of existing CompactListList.
224 friend Istream& operator>> <T>(Istream&, CompactListList<T>&);
226 // Write CompactListList to Ostream.
227 friend Ostream& operator<< <T>(Ostream&, const CompactListList<T>&);
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
233 } // End namespace Foam
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 # include "CompactListListI.H"
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 # include "CompactListList.C"
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 // ************************************************************************* //