Loading...
Searching...
No Matches
IOList.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) 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::IOList
29
30Description
31 A List of objects of type <T> with automated input and output.
32
33SourceFiles
34 IOList.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_IOList_H
39#define Foam_IOList_H
40
41#include "List.H"
42#include "regIOobject.H"
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46namespace Foam
47{
48
49/*---------------------------------------------------------------------------*\
50 Class IOList Declaration
51\*---------------------------------------------------------------------------*/
52
53template<class T>
54class IOList
55:
56 public regIOobject,
57 public List<T>
58{
59 // Private Member Functions
60
61 //- Read if IOobject flags set. Return true if read.
62 bool readIOcontents();
63
64 //- Read the content size.
65 // Return the size if read, -1 otherwise
66 label readIOsize();
67
68public:
69
70 //- The underlying content type
71 typedef List<T> content_type;
72
73 //- Runtime type information
74 TypeName("List");
75
76
77 // Constructors
79 //- Default copy construct
80 IOList(const IOList&) = default;
81
82 //- Construct from IOobject. Will be zero size if not read.
83 explicit IOList(const IOobject& io);
84
85 //- Construct from IOobject and zero size (if not read)
87
88 //- Construct from IOobject and list size (if not read)
89 IOList(const IOobject& io, const label len);
90
91 //- Construct from IOobject and a copy of content
92 IOList(const IOobject& io, const UList<T>& content);
93
94 //- Construct by transferring the content
95 IOList(const IOobject& io, List<T>&& content);
97
98 // Factory Methods
99
100 //- Read and return content size, -1 if not read.
101 // The IOobject is never registered
102 static label readContentsSize(const IOobject& io);
103
104 //- Read and return contents. The IOobject is never registered
105 static List<T> readContents(const IOobject& io);
107 //- Write contents. The IOobject is never registered.
108 // Uses IOListRef internally.
109 static void writeContents(const IOobject& io, const UList<T>& content);
110
112 //- Destructor
113 virtual ~IOList() = default;
114
115
116 // Member Functions
117
118 //- The writeData method for regIOobject write operation
119 virtual bool writeData(Ostream& os) const;
120
122 // Member Operators
123
124 //- Copy or move assignment of entries
125 using List<T>::operator=;
127 //- Copy assignment of entries
128 void operator=(const IOList<T>& rhs)
129 {
131 }
132
133 //- Move assignment of entries
134 void operator=(IOList<T>&& rhs)
135 {
136 List<T>::operator=(std::move(static_cast<List<T>&>(rhs)));
137 }
138};
140
141/*---------------------------------------------------------------------------*\
142 Class IOListRef Declaration
143\*---------------------------------------------------------------------------*/
144
145//- A IOList wrapper for writing external List data
146template<class T>
148:
149 public regIOobject
150{
151 // Private Data
152
153 //- Reference to the external content
154 UList<T> contentRef_;
155
156
157public:
158
159 //- The underlying content type
160 typedef List<T> content_type;
161
162
163 //- Type is identical to IOList
164 virtual const word& type() const
165 {
166 return IOList<T>::typeName;
167 }
169
170 // Generated Methods
171
172 //- No default construct
173 IOListRef() = delete;
174
175 //- No copy construct
176 IOListRef(const IOListRef&) = delete;
177
178 //- No copy assignment
179 void operator=(const IOListRef&) = delete;
180
181
182 // Constructors
184 //- Construct from IOobject and const data reference
185 IOListRef(const IOobject& io, const UList<T>& content);
186
187
188 //- Destructor
189 virtual ~IOListRef() = default;
190
191
192 // Member Functions
193
194 //- Allow cast to const content
195 operator const UList<T>&() const
196 {
197 return contentRef_;
198 }
199
200 //- The writeData method for regIOobject write operation
201 // Fatal if content is not set
202 virtual bool writeData(Ostream& os) const;
203};
204
205
206// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207
208} // End namespace Foam
209
210// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211
212#ifdef NoRepository
213 #include "IOList.C"
214#endif
215
216// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218#endif
219
220// ************************************************************************* //
A IOList wrapper for writing external List data.
Definition IOList.H:186
List< T > content_type
The underlying content type.
Definition IOList.H:200
IOListRef()=delete
No default construct.
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition IOList.C:220
virtual ~IOListRef()=default
Destructor.
void operator=(const IOListRef &)=delete
No copy assignment.
virtual const word & type() const
Type is identical to IOList.
Definition IOList.H:206
IOListRef(const IOListRef &)=delete
No copy construct.
A List of objects of type <T> with automated input and output.
Definition IOList.H:53
List< T > content_type
The underlying content type.
Definition IOList.H:73
void operator=(IOList< T > &&rhs)
Move assignment of entries.
Definition IOList.H:168
IOList(const IOobject &io)
Construct from IOobject. Will be zero size if not read.
Definition IOList.C:75
IOList(const IOobject &io, Foam::zero)
Construct from IOobject and zero size (if not read).
Definition IOList.C:87
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition IOList.C:212
virtual ~IOList()=default
Destructor.
IOList(const IOList &)=default
Default copy construct.
static List< T > readContents(const IOobject &io)
Read and return contents. The IOobject is never registered.
Definition IOList.C:177
TypeName("List")
Runtime type information.
static void writeContents(const IOobject &io, const UList< T > &content)
Write contents. The IOobject is never registered.
Definition IOList.C:194
IOList(const IOobject &io, List< T > &&content)
Construct by transferring the content.
Definition IOList.C:129
IOList(const IOobject &io, const UList< T > &content)
Construct from IOobject and a copy of content.
Definition IOList.C:114
IOList(const IOobject &io, const label len)
Construct from IOobject and list size (if not read).
Definition IOList.C:99
void operator=(const IOList< T > &rhs)
Copy assignment of entries.
Definition IOList.H:160
static label readContentsSize(const IOobject &io)
Read and return content size, -1 if not read.
Definition IOList.C:157
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
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 for handling words, derived from Foam::string.
Definition word.H:66
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.
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