1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
26 Foam::CompactListList_dev
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+1
33 whose elements are the
34 accumulated sizes of the rows, i.e.
35 - offset[i] gives the index of first element of row i
36 - offset[i+1] - offset[i] is the number of elements in row i
38 Storage is allocated on free-store during construction.
40 As a special case a null-contructed CompactListList_dev has an empty
41 offsets_ (instead of size 1).
45 CompactListList_devI.H
46 CompactListList_devIO.C
48 \*---------------------------------------------------------------------------*/
50 #ifndef CompactListListDev_H
51 #define CompactListListDev_H
53 #include "labelList.H"
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 // Forward declaration of friend functions and operators
62 template<class T, class Container> class CompactListList_dev;
64 template<class T, class Container> Istream& operator>>
67 CompactListList_dev<T, Container>&
69 template<class T, class Container> Ostream& operator<<
72 const CompactListList_dev<T, Container>&
76 /*---------------------------------------------------------------------------*\
77 Class CompactListList_dev Declaration
78 \*---------------------------------------------------------------------------*/
80 template<class T, class Container = List<T> >
81 class CompactListList_dev
90 //- Packed matrix of data
96 // Static Member Functions
98 //- Return a null CompactListList_dev
99 inline static const CompactListList_dev<T, Container>& null();
103 //- Null constructor.
104 inline CompactListList_dev();
106 //- Construct by converting given List<List<T> >
107 explicit CompactListList_dev(const List<Container>&);
109 //- Construct given size of offset table (number of rows)
110 // and number of data.
111 inline CompactListList_dev(const label nRows, const label nData);
113 //- Construct given size of offset table (number of rows),
114 // the number of data and a value for all elements.
115 inline CompactListList_dev(const label nRows, const label nData, const T&);
117 //- Construct given list of row-sizes.
118 explicit CompactListList_dev(const UList<label>& rowSizes);
120 //- Construct given list of row-sizes
121 CompactListList_dev(const UList<label>& rowSizes, const T&);
123 //- Construct by transferring the parameter contents
124 explicit CompactListList_dev(const Xfer<CompactListList_dev<T, Container> >&);
126 //- Construct as copy or re-use as specified.
127 CompactListList_dev(CompactListList_dev<T, Container>&, bool reUse);
129 //- Construct from Istream.
130 CompactListList_dev(Istream&);
133 inline autoPtr<CompactListList_dev<T, Container> > clone() const;
140 //- Return the primary size, i.e. the number of rows
141 inline label size() const;
143 //- Return true if the number of rows is zero
144 inline bool empty() const;
146 //- Return the offset table (= size()+1)
147 inline const List<label>& offsets() const;
149 //- Return non-const access to the offset table
150 inline List<label>& offsets();
152 //- Return the packed matrix of data
153 inline const List<T>& m() const;
155 //- Return non-const access to the packed matrix of data
161 //- Reset size of CompactListList_dev.
162 // This form only allows contraction of the CompactListList_dev.
163 void setSize(const label nRows);
165 //- Reset size of CompactListList_dev.
166 void setSize(const label nRows, const label nData);
168 //- Reset sizes of CompactListList_dev and value for new elements.
169 void setSize(const label nRows, const label nData, const T&);
171 //- Reset size of CompactListList_dev.
172 void setSize(const UList<label>& rowSizes);
174 //- Reset size of CompactListList_dev.
175 // This form only allows contraction of the CompactListList_dev.
176 inline void resize(const label nRows);
178 //- Reset size of CompactListList_dev.
179 inline void resize(const label nRows, const label nData);
181 //- Reset sizes of CompactListList_dev and value for new elements.
182 inline void resize(const label nRows, const label nData, const T&);
184 //- Reset size of CompactListList_dev.
185 inline void resize(const UList<label>& rowSizes);
187 //- Clear the CompactListList_dev, i.e. set sizes to zero.
190 //- Return sizes (to be used e.g. for construction)
191 labelList sizes() const;
193 //- Transfer the contents of the argument CompactListList_dev
194 // into this CompactListList_dev and annul the argument list.
195 void transfer(CompactListList_dev<T, Container>&);
197 //- Transfer the contents to the Xfer container
198 inline Xfer<CompactListList_dev<T, Container> > xfer();
202 //- Return index into m
203 inline label index(const label row, const label col) const;
205 //- Get row for index into m.
206 inline label whichRow(const label index) const;
208 //- Get column index (j) given above row
209 inline label whichColumn(const label row, const label index) const;
214 //- Return subscript-checked row as UList.
215 inline UList<T> operator[](const label i);
217 //- Return const subscript-checked row as UList.
218 inline const UList<T> operator[](const label i) const;
220 //- Return subscript-checked element.
221 inline T& operator()(const label i, const label j);
223 //- Return const subscript-checked element.
224 inline const T& operator()(const label i, const label j) const;
226 //- Return as List<Container>
227 List<Container> operator()() const;
229 //- Assignment of all entries to the given value
230 inline void operator=(const T&);
235 //- Read CompactListList_dev from Istream, discarding contents
236 // of existing CompactListList_dev.
237 friend Istream& operator>> <T, Container>
240 CompactListList_dev<T, Container>&
243 // Write CompactListList_dev to Ostream.
244 friend Ostream& operator<< <T, Container>
247 const CompactListList_dev<T, Container>&
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 } // End namespace Foam
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 # include "CompactListList_devI.H"
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 # include "CompactListList_dev.C"
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 // ************************************************************************* //