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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::IOField
29 
30 Description
31  A primitive field of type <T> with automated input and output.
32 
33 SourceFiles
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 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class IOField Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 template<class Type>
55 class 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 
65 public:
66 
67  //- The underlying content type
68  typedef Field<Type> 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)
86  IOField(const IOobject& io, Foam::zero);
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.
126 template<class Type>
127 class IOFieldRef
128 :
129  public regIOobject
130 {
131  // Private Data
132 
133  //- Reference to the external content
134  refPtr<Field<Type>> contentRef_;
135 
136 
137 public:
138 
139  //- The underlying content type
140  typedef Field<Type> 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;
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 
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 // ************************************************************************* //
IOFieldRef()=delete
No default construct.
IOField(const IOField &)=default
Default copy construct.
A IOField wrapper for writing external data.
Definition: IOField.H:154
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
Definition: refPtrI.H:194
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOField.C:179
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
virtual ~IOFieldRef()=default
Destructor.
Generic templated field type.
Definition: Field.H:61
A class for handling words, derived from Foam::string.
Definition: word.H:63
TypeName("Field")
Runtime type information.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
virtual ~IOField()=default
Destructor.
void operator=(const IOField< Type > &rhs)
Copy assignment of entries.
Definition: IOField.C:197
Field< Type > content_type
The underlying content type.
Definition: IOField.H:67
OBJstream os(runTime.globalPath()/outputName)
Field< Type > content_type
The underlying content type.
Definition: IOField.H:171
virtual const word & type() const
Type is identical to IOField.
Definition: IOField.H:177
void operator=(const IOFieldRef &)=delete
No copy assignment.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:69
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:58
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOField.C:187
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
A primitive field of type <T> with automated input and output.
Namespace for OpenFOAM.