IOField.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-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::IOField
29
30Description
31 A primitive field of type <T> with automated input and output.
32
33SourceFiles
34 IOField.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_IOField_H
39#define Foam_IOField_H
40
41#include "Field.H"
42#include "regIOobject.H"
43#include "refPtr.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50/*---------------------------------------------------------------------------*\
51 Class IOField Declaration
52\*---------------------------------------------------------------------------*/
53
54template<class Type>
55class IOField
56:
57 public regIOobject,
58 public Field<Type>
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
69
70 //- Runtime type information
71 TypeName("Field");
72
73
74 // Constructors
75
76 //- Default copy construct
77 IOField(const IOField&) = default;
78
79 //- Construct from IOobject
80 explicit IOField(const IOobject& io);
81
82 //- Construct from IOobject, with local processor conditional reading
83 IOField(const IOobject& io, const bool valid);
84
85 //- Construct from IOobject and zero size (if not read)
87
88 //- Construct from IOobject and field size (if not read)
89 IOField(const IOobject& io, const label len);
90
91 //- Construct from IOobject and copy of List/Field content
92 IOField(const IOobject& io, const UList<Type>& content);
93
94 //- Construct by transferring the Field content
95 IOField(const IOobject& io, Field<Type>&& content);
96
97 //- Construct by copying/moving tmp content
98 IOField(const IOobject& io, const tmp<Field<Type>>& tfld);
99
100
101 //- Destructor
102 virtual ~IOField() = default;
103
104
105 // Member Functions
106
107 //- The writeData method for regIOobject write operation
108 virtual bool writeData(Ostream& os) const;
109
110
111 // Member Operators
112
113 //- Copy assignment of entries
114 void operator=(const IOField<Type>& rhs);
115
116 //- Copy or move assignment of entries
117 using Field<Type>::operator=;
118};
119
120
121/*---------------------------------------------------------------------------*\
122 Class IOFieldRef Declaration
123\*---------------------------------------------------------------------------*/
124
125//- A IOField wrapper for writing external data.
126template<class Type>
127class IOFieldRef
128:
129 public regIOobject
130{
131 // Private Data
132
133 //- Reference to the external content
134 refPtr<Field<Type>> contentRef_;
135
136
137public:
138
139 //- The underlying content type
141
142
143 //- Type is identical to IOField
144 virtual const word& type() const
145 {
147 }
148
149
150 // Generated Methods
151
152 //- No default construct
153 IOFieldRef() = delete;
154
155 //- No copy construct
156 IOFieldRef(const IOFieldRef&) = delete;
157
158 //- No copy assignment
159 void operator=(const IOFieldRef&) = delete;
160
161
162 // Constructors
163
164 //- Construct from IOobject and const data reference
165 IOFieldRef(const IOobject& io, const Field<Type>& content);
166
167
168 //- Destructor
169 virtual ~IOFieldRef() = default;
170
171
172 // Member Functions
173
174 //- Allow cast to const content
175 // Fatal if content is not set
176 operator const Field<Type>&() const
177 {
178 return contentRef_.cref();
179 }
180
181 //- The writeData method for regIOobject write operation
182 // Fatal if content is not set
183 virtual bool writeData(Ostream& os) const;
184};
185
186
187// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188
189} // End namespace Foam
190
191// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192
193#ifdef NoRepository
194 #include "IOField.C"
195#endif
196
197// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198
199#endif
200
201// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
friend Ostream & operator(Ostream &, const Field< Type > &)
A IOField wrapper for writing external data.
Definition: IOField.H:129
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOField.C:205
virtual ~IOFieldRef()=default
Destructor.
virtual const word & type() const
Type is identical to IOField.
Definition: IOField.H:143
void operator=(const IOFieldRef &)=delete
No copy assignment.
IOFieldRef(const IOFieldRef &)=delete
No copy construct.
IOFieldRef()=delete
No default construct.
Field< Type > content_type
The underlying content type.
Definition: IOField.H:139
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
virtual ~IOField()=default
Destructor.
IOField(const IOField &)=default
Default copy construct.
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOField.C:197
TypeName("Field")
Runtime type information.
void operator=(const IOField< Type > &rhs)
Copy assignment of entries.
Definition: IOField.C:215
Field< Type > content_type
The underlying content type.
Definition: IOField.H:67
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
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 managing temporary objects.
Definition: tmp.H:65
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
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