Loading...
Searching...
No Matches
CompactIOList.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-2017 OpenFOAM Foundation
9 Copyright (C) 2018-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::CompactIOList
29
30Description
31 A List of objects of type <T> with automated input and output using
32 a compact storage. Behaves like IOList except when binary output in
33 case it writes a CompactListList.
34
35 Useful for lists of small sublists e.g. faceList, cellList.
36
37SourceFiles
38 CompactIOList.C
39
40\*---------------------------------------------------------------------------*/
41
42#ifndef Foam_CompactIOList_H
43#define Foam_CompactIOList_H
44
45#include "IOList.H"
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
52// Forward Declarations
53template<class T> class CompactIOList;
54
55template<class T> Istream& operator>>(Istream&, CompactIOList<T>&);
56template<class T> Ostream& operator<<(Ostream&, const CompactIOList<T>&);
57
58/*---------------------------------------------------------------------------*\
59 Class CompactIOList Declaration
60\*---------------------------------------------------------------------------*/
61
62template<class T>
63class CompactIOList
64:
65 public regIOobject,
66 public List<T>
67{
68 // Private Member Functions
69
70 //- Read if IOobject flags set. Return true if read.
71 //- Reads according to the header type.
72 // Return true if read.
73 bool readIOcontents();
74
75 //- Read the content size.
76 // Return the size if read, -1 otherwise
77 label readIOsize();
78
79 //- Has too many elements in it?
80 bool overflows() const;
81
82
83public:
84
85 //- The underlying content type
86 typedef List<T> content_type;
87
88 //- Runtime type information
89 TypeName("CompactList");
90
92 // Constructors
93
94 //- Default copy construct
95 CompactIOList(const CompactIOList&) = default;
97 //- Construct from IOobject. Will be zero size if not read.
98 explicit CompactIOList(const IOobject& io);
99
100 //- Construct from IOobject and zero size (if not read)
102
103 //- Construct from IOobject and default length of CompactIOList
104 CompactIOList(const IOobject& io, const label len);
105
106 //- Construct from IOobject and List content
107 CompactIOList(const IOobject& io, const UList<T>& content);
108
109 //- Construct by transferring the List content
110 CompactIOList(const IOobject& io, List<T>&& content);
111
112
113 // Factory Methods
115 //- Read and return content size, -1 if not read.
116 // The IOobject will not be registered
117 static label readContentsSize(const IOobject& io);
118
119 //- Read and return contents. The IOobject will not be registered
120 static List<T> readContents(const IOobject& io);
121
122
123 //- Destructor
124 virtual ~CompactIOList() = default;
125
126
127 // Member Functions
128
129 //- Read as offsets/packed-values and transcribe into *this
131
132 //- Write as offsets/packed-values
134
135 //- Write using stream options. Checks for overflow in binary
136 virtual bool writeObject
137 (
138 IOstreamOption streamOpt,
139 const bool writeOnProc
140 ) const;
141
142 //- Write as plain or compact content (depends on stream format)
143 virtual bool writeData(Ostream& os) const;
145
146 // Member Operators
147
148 //- Copy or move assignment of entries
149 using List<T>::operator=;
151 //- Copy assignment of entries
152 void operator=(const CompactIOList<T>& rhs)
153 {
155 }
156
157 //- Move assignment of entries
159 {
160 List<T>::operator=(std::move(static_cast<List<T>&>(rhs)));
161 }
162};
164
165// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166
167} // End namespace Foam
169// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170
171#ifdef NoRepository
172 #include "CompactIOList.C"
173#endif
174
175// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176
177#endif
178
179// ************************************************************************* //
A List of objects of type <T> with automated input and output using a compact storage....
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options. Checks for overflow in binary.
void operator=(CompactIOList< T > &&rhs)
Move assignment of entries.
List< T > content_type
The underlying content type.
TypeName("CompactList")
Runtime type information.
Ostream & writeCompact(Ostream &os) const
Write as offsets/packed-values.
virtual bool writeData(Ostream &os) const
Write as plain or compact content (depends on stream format).
CompactIOList(const IOobject &io, const label len)
Construct from IOobject and default length of CompactIOList.
virtual ~CompactIOList()=default
Destructor.
CompactIOList(const IOobject &io, Foam::zero)
Construct from IOobject and zero size (if not read).
static List< T > readContents(const IOobject &io)
Read and return contents. The IOobject will not be registered.
CompactIOList(const IOobject &io)
Construct from IOobject. Will be zero size if not read.
CompactIOList(const IOobject &io, const UList< T > &content)
Construct from IOobject and List content.
Istream & readCompact(Istream &is)
Read as offsets/packed-values and transcribe into *this.
void operator=(const CompactIOList< T > &rhs)
Copy assignment of entries.
CompactIOList(const IOobject &io, List< T > &&content)
Construct by transferring the List content.
CompactIOList(const CompactIOList &)=default
Default copy construct.
static label readContentsSize(const IOobject &io)
Read and return content size, -1 if not read.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A simple container for options an IOstream can normally have.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
void operator=(const UList< T > &list)
Assignment to UList operator. Takes linear time.
Definition List.C:381
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
OBJstream os(runTime.globalPath()/outputName)
const auto & io
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68