CompactListList.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::CompactListList
29 
30 Description
31  A packed storage unstructured matrix of objects of type <T>
32  using an offset table for access.
33 
34  The offset table is the size of the number of rows+1
35  whose elements are the
36  accumulated sizes of the rows, i.e.
37  - offset[i] gives the index of first element of row i
38  - offset[i+1] - offset[i] is the number of elements in row i
39 
40  Storage is allocated on free-store during construction.
41 
42  As a special case a null-constructed CompactListList has an empty
43  offsets_ (instead of size 1).
44 
45 SourceFiles
46  CompactListList.C
47  CompactListListI.H
48  CompactListListIO.C
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef CompactListList_H
53 #define CompactListList_H
54 
55 #include "labelList.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 // Forward Declarations
63 
64 template<class T, class Container> class CompactListList;
65 
66 template<class T, class Container> Istream& operator>>
67 (
68  Istream&,
70 );
71 template<class T, class Container> Ostream& operator<<
72 (
73  Ostream&,
75 );
76 
77 
78 /*---------------------------------------------------------------------------*\
79  Class CompactListList Declaration
80 \*---------------------------------------------------------------------------*/
81 
82 template<class T, class Container = List<T>>
83 class CompactListList
84 {
85  // Private Data
86 
87  label size_;
88 
89  //- Offset table
90  List<label> offsets_;
91 
92  //- Packed matrix of data
93  List<T> m_;
94 
95 
96 public:
97 
98  // Static Member Functions
99 
100  //- Return a null CompactListList
101  inline static const CompactListList<T, Container>& null();
102 
103 
104  // Constructors
105 
106  //- Default construct
107  inline CompactListList();
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  //- Copy construct
128 
129  //- Move construct
131 
132  //- Construct as copy or re-use as specified.
133  inline CompactListList(CompactListList<T, Container>& list, bool reuse);
134 
135  //- Construct from Istream.
137 
138  //- Clone
140 
141 
142  // Member Functions
143 
144  // Access
145 
146  //- The primary size (the number of rows)
147  inline label size() const noexcept;
148 
149  //- True if the number of rows is zero
150  inline bool empty() const noexcept;
151 
152  //- Return the offset table (= size()+1)
153  inline const List<label>& offsets() const;
154 
155  //- Return non-const access to the offset table
156  inline List<label>& offsets();
157 
158  //- Return the packed matrix of data
159  inline const List<T>& m() const;
160 
161  //- Return non-const access to the packed matrix of data
162  inline List<T>& m();
163 
164 
165  // Edit
166 
167  //- Reset size of CompactListList.
168  // This form only allows contraction of the CompactListList.
169  void setSize(const label mRows);
170 
171  //- Reset size of CompactListList.
172  void setSize(const label mRows, const label nData);
173 
174  //- Reset sizes of CompactListList and value for new elements.
175  void setSize(const label mRows, const label nData, const T&);
176 
177  //- Reset size of CompactListList.
178  void setSize(const labelUList& rowSizes);
179 
180  //- Reset size of CompactListList.
181  // This form only allows contraction of the CompactListList.
182  inline void resize(const label mRows);
183 
184  //- Reset size of CompactListList.
185  inline void resize(const label mRows, const label nData);
186 
187  //- Reset sizes of CompactListList and value for new elements.
188  inline void resize(const label mRows, const label nData, const T&);
189 
190  //- Reset size of CompactListList.
191  inline void resize(const labelUList& rowSizes);
192 
193  //- Clear the CompactListList, i.e. set sizes to zero.
194  void clear();
195 
196  //- Return sizes (to be used e.g. for construction)
197  labelList sizes() const;
198 
199  //- Swap contents
200  void swap(CompactListList<T, Container>& other);
201 
202  //- Transfer contents into this and annul the argument
203  void transfer(CompactListList<T, Container>& list);
204 
205 
206  // Other
207 
208  //- Return index into m
209  inline label index(const label row, const label col) const;
210 
211  //- Get row for index into m.
212  inline label whichRow(const label index) const;
213 
214  //- Get column index (j) given above row
215  inline label whichColumn(const label row, const label index) const;
216 
217 
218  // Member Operators
219 
220  //- Return subscript-checked row as UList.
221  inline UList<T> operator[](const label i);
222 
223  //- Return const subscript-checked row as UList.
224  inline const UList<T> operator[](const label i) const;
225 
226  //- Return subscript-checked element.
227  inline T& operator()(const label i, const label j);
228 
229  //- Return const subscript-checked element.
230  inline const T& operator()(const label i, const label j) const;
231 
232  //- Return as List<Container>
233  List<Container> operator()() const;
234 
235  //- Assignment of all entries to the given value
236  inline void operator=(const T& val);
237 
238  //- Copy assignment
239  inline void operator=(const CompactListList<T, Container>& lst);
240 
241  //- Move assignment
242  inline void operator=(CompactListList<T, Container>&& lst);
243 
244 
245  // IO Operators
246 
247  //- Read CompactListList from Istream, discarding contents
248  // of existing CompactListList.
249  friend Istream& operator>> <T, Container>
250  (
251  Istream&,
252  CompactListList<T, Container>&
253  );
254 
255  // Write CompactListList to Ostream.
256  friend Ostream& operator<< <T, Container>
257  (
258  Ostream&,
259  const CompactListList<T, Container>&
260  );
261 };
262 
263 
264 // Note: uses default Foam::Swap (move construct/assignment)
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 } // End namespace Foam
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 #include "CompactListListI.H"
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 #ifdef NoRepository
277  #include "CompactListList.C"
278  #include "CompactListListIO.C"
279 #endif
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 #endif
284 
285 // ************************************************************************* //
Foam::CompactListList::offsets
const List< label > & offsets() const
Return the offset table (= size()+1)
Definition: CompactListListI.H:142
Foam::CompactListList::m
const List< T > & m() const
Return the packed matrix of data.
Definition: CompactListListI.H:156
Foam::CompactListList::whichRow
label whichRow(const label index) const
Get row for index into m.
Definition: CompactListListI.H:182
Foam::CompactListList::transfer
void transfer(CompactListList< T, Container > &list)
Transfer contents into this and annul the argument.
Definition: CompactListList.C:220
Foam::CompactListList
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
Definition: CompactListList.H:63
CompactListList.C
Foam::CompactListList::empty
bool empty() const noexcept
True if the number of rows is zero.
Definition: CompactListListI.H:134
Foam::CompactListList::whichColumn
label whichColumn(const label row, const label index) const
Get column index (j) given above row.
Definition: CompactListListI.H:198
Foam::CompactListList::resize
void resize(const label mRows)
Reset size of CompactListList.
Definition: CompactListListI.H:208
labelList.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::CompactListList::setSize
void setSize(const label mRows)
Reset size of CompactListList.
Definition: CompactListList.C:108
Foam::CompactListList::operator
friend Ostream & operator(Ostream &, const CompactListList< T, Container > &)
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::CompactListList::clear
void clear()
Clear the CompactListList, i.e. set sizes to zero.
Definition: CompactListList.C:193
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::CompactListList::index
label index(const label row, const label col) const
Return index into m.
Definition: CompactListListI.H:172
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::CompactListList::sizes
labelList sizes() const
Return sizes (to be used e.g. for construction)
Definition: CompactListList.C:177
Foam::List< label >
Foam::UList< label >
Foam::CompactListList::CompactListList
CompactListList()
Default construct.
Definition: CompactListListI.H:35
Foam::CompactListList::size
label size() const noexcept
The primary size (the number of rows)
Definition: CompactListListI.H:127
Foam::CompactListList::swap
void swap(CompactListList< T, Container > &other)
Swap contents.
Definition: CompactListList.C:203
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::CompactListList::clone
autoPtr< CompactListList< T, Container > > clone() const
Clone.
Definition: CompactListListI.H:110
CompactListListIO.C