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 | Copyright (C) 2011-2017 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "IOMap.H"
27 
28 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
29 
30 template<class T>
32 :
33  regIOobject(io)
34 {
35  if
36  (
37  (
40  )
42  )
43  {
44  // For if MUST_READ_IF_MODIFIED
45  addWatch();
46 
47  readStream(typeName) >> *this;
48  close();
49  }
50 }
51 
52 template<class T>
54 :
55  regIOobject(io)
56 {
57  if
58  (
59  (
62  )
64  )
65  {
66  // For if MUST_READ_IF_MODIFIED
67  addWatch();
68 
69  readStream(typeName) >> *this;
70  close();
71  }
72  else
73  {
74  Map<T>::setSize(size);
75  }
76 }
77 
78 
79 template<class T>
80 Foam::IOMap<T>::IOMap(const IOobject& io, const Map<T>& map)
81 :
82  regIOobject(io)
83 {
84  if
85  (
86  (
89  )
91  )
92  {
93  // For if MUST_READ_IF_MODIFIED
94  addWatch();
95 
96  readStream(typeName) >> *this;
97  close();
98  }
99  else
100  {
101  Map<T>::operator=(map);
102  }
103 }
104 
105 
106 template<class T>
107 Foam::IOMap<T>::IOMap(const IOobject& io, const Xfer<Map<T>>& map)
108 :
109  regIOobject(io)
110 {
111  Map<T>::transfer(map());
112 
113  if
114  (
115  (
118  )
119  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
120  )
121  {
122  // For if MUST_READ_IF_MODIFIED
123  addWatch();
124 
125  readStream(typeName) >> *this;
126  close();
127  }
128 }
129 
130 
131 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
132 
133 template<class T>
135 {}
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
140 template<class T>
142 {
143  return (os << *this).good();
144 }
145 
146 
147 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
148 
149 template<class T>
151 {
152  Map<T>::operator=(rhs);
153 }
154 
155 
156 template<class T>
158 {
159  Map<T>::operator=(rhs);
160 }
161 
162 
163 // ************************************************************************* //
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
IOMap(const IOobject &)
Construct from IOobject.
Definition: IOMap.C:31
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void operator=(const HashTable< T, label, Hash< label > > &)
Assignment.
Definition: HashTable.C:537
bool headerOk()
Read and check header info.
Definition: regIOobject.C:423
A Map of objects of type <T> with automated input and output. Is a global object; i...
Definition: IOMap.H:51
void transfer(HashTable< T, label, Hash< label > > &)
Transfer the contents of the argument table into this table.
Definition: HashTable.C:513
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
points setSize(newPointi)
Istream & readStream(const word &, const bool valid=true)
Return Istream and check object type against that given.
void close()
Close Istream.
bool writeData(Ostream &) const
Pure virtual writaData function.
Definition: IOMap.C:141
virtual ~IOMap()
Destructor.
Definition: IOMap.C:134
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:244
void operator=(const IOMap< T > &)
Assignment of other IOMap&#39;s entries to this IOMap.
Definition: IOMap.C:150
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:65
readOption readOpt() const
Definition: IOobject.H:353
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49