Loading...
Searching...
No Matches
IOMap.C
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-2024 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
27\*---------------------------------------------------------------------------*/
28
29#include "IOMap.H"
30
31// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32
33template<class T>
34bool Foam::IOMap<T>::readIOcontents()
35{
36 if (isReadRequired() || (isReadOptional() && headerOk()))
37 {
38 // For if MUST_READ_IF_MODIFIED
39 addWatch();
40
41 readStream(typeName) >> *this;
42 close();
43
44 return true;
45 }
46
47 return false;
48}
49
50
51// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
52
53template<class T>
55:
57{
58 readIOcontents();
59}
60
61
62template<class T>
63Foam::IOMap<T>::IOMap(const IOobject& io, const label size)
64:
66{
67 if (!readIOcontents())
68 {
70 }
71}
72
73
74template<class T>
75Foam::IOMap<T>::IOMap(const IOobject& io, const Map<T>& content)
76:
77 regIOobject(io)
78{
79 if (!readIOcontents())
80 {
81 Map<T>::operator=(content);
82 }
83}
84
85
86template<class T>
87Foam::IOMap<T>::IOMap(const IOobject& io, Map<T>&& content)
88:
89 regIOobject(io)
90{
91 Map<T>::transfer(content);
92
93 readIOcontents();
94}
95
96
97// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
98
99template<class T>
101{
103 if (rio.readOpt() == IOobjectOption::READ_MODIFIED)
104 {
105 rio.readOpt(IOobjectOption::MUST_READ);
106 }
107 rio.resetHeader();
108
109 // The object is global
110 rio.globalObject(true);
111
112 IOMap<T> reader(rio);
113
114 return Map<T>(std::move(static_cast<Map<T>&>(reader)));
115}
116
117
118// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
119
120template<class T>
122{
123 os << *this;
124 return os.good();
125}
126
127
128// ************************************************************************* //
void transfer(HashTable< T, label, Hash > &rhs)
IOMap(const IOMap &)=default
Default copy construct.
bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition IOMap.C:114
static Map< T > readContents(const IOobject &io)
Read and return contents. The IOobject will not be registered.
Definition IOMap.C:93
@ NO_REGISTER
Do not request registration (bool: false).
bool globalObject() const noexcept
True if object is treated the same for all processors.
readOption readOpt() const noexcept
Get the read option.
@ MUST_READ
Reading required.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
void resetHeader(const word &newName=word::null)
Clear various bits (headerClassName, note, sizeof...) that would be obtained when reading from a file...
Definition IOobject.C:644
A HashTable to objects of type <T> with a label key.
Definition Map.H:54
constexpr Map() noexcept=default
Default construct: empty without allocation (capacity=0).
void operator=(const this_type &rhs)
Copy assignment.
Definition Map.H:152
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
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
OBJstream os(runTime.globalPath()/outputName)
const auto & io