OpenFOAM
v2312
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-2023 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>::readContents
()
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
readContents();
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
(!readContents())
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
(!readContents())
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
readContents();
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::MUST_READ_IF_MODIFIED
)
104
{
105
rio.readOpt(
IOobjectOption::MUST_READ
);
106
}
107
108
IOMap<T> reader(rio);
109
110
return
Map<T>
(std::move(
static_cast<
Map<T>
&
>
(reader)));
111
}
112
113
114
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115
116
template
<
class
T>
117
bool
Foam::IOMap<T>::writeData
(
Ostream
&
os
)
const
118
{
119
os
<< *
this
;
120
return
os
.
good
();
121
}
122
123
124
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
125
126
template
<
class
T>
127
void
Foam::IOMap<T>::operator=
(
const
IOMap<T>
& rhs)
128
{
129
Map<T>::operator=
(rhs);
130
}
131
132
133
// ************************************************************************* //
Foam::IOMap::operator=
void operator=(const IOMap< T > &rhs)
Copy assignment of entries.
Definition:
IOMap.C:120
Foam::IOMap::writeData
bool writeData(Ostream &os) const
Pure virtual writeData function.
Definition:
IOMap.C:110
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:342
IOMap.H
Foam::IOobjectOption::MUST_READ_IF_MODIFIED
Definition:
IOobjectOption.H:71
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:705
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:777
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition:
regIOobject.H:66
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:172
Foam::Map::operator=
void operator=(const this_type &rhs)
Copy assignment.
Definition:
Map.H:134
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