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>
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>
55 :
57 {
58  readContents();
59 }
60 
61 
62 template<class T>
63 Foam::IOMap<T>::IOMap(const IOobject& io, const label size)
64 :
66 {
67  if (!readContents())
68  {
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>
101 {
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>
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 // ************************************************************************* //
void operator=(const IOMap< T > &rhs)
Copy assignment of entries.
Definition: IOMap.C:120
bool writeData(Ostream &os) const
Pure virtual writeData function.
Definition: IOMap.C:110
A Map of objects of type <T> with automated input and output. Is a global object; i...
Definition: IOMap.H:50
label size() const noexcept
The number of elements in table.
Definition: HashTable.H:342
IOMap(const IOMap &)=default
Default copy construct.
void resize(label newCapacity)
Rehash the hash table with new number of buckets. Currently identical to setCapacity() ...
Definition: HashTable.C:705
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:281
void transfer(HashTable< T, label, Hash< label > > &rhs)
Transfer contents into this table.
Definition: HashTable.C:777
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
void operator=(const this_type &rhs)
Copy assignment.
Definition: Map.H:134
Do not request registration (bool: false)
A HashTable to objects of type <T> with a label key.