OpenFOAM
v2406
The open source CFD toolbox
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
-------------------------------------------------------------------------------
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
\*---------------------------------------------------------------------------*/
28
29
#include "
IOMap.H
"
30
31
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32
33
template
<
class
T>
34
bool
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
53
template
<
class
T>
54
Foam::IOMap<T>::IOMap
(
const
IOobject
&
io
)
55
:
56
regIOobject
(
io
)
57
{
58
readIOcontents();
59
}
60
61
62
template
<
class
T>
63
Foam::IOMap<T>::IOMap
(
const
IOobject
&
io
,
const
label size)
64
:
65
regIOobject
(
io
)
66
{
67
if
(!readIOcontents())
68
{
69
Map<T>::resize
(
size
);
70
}
71
}
72
73
74
template
<
class
T>
75
Foam::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
86
template
<
class
T>
87
Foam::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
99
template
<
class
T>
100
Foam::Map<T>
Foam::IOMap<T>::readContents
(
const
IOobject
&
io
)
101
{
102
IOobject
rio(
io
,
IOobjectOption::NO_REGISTER
);
103
if
(rio.readOpt() ==
IOobjectOption::READ_MODIFIED
)
104
{
105
rio.readOpt(
IOobjectOption::MUST_READ
);
106
}
107
108
// The object is global
109
rio.globalObject(
true
);
110
111
IOMap<T> reader(rio);
112
113
return
Map<T>
(std::move(
static_cast<
Map<T>
&
>
(reader)));
114
}
115
116
117
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118
119
template
<
class
T>
120
bool
Foam::IOMap<T>::writeData
(
Ostream
&
os
)
const
121
{
122
os
<< *
this
;
123
return
os
.
good
();
124
}
125
126
127
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
128
129
template
<
class
T>
130
void
Foam::IOMap<T>::operator=
(
const
IOMap<T>
& rhs)
131
{
132
Map<T>::operator=
(rhs);
133
}
134
135
136
// ************************************************************************* //
Foam::IOMap::operator=
void operator=(const IOMap< T > &rhs)
Copy assignment of entries.
Definition:
IOMap.C:123
Foam::IOobjectOption::READ_MODIFIED
Definition:
IOobjectOption.H:67
Foam::IOMap::readContents
static Map< T > readContents(const IOobject &io)
Read and return contents. The IOobject will not be registered.
Definition:
IOMap.C:93
Foam::IOMap::writeData
bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition:
IOMap.C:113
Foam::IOMap
A Map of objects of type <T> with automated input and output. Is a global object; i...
Definition:
IOMap.H:50
Foam::HashTable< T, label, Hash< label > >::size
label size() const noexcept
The number of elements in table.
Definition:
HashTable.H:358
IOMap.H
Foam::IOMap::IOMap
IOMap(const IOMap &)=default
Default copy construct.
Foam::IOobjectOption::MUST_READ
Reading required.
Definition:
IOobjectOption.H:63
Foam::HashTable< T, label, Hash< label > >::resize
void resize(label newCapacity)
Rehash the hash table with new number of buckets. Currently identical to setCapacity() ...
Definition:
HashTable.C:729
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition:
Ostream.H:56
os
OBJstream os(runTime.globalPath()/outputName)
Foam::IOstream::good
bool good() const noexcept
True if next operation might succeed.
Definition:
IOstream.H:281
Foam::HashTable< T, label, Hash< label > >::transfer
void transfer(HashTable< T, label, Hash< label > > &rhs)
Transfer contents into this table.
Definition:
HashTable.C:801
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition:
regIOobject.H:68
io
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition:
IOobject.H:180
Foam::Map::operator=
void operator=(const this_type &rhs)
Copy assignment.
Definition:
Map.H:155
Foam::IOobjectOption::NO_REGISTER
Do not request registration (bool: false)
Definition:
IOobjectOption.H:99
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition:
lumpedPointController.H:65
src
OpenFOAM
db
IOobjects
IOMap
IOMap.C
Generated by
1.8.14