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-2025 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 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class IOField Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 template<class Type>
54 class IOField
55 :
56  public regIOobject,
57  public Field<Type>
58 {
59  // Private Member Functions
60 
61  //- Read if IOobject flags set and 'on-proc' is true.
62  // Return true if read (only accurate when readOnProc == true).
63  bool readIOcontents(bool readOnProc = true);
64 
65  //- Read the content size.
66  // Return the size if read, -1 otherwise
67  label readIOsize();
68 
69 public:
70 
71  //- The underlying content type
72  typedef Field<Type> content_type;
73 
74  //- Runtime type information
75  TypeName("Field");
76 
77 
78  // Constructors
79 
80  //- Default copy construct
81  IOField(const IOField&) = default;
82 
83  //- Construct from IOobject. Will be zero size if not read.
84  explicit IOField(const IOobject& io);
85 
86  //- Construct from IOobject, with local processor conditional reading
87  IOField(const IOobject& io, const bool readOnProc);
88 
89  //- Construct from IOobject and zero size (if not read)
90  IOField(const IOobject& io, Foam::zero);
91 
92  //- Construct from IOobject and field size (if not read)
93  IOField(const IOobject& io, const label len);
94 
95  //- Construct from IOobject and copy of List/Field content
96  IOField(const IOobject& io, const UList<Type>& content);
97 
98  //- Construct by transferring the Field content
99  IOField(const IOobject& io, Field<Type>&& content);
100 
101  //- Construct by copying/moving tmp content
102  IOField(const IOobject& io, const tmp<Field<Type>>& tfld);
103 
104 
105  // Factory Methods
106 
107  //- Read and return content size, -1 if not read.
108  // The IOobject will not be registered
109  static label readContentsSize(const IOobject& io);
110 
111  //- Read and return contents. The IOobject will not be registered
112  static Field<Type> readContents(const IOobject& io);
113 
114 
115  //- Destructor
116  virtual ~IOField() = default;
117 
118 
119  // Member Functions
120 
121  //- The writeData method for regIOobject write operation
122  virtual bool writeData(Ostream& os) const;
123 
124 
125  // Member Operators
126 
127  //- Copy or move assignment of entries
128  using Field<Type>::operator=;
129 
130  //- Copy assignment of entries
131  void operator=(const IOField<Type>& rhs)
132  {
134  }
135 
136  //- Move assignment of entries
137  void operator=(IOField<Type>&& rhs)
138  {
139  Field<Type>::operator=(std::move(static_cast<Field<Type>&>(rhs)));
140  }
141 };
142 
143 
144 /*---------------------------------------------------------------------------*\
145  Class IOFieldRef Declaration
146 \*---------------------------------------------------------------------------*/
147 
148 //- A IOField wrapper for writing external data.
149 template<class Type>
150 class IOFieldRef
151 :
152  public regIOobject
153 {
154  // Private Data
155 
156  //- Reference to the external content
157  refPtr<Field<Type>> contentRef_;
158 
159 
160 public:
161 
162  //- The underlying content type
163  typedef Field<Type> content_type;
164 
166  //- Type is identical to IOField
167  virtual const word& type() const
168  {
170  }
171 
172 
173  // Generated Methods
174 
175  //- No default construct
176  IOFieldRef() = delete;
177 
178  //- No copy construct
179  IOFieldRef(const IOFieldRef&) = delete;
180 
181  //- No copy assignment
182  void operator=(const IOFieldRef&) = delete;
183 
184 
185  // Constructors
186 
187  //- Construct from IOobject and const data reference
188  IOFieldRef(const IOobject& io, const Field<Type>& content);
189 
190 
191  //- Destructor
192  virtual ~IOFieldRef() = default;
193 
194 
195  // Member Functions
196 
197  //- Allow cast to const content
198  // Fatal if content is not set
199  operator const Field<Type>&() const
200  {
201  return contentRef_.cref();
202  }
203 
204  //- The writeData method for regIOobject write operation
205  // Fatal if content is not set
206  virtual bool writeData(Ostream& os) const;
207 };
208 
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 } // End namespace Foam
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 #ifdef NoRepository
217  #include "IOField.C"
218 #endif
219 
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 
222 #endif
223 
224 // ************************************************************************* //
IOFieldRef()=delete
No default construct.
IOField(const IOField &)=default
Default copy construct.
A IOField wrapper for writing external data.
Definition: IOField.H:188
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOField.C:234
static label readContentsSize(const IOobject &io)
Read and return content size, -1 if not read.
Definition: IOField.C:196
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
virtual ~IOFieldRef()=default
Destructor.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition: Field.H:69
A class for handling words, derived from Foam::string.
Definition: word.H:63
TypeName("Field")
Runtime type information.
const auto & io
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual ~IOField()=default
Destructor.
void operator=(const IOField< Type > &rhs)
Copy assignment of entries.
Definition: IOField.H:165
Field< Type > content_type
The underlying content type.
Definition: IOField.H:75
void operator=(const Field< Type > &)
Copy assignment.
Definition: Field.C:781
Field< Type > content_type
The underlying content type.
Definition: IOField.H:205
virtual const word & type() const
Type is identical to IOField.
Definition: IOField.H:211
void operator=(const IOFieldRef &)=delete
No copy assignment.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOField.C:242
static Field< Type > readContents(const IOobject &io)
Read and return contents. The IOobject will not be registered.
Definition: IOField.C:216
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:188
A primitive field of type <T> with automated input and output.
Namespace for OpenFOAM.