IOList.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-2016 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 "IOList.H"
27 
28 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
29 
30 template<class T>
32 :
33  regIOobject(io)
34 {
35  // Temporary warning
37  {
39  << "IOList " << name()
40  << " constructed with IOobject::MUST_READ_IF_MODIFIED"
41  " but IOList does not support automatic rereading."
42  << endl;
43  }
44  if
45  (
46  (
49  )
51  )
52  {
53  readStream(typeName) >> *this;
54  close();
55  }
56 }
57 
58 
59 template<class T>
61 :
62  regIOobject(io)
63 {
64  // Temporary warning
66  {
68  << "IOList " << name()
69  << " constructed with IOobject::MUST_READ_IF_MODIFIED"
70  " but IOList does not support automatic rereading."
71  << endl;
72  }
73  if
74  (
75  (
78  )
80  )
81  {
82  readStream(typeName) >> *this;
83  close();
84  }
85  else
86  {
87  List<T>::setSize(size);
88  }
89 }
90 
91 
92 template<class T>
93 Foam::IOList<T>::IOList(const IOobject& io, const List<T>& list)
94 :
95  regIOobject(io)
96 {
97  // Temporary warning
99  {
101  << "IOList " << name()
102  << " constructed with IOobject::MUST_READ_IF_MODIFIED"
103  " but IOList does not support automatic rereading."
104  << endl;
105  }
106 
107  if
108  (
109  (
112  )
113  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
114  )
115  {
116  readStream(typeName) >> *this;
117  close();
118  }
119  else
120  {
121  List<T>::operator=(list);
122  }
123 }
124 
125 
126 template<class T>
128 :
129  regIOobject(io)
130 {
131  // Temporary warning
133  {
135  << "IOList " << name()
136  << " constructed with IOobject::MUST_READ_IF_MODIFIED"
137  " but IOList does not support automatic rereading."
138  << endl;
139  }
140 
141  List<T>::transfer(list());
142 
143  if
144  (
145  (
148  )
149  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
150  )
151  {
152  readStream(typeName) >> *this;
153  close();
154  }
155 }
156 
157 
158 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
159 
160 template<class T>
162 {}
163 
164 
165 
166 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
167 
168 template<class T>
170 {
171  return (os << *this).good();
172 }
173 
174 
175 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
176 
177 template<class T>
179 {
180  List<T>::operator=(rhs);
181 }
182 
183 
184 template<class T>
186 {
187  List<T>::operator=(rhs);
188 }
189 
190 
191 // ************************************************************************* //
virtual ~IOList()
Destructor.
Definition: IOList.C:161
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 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
A List of objects of type <T> with automated input and output.
Definition: IOList.H:50
void operator=(const IOList< T > &)
Definition: IOList.C:178
bool writeData(Ostream &) const
Pure virtual writaData function.
Definition: IOList.C:169
const word typeName("scalarVectorTable")
Istream & readStream(const word &)
Return Istream and check object type against that given.
void close()
Close Istream.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
label size() const
Return the number of elements in the UList.
Definition: ListI.H:83
void operator=(const UList< T > &)
Assignment from UList operator. Takes linear time.
Definition: List.C:399
void setSize(const label)
Reset size of List.
Definition: List.C:295
IOList(const IOobject &)
Construct from IOobject.
Definition: IOList.C:31
#define WarningInFunction
Report a warning using Foam::Warning.
readOption readOpt() const
Definition: IOobject.H:304
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
bool headerOk()
Read and check header info.
Definition: IOobject.C:400
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:365
const word & name() const
Return name.
Definition: IOobject.H:260