All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CompactListList.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
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
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-constructed CompactListList has an empty
40  offsets_ (instead of size 1).
41 
42 SourceFiles
43  CompactListList.C
44  CompactListListI.H
45  CompactListListIO.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef CompactListList_H
50 #define CompactListList_H
51 
52 #include "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;
62 
63 template<class T, class Container> Istream& operator>>
64 (
65  Istream&,
66  CompactListList<T, Container>&
67 );
68 template<class T, class Container> Ostream& operator<<
69 (
70  Ostream&,
71  const CompactListList<T, Container>&
72 );
73 
74 
75 /*---------------------------------------------------------------------------*\
76  Class CompactListList Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class T, class Container = List<T>>
80 class CompactListList
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
98  inline static const CompactListList<T, Container>& null();
99 
100 
101  // Constructors
102 
103  //- Null constructor.
104  inline CompactListList();
105 
106  //- Move constructor
107  CompactListList(CompactListList<T, Container>&&);
108 
109  //- Construct by converting given List<List<T>>
110  explicit CompactListList(const List<Container>&);
111 
112  //- Construct given size of offset table (number of rows)
113  // and number of data.
114  inline CompactListList(const label mRows, const label nData);
115 
116  //- Construct given size of offset table (number of rows),
117  // the number of data and a value for all elements.
118  inline CompactListList(const label mRows, const label nData, const T&);
119 
120  //- Construct given list of row-sizes.
121  explicit CompactListList(const labelUList& rowSizes);
122 
123  //- Construct given list of row-sizes
124  CompactListList(const labelUList& rowSizes, const T&);
125 
126  //- Construct as copy or re-use as specified.
127  CompactListList(CompactListList<T, Container>&, bool reuse);
128 
129  //- Construct from Istream.
130  CompactListList(Istream&);
131 
132  //- Clone
133  inline autoPtr<CompactListList<T, Container>> clone() const;
134 
135 
136  // Member Functions
137 
138  // Access
139 
140  //- Return the primary size, i.e. the number of rows
141  inline label size() const;
142 
143  //- Return true if the number of rows is zero
144  inline bool empty() const;
145 
146  //- Return the offset table (= size()+1)
147  inline const List<label>& offsets() const;
148 
149  //- Return non-const access to the offset table
150  inline List<label>& offsets();
151 
152  //- Return the packed matrix of data
153  inline const List<T>& m() const;
154 
155  //- Return non-const access to the packed matrix of data
156  inline List<T>& m();
157 
158 
159  // Edit
160 
161  //- Reset size of CompactListList.
162  // This form only allows contraction of the CompactListList.
163  void setSize(const label mRows);
164 
165  //- Reset size of CompactListList.
166  void setSize(const label mRows, const label nData);
167 
168  //- Reset sizes of CompactListList and value for new elements.
169  void setSize(const label mRows, const label nData, const T&);
170 
171  //- Reset size of CompactListList.
172  void setSize(const labelUList& rowSizes);
173 
174  //- Reset size of CompactListList.
175  // This form only allows contraction of the CompactListList.
176  inline void resize(const label mRows);
177 
178  //- Reset size of CompactListList.
179  inline void resize(const label mRows, const label nData);
180 
181  //- Reset sizes of CompactListList and value for new elements.
182  inline void resize(const label mRows, const label nData, const T&);
183 
184  //- Reset size of CompactListList.
185  inline void resize(const labelUList& rowSizes);
186 
187  //- Clear the CompactListList, i.e. set sizes to zero.
188  void clear();
189 
190  //- Return sizes (to be used e.g. for construction)
191  labelList sizes() const;
192 
193  //- Transfer the contents of the argument CompactListList
194  // into this CompactListList and annul the argument list.
195  void transfer(CompactListList<T, Container>&);
196 
197 
198  // Other
199 
200  //- Return index into m
201  inline label index(const label row, const label col) const;
202 
203  //- Get row for index into m.
204  inline label whichRow(const label index) const;
205 
206  //- Get column index (j) given above row
207  inline label whichColumn(const label row, const label index) const;
208 
209 
210  // Member Operators
211 
212  //- Return subscript-checked row as UList.
213  inline UList<T> operator[](const label i);
214 
215  //- Return const subscript-checked row as UList.
216  inline const UList<T> operator[](const label i) const;
217 
218  //- Return subscript-checked element.
219  inline T& operator()(const label i, const label j);
220 
221  //- Return const subscript-checked element.
222  inline const T& operator()(const label i, const label j) const;
223 
224  //- Return as List<Container>
225  List<Container> operator()() const;
226 
227  //- Move assignment operator
228  inline void operator=(CompactListList<T, Container>&&);
229 
230  //- Assignment of all entries to the given value
231  inline void operator=(const T&);
232 
233 
234  // Istream operator
235 
236  //- Read CompactListList from Istream, discarding contents
237  // of existing CompactListList.
238  friend Istream& operator>> <T, Container>
239  (
240  Istream&,
241  CompactListList<T, Container>&
242  );
243 
244  // Write CompactListList to Ostream.
245  friend Ostream& operator<< <T, Container>
246  (
247  Ostream&,
248  const CompactListList<T, Container>&
249  );
250 };
251 
252 
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 
255 } // End namespace Foam
256 
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 
259  #include "CompactListListI.H"
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 #ifdef NoRepository
264  #include "CompactListList.C"
265 #endif
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 #endif
270 
271 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const List< T > & m() const
Return the packed matrix of data.
void clear()
Clear the CompactListList, i.e. set sizes to zero.
UList< label > labelUList
Definition: UList.H:65
void transfer(CompactListList< T, Container > &)
Transfer the contents of the argument CompactListList.
labelList sizes() const
Return sizes (to be used e.g. for construction)
label size() const
Return the primary size, i.e. the number of rows.
UList< T > operator[](const label i)
Return subscript-checked row as UList.
CompactListList()
Null constructor.
List< label > labelList
A List of labels.
Definition: labelList.H:56
label whichColumn(const label row, const label index) const
Get column index (j) given above row.
void resize(const label mRows)
Reset size of CompactListList.
void setSize(const label mRows)
Reset size of CompactListList.
autoPtr< CompactListList< T, Container > > clone() const
Clone.
void operator=(CompactListList< T, Container > &&)
Move assignment operator.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
static const CompactListList< T, Container > & null()
Return a null CompactListList.
const List< label > & offsets() const
Return the offset table (= size()+1)
label index(const label row, const label col) const
Return index into m.
List< Container > operator()() const
Return as List<Container>
label whichRow(const label index) const
Get row for index into m.
Namespace for OpenFOAM.
bool empty() const
Return true if the number of rows is zero.