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 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 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
32 
33 template<class T>
35 :
36  regIOobject(io)
37 {
38  if
39  (
40  (
43  )
45  )
46  {
47  // For if MUST_READ_IF_MODIFIED
48  addWatch();
49 
50  readStream(typeName) >> *this;
51  close();
52  }
53 }
54 
55 template<class T>
56 Foam::IOMap<T>::IOMap(const IOobject& io, const label size)
57 :
58  regIOobject(io)
59 {
60  if
61  (
62  (
65  )
67  )
68  {
69  // For if MUST_READ_IF_MODIFIED
70  addWatch();
71 
72  readStream(typeName) >> *this;
73  close();
74  }
75  else
76  {
77  Map<T>::setSize(size);
78  }
79 }
80 
81 
82 template<class T>
83 Foam::IOMap<T>::IOMap(const IOobject& io, const Map<T>& content)
84 :
85  regIOobject(io)
86 {
87  if
88  (
89  (
92  )
94  )
95  {
96  // For if MUST_READ_IF_MODIFIED
97  addWatch();
98 
99  readStream(typeName) >> *this;
100  close();
101  }
102  else
103  {
104  Map<T>::operator=(content);
105  }
106 }
107 
108 
109 template<class T>
110 Foam::IOMap<T>::IOMap(const IOobject& io, Map<T>&& content)
111 :
112  regIOobject(io)
113 {
114  Map<T>::transfer(content);
115 
116  if
117  (
118  (
121  )
122  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
123  )
124  {
125  // For if MUST_READ_IF_MODIFIED
126  addWatch();
127 
128  readStream(typeName) >> *this;
129  close();
130  }
131 }
132 
133 
134 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135 
136 template<class T>
138 {
139  return (os << *this).good();
140 }
141 
142 
143 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
144 
145 template<class T>
147 {
148  Map<T>::operator=(rhs);
149 }
150 
151 
152 // ************************************************************************* //
setSize
points setSize(newPointi)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::IOMap::operator=
void operator=(const IOMap< T > &rhs)
Copy assignment of entries.
Definition: IOMap.C:146
Foam::regIOobject::addWatch
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:267
Foam::Map::operator=
void operator=(const this_type &rhs)
Copy assignment.
Definition: Map.H:117
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
Foam::IOMap::IOMap
IOMap(const IOMap &)=default
Default copy construct.
Foam::IOMap::writeData
bool writeData(Ostream &os) const
Pure virtual writeData function.
Definition: IOMap.C:137
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:187
IOMap.H
os
OBJstream os(runTime.globalPath()/outputName)
Foam::IOobject::readOpt
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
Foam::regIOobject::close
void close()
Close Istream.
Definition: regIOobjectRead.C:171
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::regIOobject::readStream
Istream & readStream(const word &, const bool valid=true)
Return Istream and check object type against that given.
Definition: regIOobjectRead.C:129
Foam::regIOobject::headerOk
bool headerOk()
Read and check header info.
Definition: regIOobject.C:436
Foam::IOobject::MUST_READ
Definition: IOobject.H:185
Foam::IOMap
A Map of objects of type <T> with automated input and output. Is a global object; i....
Definition: IOMap.H:54