FreeFOAM The Cross-Platform CFD Toolkit
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) 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
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 whose elements are the
32  accumulated sizes of the rows, i.e.
33  - offset[i] gives the index of first element of row i + 1
34  - offset[i] - offset[i-1] is the number of elements in row i
35 
36  and for i = 0, offset[i-1] = 0.
37 
38  Storage is allocated on free-store during construction.
39 
40 SourceFiles
41  CompactListList.C
42  CompactListListI.H
43  CompactListListIO.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef CompactListList_H
48 #define CompactListList_H
49 
50 #include <OpenFOAM/labelList.H>
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // Forward declaration of friend functions and operators
58 
59 template<class T> class CompactListList;
60 
61 template<class T> Istream& operator>>(Istream&, CompactListList<T>&);
62 template<class T> Ostream& operator<<(Ostream&, const CompactListList<T>&);
63 
64 
65 /*---------------------------------------------------------------------------*\
66  Class CompactListList Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 template<class T>
71 {
72  // Private data
73 
74  //- Offset table
75  List<label> offsets_;
76 
77  //- Packed matrix of data
78  List<T> m_;
79 
80 
81 public:
82 
83  // Static Member Functions
84 
85  //- Return a null CompactListList
86  inline static const CompactListList<T>& null();
87 
88  // Constructors
89 
90  //- Null constructor.
91  inline CompactListList();
92 
93  //- Construct by converting given List<List<T> >
94  CompactListList(const List<List<T> >&);
95 
96  //- Construct given size of offset table (number of rows)
97  // and number of data.
98  inline CompactListList(const label nRows, const label nData);
99 
100  //- Construct given size of offset table (number of rows),
101  // the number of data and a value for all elements.
102  inline CompactListList(const label nRows, const label nData, const T&);
103 
104  //- Construct given list of row-sizes.
105  CompactListList(const UList<label>& rowSizes);
106 
107  //- Construct given list of row-sizes
108  CompactListList(const UList<label>& rowSizes, const T&);
109 
110  //- Construct by transferring the parameter contents
112 
113  //- Construct as copy or re-use as specified.
114  CompactListList(CompactListList<T>&, bool reUse);
115 
116  //- Construct from Istream.
118 
119  //- Clone
120  inline autoPtr<CompactListList<T> > clone() const;
121 
122 
123  // Member Functions
124 
125  // Access
126 
127  //- Return the primary size, i.e. the number of rows
128  inline label size() const;
129 
130  //- Return true if the number of rows is zero
131  inline bool empty() const;
132 
133  //- Return the offset table
134  inline const List<label>& offsets() const;
135 
136  //- Return non-const access to the offset table
137  inline List<label>& offsets();
138 
139  //- Return the packed matrix of data
140  inline const List<T>& m() const;
141 
142  //- Return non-const access to the packed matrix of data
143  inline List<T>& m();
144 
145 
146  // Edit
147 
148  //- Reset size of CompactListList.
149  // This form only allows contraction of the CompactListList.
150  void setSize(const label nRows);
151 
152  //- Reset size of CompactListList.
153  void setSize(const label nRows, const label nData);
154 
155  //- Reset sizes of CompactListList and value for new elements.
156  void setSize(const label nRows, const label nData, const T&);
157 
158  //- Reset size of CompactListList.
159  void setSize(const UList<label>& rowSizes);
160 
161  //- Reset size of CompactListList.
162  // This form only allows contraction of the CompactListList.
163  inline void resize(const label nRows);
164 
165  //- Reset size of CompactListList.
166  inline void resize(const label nRows, const label nData);
167 
168  //- Reset sizes of CompactListList and value for new elements.
169  inline void resize(const label nRows, const label nData, const T&);
170 
171  //- Reset size of CompactListList.
172  inline void resize(const UList<label>& rowSizes);
173 
174  //- Clear the CompactListList, i.e. set sizes to zero.
175  void clear();
176 
177  //- Return sizes (to be used e.g. for construction)
178  labelList sizes() const;
179 
180  //- Transfer the contents of the argument CompactListList
181  // into this CompactListList and annull the argument list.
183 
184  //- Transfer the contents to the Xfer container
185  inline Xfer<CompactListList<T> > xfer();
186 
187  // Other
188 
189  //- Return index into m
190  inline label index(const label row, const label col) const;
191 
192  //- Get row for index into m.
193  inline label whichRow(const label index) const;
194 
195  //- Get column index (j) given above row
196  inline label whichColumn(const label row, const label index) const;
197 
198 
199  // Member operators
200 
201  //- Return subscript-checked row as UList.
202  inline UList<T> operator[](const label i);
203 
204  //- Return const subscript-checked row as UList.
205  inline const UList<T> operator[](const label i) const;
206 
207  //- Return subscript-checked element.
208  inline T& operator()(const label i, const label j);
209 
210  //- Return const subscript-checked element.
211  inline const T& operator()(const label i, const label j) const;
212 
213  //- Return as List<List<T> >
214  List<List<T> > operator()() const;
215 
216  //- Assignment of all entries to the given value
217  inline void operator=(const T&);
218 
219 
220  // Istream operator
221 
222  //- Read CompactListList from Istream, discarding contents
223  // of existing CompactListList.
224  friend Istream& operator>> <T>(Istream&, CompactListList<T>&);
225 
226  // Write CompactListList to Ostream.
227  friend Ostream& operator<< <T>(Ostream&, const CompactListList<T>&);
228 };
229 
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 } // End namespace Foam
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 # include <OpenFOAM/CompactListListI.H>
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 #ifdef NoRepository
242 # include <OpenFOAM/CompactListList.C>
243 #endif
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 #endif
248 
249 // ************************ vim: set sw=4 sts=4 et: ************************ //