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 | Copyright (C) 2011-2013 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
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  // Constructors
101 
102  //- Null constructor.
103  inline CompactListList();
104 
105  //- Construct by converting given List<List<T> >
106  explicit CompactListList(const List<Container>&);
107 
108  //- Construct given size of offset table (number of rows)
109  // and number of data.
110  inline CompactListList(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(const label nRows, const label nData, const T&);
115 
116  //- Construct given list of row-sizes.
117  explicit CompactListList(const labelUList& rowSizes);
118 
119  //- Construct given list of row-sizes
120  CompactListList(const labelUList& 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.
161  // This form only allows contraction of the CompactListList.
162  void setSize(const label nRows);
163 
164  //- Reset size of CompactListList.
165  void setSize(const label nRows, const label nData);
166 
167  //- Reset sizes of CompactListList and value for new elements.
168  void setSize(const label nRows, const label nData, const T&);
169 
170  //- Reset size of CompactListList.
171  void setSize(const labelUList& rowSizes);
172 
173  //- Reset size of CompactListList.
174  // This form only allows contraction of the CompactListList.
175  inline void resize(const label nRows);
176 
177  //- Reset size of CompactListList.
178  inline void resize(const label nRows, const label nData);
179 
180  //- Reset sizes of CompactListList and value for new elements.
181  inline void resize(const label nRows, const label nData, const T&);
182 
183  //- Reset size of CompactListList.
184  inline void resize(const labelUList& rowSizes);
185 
186  //- Clear the CompactListList, 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
193  // into this CompactListList 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 from Istream, discarding contents
235  // of existing CompactListList.
236  friend Istream& operator>> <T, Container>
237  (
238  Istream&,
240  );
241 
242  // Write CompactListList 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 "CompactListListI.H"
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 #ifdef NoRepository
262 # include "CompactListList.C"
263 #endif
264 
265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 
267 #endif
268 
269 // ************************************************************************* //
Foam::CompactListList::offsets
const List< label > & offsets() const
Return the offset table (= size()+1)
Definition: CompactListListI.H:102
Foam::CompactListList::m
const List< T > & m() const
Return the packed matrix of data.
Definition: CompactListListI.H:116
Foam::CompactListList::size_
label size_
Definition: CompactListList.H:83
Foam::CompactListList::operator()
List< Container > operator()() const
Return as List<Container>
Definition: CompactListList.C:236
Foam::CompactListList::whichRow
label whichRow(const label index) const
Get row for index into m.
Definition: CompactListListI.H:142
Foam::CompactListList
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
Definition: polyTopoChange.H:91
Foam::CompactListList::operator=
void operator=(const T &)
Assignment of all entries to the given value.
Definition: CompactListListI.H:267
CompactListList.C
Foam::CompactListList::empty
bool empty() const
Return true if the number of rows is zero.
Definition: CompactListListI.H:94
Foam::CompactListList::operator[]
UList< T > operator[](const label i)
Return subscript-checked row as UList.
Definition: CompactListListI.H:219
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
Foam::CompactListList::resize
void resize(const label nRows)
Reset size of CompactListList.
Definition: CompactListListI.H:176
Foam::CompactListList::whichColumn
label whichColumn(const label row, const label index) const
Get column index (j) given above row.
Definition: CompactListListI.H:158
Foam::label
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
labelList.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
Foam::CompactListList::clear
void clear()
Clear the CompactListList, i.e. set sizes to zero.
Definition: CompactListList.C:213
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::CompactListList::transfer
void transfer(CompactListList< T, Container > &)
Transfer the contents of the argument CompactListList.
Definition: CompactListList.C:223
Foam::CompactListList::index
label index(const label row, const label col) const
Return index into m.
Definition: CompactListListI.H:132
Foam::CompactListList::m_
List< T > m_
Packed matrix of data.
Definition: CompactListList.H:89
Foam::graphRow
Definition: graphRow.H:48
Foam::CompactListList::setSize
void setSize(const label nRows)
Reset size of CompactListList.
Definition: CompactListList.C:128
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::CompactListList::sizes
labelList sizes() const
Return sizes (to be used e.g. for construction)
Definition: CompactListList.C:197
Foam::List< label >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Foam::CompactListList::size
label size() const
Return the primary size, i.e. the number of rows.
Definition: CompactListListI.H:87
Foam::CompactListList::CompactListList
CompactListList()
Null constructor.
Definition: CompactListListI.H:32
CompactListListI.H
Foam::CompactListList::xfer
Xfer< CompactListList< T, Container > > xfer()
Transfer the contents to the Xfer container.
Definition: CompactListListI.H:169
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::CompactListList::clone
autoPtr< CompactListList< T, Container > > clone() const
Clone.
Definition: CompactListListI.H:67
Foam::CompactListList::offsets_
List< label > offsets_
Offset table.
Definition: CompactListList.H:86