FreeFOAM The Cross-Platform CFD Toolkit
CompactListList_dev.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Class
25  Foam::CompactListList_dev
26 
27 Description
28  A packed storage unstructured matrix of objects of type <T>
29  using an offset table for access.
30 
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
36 
37  Storage is allocated on free-store during construction.
38 
39  As a special case a null-contructed CompactListList_dev has an empty
40  offsets_ (instead of size 1).
41 
42 SourceFiles
43  CompactListList_dev.C
44  CompactListList_devI.H
45  CompactListList_devIO.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef CompactListListDev_H
50 #define CompactListListDev_H
51 
52 #include <OpenFOAM/labelList.H>
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 // Forward declaration of friend functions and operators
60 
61 template<class T, class Container> class CompactListList_dev;
62 
63 template<class T, class Container> Istream& operator>>
64 (
65  Istream&,
66  CompactListList_dev<T, Container>&
67 );
68 template<class T, class Container> Ostream& operator<<
69 (
70  Ostream&,
71  const CompactListList_dev<T, Container>&
72 );
73 
74 
75 /*---------------------------------------------------------------------------*\
76  Class CompactListList_dev Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class T, class Container = List<T> >
81 {
82  // Private data
83 
84  label size_;
85 
86  //- Offset table
87  List<label> offsets_;
88 
89  //- Packed matrix of data
90  List<T> m_;
91 
92 
93 public:
94 
95  // Static Member Functions
96 
97  //- Return a null CompactListList_dev
98  inline static const CompactListList_dev<T, Container>& null();
99 
100  // Constructors
101 
102  //- Null constructor.
103  inline CompactListList_dev();
104 
105  //- Construct by converting given List<List<T> >
106  explicit CompactListList_dev(const List<Container>&);
107 
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);
111 
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&);
115 
116  //- Construct given list of row-sizes.
117  explicit CompactListList_dev(const UList<label>& rowSizes);
118 
119  //- Construct given list of row-sizes
120  CompactListList_dev(const UList<label>& rowSizes, const T&);
121 
122  //- Construct by transferring the parameter contents
124 
125  //- Construct as copy or re-use as specified.
127 
128  //- Construct from Istream.
130 
131  //- Clone
133 
134 
135  // Member Functions
136 
137  // Access
138 
139  //- Return the primary size, i.e. the number of rows
140  inline label size() const;
141 
142  //- Return true if the number of rows is zero
143  inline bool empty() const;
144 
145  //- Return the offset table (= size()+1)
146  inline const List<label>& offsets() const;
147 
148  //- Return non-const access to the offset table
149  inline List<label>& offsets();
150 
151  //- Return the packed matrix of data
152  inline const List<T>& m() const;
153 
154  //- Return non-const access to the packed matrix of data
155  inline List<T>& m();
156 
157 
158  // Edit
159 
160  //- Reset size of CompactListList_dev.
161  // This form only allows contraction of the CompactListList_dev.
162  void setSize(const label nRows);
163 
164  //- Reset size of CompactListList_dev.
165  void setSize(const label nRows, const label nData);
166 
167  //- Reset sizes of CompactListList_dev and value for new elements.
168  void setSize(const label nRows, const label nData, const T&);
169 
170  //- Reset size of CompactListList_dev.
171  void setSize(const UList<label>& rowSizes);
172 
173  //- Reset size of CompactListList_dev.
174  // This form only allows contraction of the CompactListList_dev.
175  inline void resize(const label nRows);
176 
177  //- Reset size of CompactListList_dev.
178  inline void resize(const label nRows, const label nData);
179 
180  //- Reset sizes of CompactListList_dev and value for new elements.
181  inline void resize(const label nRows, const label nData, const T&);
182 
183  //- Reset size of CompactListList_dev.
184  inline void resize(const UList<label>& rowSizes);
185 
186  //- Clear the CompactListList_dev, i.e. set sizes to zero.
187  void clear();
188 
189  //- Return sizes (to be used e.g. for construction)
190  labelList sizes() const;
191 
192  //- Transfer the contents of the argument CompactListList_dev
193  // into this CompactListList_dev and annul the argument list.
195 
196  //- Transfer the contents to the Xfer container
198 
199  // Other
200 
201  //- Return index into m
202  inline label index(const label row, const label col) const;
203 
204  //- Get row for index into m.
205  inline label whichRow(const label index) const;
206 
207  //- Get column index (j) given above row
208  inline label whichColumn(const label row, const label index) const;
209 
210 
211  // Member operators
212 
213  //- Return subscript-checked row as UList.
214  inline UList<T> operator[](const label i);
215 
216  //- Return const subscript-checked row as UList.
217  inline const UList<T> operator[](const label i) const;
218 
219  //- Return subscript-checked element.
220  inline T& operator()(const label i, const label j);
221 
222  //- Return const subscript-checked element.
223  inline const T& operator()(const label i, const label j) const;
224 
225  //- Return as List<Container>
226  List<Container> operator()() const;
227 
228  //- Assignment of all entries to the given value
229  inline void operator=(const T&);
230 
231 
232  // Istream operator
233 
234  //- Read CompactListList_dev from Istream, discarding contents
235  // of existing CompactListList_dev.
236  friend Istream& operator>> <T, Container>
237  (
238  Istream&,
240  );
241 
242  // Write CompactListList_dev to Ostream.
243  friend Ostream& operator<< <T, Container>
244  (
245  Ostream&,
247  );
248 };
249 
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 
253 } // End namespace Foam
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 # include "CompactListList_devI.H"
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 #ifdef NoRepository
262 # include "CompactListList_dev.C"
263 #endif
264 
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 
267 #endif
268 
269 // ************************ vim: set sw=4 sts=4 et: ************************ //