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 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  readStream(typeName) >> *this;
45  close();
46  }
47 }
48 
49 template<class T>
51 :
52  regIOobject(io)
53 {
54  if
55  (
56  (
59  )
61  )
62  {
63  readStream(typeName) >> *this;
64  close();
65  }
66  else
67  {
68  Map<T>::setSize(size);
69  }
70 }
71 
72 
73 template<class T>
74 Foam::IOMap<T>::IOMap(const IOobject& io, const Map<T>& map)
75 :
76  regIOobject(io)
77 {
78  if
79  (
80  (
83  )
85  )
86  {
87  readStream(typeName) >> *this;
88  close();
89  }
90  else
91  {
92  Map<T>::operator=(map);
93  }
94 }
95 
96 
97 template<class T>
98 Foam::IOMap<T>::IOMap(const IOobject& io, const Xfer<Map<T> >& map)
99 :
100  regIOobject(io)
101 {
102  Map<T>::transfer(map());
103 
104  if
105  (
106  (
109  )
110  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
111  )
112  {
113  readStream(typeName) >> *this;
114  close();
115  }
116 }
117 
118 
119 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
120 
121 template<class T>
123 {}
124 
125 
126 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
127 
128 template<class T>
130 {
131  return (os << *this).good();
132 }
133 
134 
135 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
136 
137 template<class T>
139 {
140  Map<T>::operator=(rhs);
141 }
142 
143 
144 template<class T>
146 {
147  Map<T>::operator=(rhs);
148 }
149 
150 
151 // ************************************************************************* //
readOption readOpt() const
Definition: IOobject.H:304
IOMap(const IOobject &)
Construct from IOobject.
Definition: IOMap.C:31
bool writeData(Ostream &) const
Pure virtual writaData function.
Definition: IOMap.C:129
void operator=(const HashTable< T, label, Hash< label > > &)
Assignment.
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
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
A Map of objects of type <T> with automated input and output.
Definition: IOMap.H:50
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
void operator=(const IOMap< T > &)
Assignment of other IOMap&#39;s entries to this IOMap.
Definition: IOMap.C:138
void close()
Close Istream.
label size() const
Return number of elements in table.
points setSize(newPointi)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void transfer(HashTable< T, label, Hash< label > > &)
Transfer the contents of the argument table into this table.
bool headerOk()
Read and check header info.
Definition: IOobject.C:424
Istream & readStream(const word &)
Return Istream and check object type against that given.
virtual ~IOMap()
Destructor.
Definition: IOMap.C:122