CompactIOList.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-2022 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::CompactIOList
26 
27 Description
28  A List of objects of type <Type> with automated input and output using
29  a compact storage. Behaves like IOList except when binary output in
30  case it writes a CompactListList.
31 
32  Useful for lists of small sublists e.g. faceList, cellList.
33 
34 SourceFiles
35  CompactIOList.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef CompactIOList_H
40 #define CompactIOList_H
41 
42 #include "IOList.H"
43 #include "regIOobject.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward declaration of friend functions and operators
51 template
52 <
53  template<class> class Container,
54  template<class> class IOContainer,
55  template<class> class CompactIOContainer,
56  class Type
57 >
58 class CompactIOListBase;
59 
60 template
61 <
62  template<class> class Container,
63  template<class> class IOContainer,
64  template<class> class CompactIOContainer,
65  class Type
66 >
67 void writeEntry
68 (
69  Ostream&,
70  const CompactIOListBase<Container, IOContainer, CompactIOContainer, Type>&
71 );
72 
73 template
74 <
75  template<class> class Container,
76  template<class> class IOContainer,
77  template<class> class CompactIOContainer,
78  class Type
79 >
80 Istream& operator>>
81 (
82  Istream&,
84 );
85 
86 template
87 <
88  template<class> class Container,
89  template<class> class IOContainer,
90  template<class> class CompactIOContainer,
91  class Type
92 >
93 Ostream& operator<<
94 (
95  Ostream&,
97 );
98 
99 
100 /*---------------------------------------------------------------------------*\
101  Class CompactIOListBase Declaration
102 \*---------------------------------------------------------------------------*/
103 
104 template
105 <
106  template<class> class Container,
107  template<class> class IOContainer,
108  template<class> class CompactIOContainer,
109  class Type
110 >
111 class CompactIOListBase
112 :
113  public regIOobject,
114  public Container<Type>
115 {
116  // Private Member Functions
117 
118  //- Does the container have too many elements to represent with the
119  // current integer size type?
120  bool overflows() const;
121 
122  //- Convert the data to a compact representation
123  void convertToCompact
124  (
125  labelList& start,
127  ) const;
128 
129  //- Convert the data from a compact representation
130  void convertFromCompact
131  (
132  const labelList& start,
134  );
135 
136  //- Read according to header type
137  void readFromStream(const bool read = true);
138 
139 
140 public:
141 
142  // Constructors
143 
144  //- Construct from IOobject
145  CompactIOListBase(const IOobject&);
146 
147  //- Construct from IOobject; does local processor require reading?
148  CompactIOListBase(const IOobject&, const bool read);
149 
150  //- Construct from IOobject and size of CompactIOListBase
151  CompactIOListBase(const IOobject&, const label);
152 
153  //- Construct from IOobject and a Container
154  CompactIOListBase(const IOobject&, const Container<Type>&);
155 
156  //- Move construct by transferring the Container contents
157  CompactIOListBase(const IOobject&, Container<Type>&&);
158 
159  //- Move constructor
161  (
163  <
164  Container,
165  IOContainer,
166  CompactIOContainer,
167  Type
168  >&&
169  );
170 
171 
172  //- Destructor
173  virtual ~CompactIOListBase();
174 
175 
176  // Member Functions
177 
178  //- WriteObject function. Changes the write type depending on whether
179  // the output is compact or not.
180  virtual bool writeObject
181  (
185  const bool write
186  ) const;
187 
188  //- WriteData function required for regIOobject write operation
189  virtual bool writeData(Ostream&) const;
190 
191 
192  // Member Operators
193 
194  //- Inherit assignment operators
195  using Container<Type>::operator=;
196 
197  //- Assign to another CompactIOList
198  void operator=
199  (
200  const CompactIOListBase
201  <
202  Container,
203  IOContainer,
204  CompactIOContainer,
205  Type
206  >&
207  );
208 
209  //- Move-assign to another CompactIOList
210  void operator=
211  (
213  <
214  Container,
215  IOContainer,
216  CompactIOContainer,
217  Type
218  >&&
219  );
220 
221 
222  // IOstream functions
223 
224  //- Write list to Ostream
225  friend void writeEntry
226  <
227  Container,
228  IOContainer,
229  CompactIOContainer,
230  Type
231  >
232  (
233  Ostream&,
234  const CompactIOListBase
235  <
236  Container,
237  IOContainer,
238  CompactIOContainer,
239  Type
240  >&
241  );
242 
243 
244  // IOstream Operators
245 
246  //- Read list from Istream
247  friend Istream& operator>>
248  <
249  Container,
250  IOContainer,
251  CompactIOContainer,
252  Type
253  >
254  (
255  Istream&,
257  <
258  Container,
259  IOContainer,
260  CompactIOContainer,
261  Type
262  >&
263  );
264 
265  // Write list to Ostream
266  friend Ostream& operator<<
267  <
268  Container,
269  IOContainer,
270  CompactIOContainer,
271  Type
272  >
273  (
274  Ostream&,
275  const CompactIOListBase
276  <
277  Container,
278  IOContainer,
279  CompactIOContainer,
280  Type
281  >&
282  );
283 };
284 
285 
286 /*---------------------------------------------------------------------------*\
287  Class CompactIOList Declaration
288 \*---------------------------------------------------------------------------*/
289 
290 template<class Type>
291 class CompactIOList
292 :
293  public CompactIOListBase<List, IOList, CompactIOList, Type>
294 {
295 
296 public:
297 
298  //- Runtime type information
299  TypeName("ListList");
300 
301 
302  // Constructors
303 
304  //- Inherit constructors
305  using
308 
309 
310  // Member Operators
311 
312  //- Inherit assignment operators
313  using
315  operator=;
316 };
317 
318 
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 
321 } // End namespace Foam
322 
323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
324 
325 #ifdef NoRepository
326  #include "CompactIOList.C"
327 #endif
328 
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 
331 #endif
332 
333 // ************************************************************************* //
virtual bool writeData(Ostream &) const
WriteData function required for regIOobject write operation.
virtual ~CompactIOListBase()
Destructor.
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write) const
WriteObject function. Changes the write type depending on whether.
CompactIOListBase(const IOobject &)
Construct from IOobject.
friend void writeEntry(Ostream &, const CompactIOListBase< Container, IOContainer, CompactIOContainer, Type > &)
Write list to Ostream.
A List of objects of type <Type> with automated input and output using a compact storage....
TypeName("ListList")
Runtime type information.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Version number type.
Definition: IOstream.H:97
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
virtual bool write(const bool write=true) const
Write using setting from DB.
virtual bool read()
Read object.
Namespace for OpenFOAM.
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
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96