1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
25 Foam::CompactListList_dev
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+1
32 whose elements are the
33 accumulated sizes of the rows, i.e.
34 - offset[i] gives the index of first element of row i
35 - offset[i+1] - offset[i] is the number of elements in row i
37 Storage is allocated on free-store during construction.
39 As a special case a null-contructed CompactListList_dev has an empty
40 offsets_ (instead of size 1).
44 CompactListList_devI.H
45 CompactListList_devIO.C
47 \*---------------------------------------------------------------------------*/
49 #ifndef CompactListListDev_H
50 #define CompactListListDev_H
52 #include <OpenFOAM/labelList.H>
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 // Forward declaration of friend functions and operators
61 template<class T, class Container> class CompactListList_dev;
63 template<class T, class Container> Istream& operator>>
66 CompactListList_dev<T, Container>&
68 template<class T, class Container> Ostream& operator<<
71 const CompactListList_dev<T, Container>&
75 /*---------------------------------------------------------------------------*\
76 Class CompactListList_dev Declaration
77 \*---------------------------------------------------------------------------*/
79 template<class T, class Container = List<T> >
80 class CompactListList_dev
89 //- Packed matrix of data
95 // Static Member Functions
97 //- Return a null CompactListList_dev
98 inline static const CompactListList_dev<T, Container>& null();
102 //- Null constructor.
103 inline CompactListList_dev();
105 //- Construct by converting given List<List<T> >
106 explicit CompactListList_dev(const List<Container>&);
108 //- Construct given size of offset table (number of rows)
109 // and number of data.
110 inline CompactListList_dev(const label nRows, const label nData);
112 //- Construct given size of offset table (number of rows),
113 // the number of data and a value for all elements.
114 inline CompactListList_dev(const label nRows, const label nData, const T&);
116 //- Construct given list of row-sizes.
117 explicit CompactListList_dev(const UList<label>& rowSizes);
119 //- Construct given list of row-sizes
120 CompactListList_dev(const UList<label>& rowSizes, const T&);
122 //- Construct by transferring the parameter contents
123 explicit CompactListList_dev(const Xfer<CompactListList_dev<T, Container> >&);
125 //- Construct as copy or re-use as specified.
126 CompactListList_dev(CompactListList_dev<T, Container>&, bool reUse);
128 //- Construct from Istream.
129 CompactListList_dev(Istream&);
132 inline autoPtr<CompactListList_dev<T, Container> > clone() const;
139 //- Return the primary size, i.e. the number of rows
140 inline label size() const;
142 //- Return true if the number of rows is zero
143 inline bool empty() const;
145 //- Return the offset table (= size()+1)
146 inline const List<label>& offsets() const;
148 //- Return non-const access to the offset table
149 inline List<label>& offsets();
151 //- Return the packed matrix of data
152 inline const List<T>& m() const;
154 //- Return non-const access to the packed matrix of data
160 //- Reset size of CompactListList_dev.
161 // This form only allows contraction of the CompactListList_dev.
162 void setSize(const label nRows);
164 //- Reset size of CompactListList_dev.
165 void setSize(const label nRows, const label nData);
167 //- Reset sizes of CompactListList_dev and value for new elements.
168 void setSize(const label nRows, const label nData, const T&);
170 //- Reset size of CompactListList_dev.
171 void setSize(const UList<label>& rowSizes);
173 //- Reset size of CompactListList_dev.
174 // This form only allows contraction of the CompactListList_dev.
175 inline void resize(const label nRows);
177 //- Reset size of CompactListList_dev.
178 inline void resize(const label nRows, const label nData);
180 //- Reset sizes of CompactListList_dev and value for new elements.
181 inline void resize(const label nRows, const label nData, const T&);
183 //- Reset size of CompactListList_dev.
184 inline void resize(const UList<label>& rowSizes);
186 //- Clear the CompactListList_dev, i.e. set sizes to zero.
189 //- Return sizes (to be used e.g. for construction)
190 labelList sizes() const;
192 //- Transfer the contents of the argument CompactListList_dev
193 // into this CompactListList_dev and annul the argument list.
194 void transfer(CompactListList_dev<T, Container>&);
196 //- Transfer the contents to the Xfer container
197 inline Xfer<CompactListList_dev<T, Container> > xfer();
201 //- Return index into m
202 inline label index(const label row, const label col) const;
204 //- Get row for index into m.
205 inline label whichRow(const label index) const;
207 //- Get column index (j) given above row
208 inline label whichColumn(const label row, const label index) const;
213 //- Return subscript-checked row as UList.
214 inline UList<T> operator[](const label i);
216 //- Return const subscript-checked row as UList.
217 inline const UList<T> operator[](const label i) const;
219 //- Return subscript-checked element.
220 inline T& operator()(const label i, const label j);
222 //- Return const subscript-checked element.
223 inline const T& operator()(const label i, const label j) const;
225 //- Return as List<Container>
226 List<Container> operator()() const;
228 //- Assignment of all entries to the given value
229 inline void operator=(const T&);
234 //- Read CompactListList_dev from Istream, discarding contents
235 // of existing CompactListList_dev.
236 friend Istream& operator>> <T, Container>
239 CompactListList_dev<T, Container>&
242 // Write CompactListList_dev to Ostream.
243 friend Ostream& operator<< <T, Container>
246 const CompactListList_dev<T, Container>&
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 } // End namespace Foam
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 # include "CompactListList_devI.H"
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 # include "CompactListList_dev.C"
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 // ************************ vim: set sw=4 sts=4 et: ************************ //