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-2022 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#include "refPtr.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50/*---------------------------------------------------------------------------*\
51 Class IOList Declaration
52\*---------------------------------------------------------------------------*/
53
54template<class T>
55class IOList
56:
57 public regIOobject,
58 public List<T>
59{
60 // Private Member Functions
61
62 //- Read if IOobject flags set. Return true if read.
63 bool readContents();
64
65public:
66
67 //- The underlying content type
68 typedef List<T> content_type;
69
70 //- Runtime type information
71 TypeName("List");
72
73
74 // Constructors
75
76 //- Default copy construct
77 IOList(const IOList&) = default;
78
79 //- Construct from IOobject
80 explicit IOList(const IOobject& io);
81
82 //- Construct from IOobject and zero size (if not read)
84
85 //- Construct from IOobject and list size (if not read)
86 IOList(const IOobject& io, const label len);
87
88 //- Construct from IOobject and a copy of content
89 IOList(const IOobject& io, const UList<T>& content);
90
91 //- Construct by transferring the content
92 IOList(const IOobject& io, List<T>&& content);
93
94
95 //- Destructor
96 virtual ~IOList() = default;
97
98
99 // Member Functions
100
101 //- The writeData method for regIOobject write operation
102 virtual bool writeData(Ostream& os) const;
103
104
105 // Member Operators
106
107 //- Copy assignment of entries
108 void operator=(const IOList<T>& rhs);
109
110 //- Copy or move assignment of entries
111 using List<T>::operator=;
112};
113
114
115/*---------------------------------------------------------------------------*\
116 Class IOListRef Declaration
117\*---------------------------------------------------------------------------*/
118
119//- A IOList wrapper for writing external data.
120template<class T>
121class IOListRef
122:
123 public regIOobject
124{
125 // Private Data
126
127 //- Reference to the external content
128 refPtr<List<T>> contentRef_;
129
130
131public:
132
133 //- The underlying content type
134 typedef List<T> content_type;
135
136
137 //- Type is identical to IOList
138 virtual const word& type() const
139 {
140 return IOList<T>::typeName;
141 }
142
143
144 // Generated Methods
145
146 //- No default construct
147 IOListRef() = delete;
148
149 //- No copy construct
150 IOListRef(const IOListRef&) = delete;
151
152 //- No copy assignment
153 void operator=(const IOListRef&) = delete;
154
155
156 // Constructors
157
158 //- Construct from IOobject and const data reference
159 IOListRef(const IOobject& io, const List<T>& content);
160
161
162 //- Destructor
163 virtual ~IOListRef() = default;
164
165
166 // Member Functions
167
168 //- Allow cast to const content
169 // Fatal if content is not set
170 operator const List<T>&() const
171 {
172 return contentRef_.cref();
173 }
174
175 //- The writeData method for regIOobject write operation
176 // Fatal if content is not set
177 virtual bool writeData(Ostream& os) const;
178};
179
180
181// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182
183} // End namespace Foam
184
185// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186
187#ifdef NoRepository
188 #include "IOList.C"
189#endif
190
191// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192
193#endif
194
195// ************************************************************************* //
A IOList wrapper for writing external data.
Definition: IOList.H:123
List< T > content_type
The underlying content type.
Definition: IOList.H:133
IOListRef()=delete
No default construct.
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOList.C:147
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:137
IOListRef(const IOListRef &)=delete
No copy construct.
A List of objects of type <T> with automated input and output.
Definition: IOList.H:58
List< T > content_type
The underlying content type.
Definition: IOList.H:67
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOList.C:139
virtual ~IOList()=default
Destructor.
IOList(const IOList &)=default
Default copy construct.
TypeName("List")
Runtime type information.
void operator=(const IOList< T > &rhs)
Copy assignment of entries.
Definition: IOList.C:157
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
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:94
A class for managing references or pointers (no reference counting)
Definition: refPtr.H:58
const T & cref() const
Definition: refPtrI.H:189
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A class for handling words, derived from Foam::string.
Definition: word.H:68
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73