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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-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 "IOList.H"
30 
31 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
32 
33 template<class T>
35 :
36  regIOobject(io)
37 {
38  // Check for MUST_READ_IF_MODIFIED
39  warnNoRereading<IOList<T>>();
40 
41  if
42  (
43  (
44  io.readOpt() == IOobject::MUST_READ
45  || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
46  )
47  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
48  )
49  {
50  readStream(typeName) >> *this;
51  close();
52  }
53 }
54 
55 
56 template<class T>
57 Foam::IOList<T>::IOList(const IOobject& io, const label len)
58 :
59  regIOobject(io)
60 {
61  // Check for MUST_READ_IF_MODIFIED
62  warnNoRereading<IOList<T>>();
63 
64  if
65  (
66  (
67  io.readOpt() == IOobject::MUST_READ
68  || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
69  )
70  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
71  )
72  {
73  readStream(typeName) >> *this;
74  close();
75  }
76  else
77  {
78  List<T>::setSize(len);
79  }
80 }
81 
82 
83 template<class T>
84 Foam::IOList<T>::IOList(const IOobject& io, const UList<T>& content)
85 :
86  regIOobject(io)
87 {
88  // Check for MUST_READ_IF_MODIFIED
89  warnNoRereading<IOList<T>>();
90 
91  if
92  (
93  (
94  io.readOpt() == IOobject::MUST_READ
95  || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
96  )
97  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
98  )
99  {
100  readStream(typeName) >> *this;
101  close();
102  }
103  else
104  {
105  List<T>::operator=(content);
106  }
107 }
108 
109 
110 template<class T>
112 :
113  regIOobject(io)
114 {
115  // Check for MUST_READ_IF_MODIFIED
116  warnNoRereading<IOList<T>>();
117 
118  List<T>::transfer(content);
119 
120  if
121  (
122  (
123  io.readOpt() == IOobject::MUST_READ
124  || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
125  )
126  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
127  )
128  {
129  readStream(typeName) >> *this;
130  close();
131  }
132 }
133 
134 
135 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
136 
137 template<class T>
139 {
140  return (os << *this).good();
141 }
142 
143 
144 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
145 
146 template<class T>
148 {
149  List<T>::operator=(rhs);
150 }
151 
152 
153 // ************************************************************************* //
setSize
points setSize(newPointi)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::IOList::IOList
IOList(const IOList &)=default
Default copy construct.
IOList.H
Foam::IOList::operator=
void operator=(const IOList< T > &rhs)
Copy assignment of entries.
Definition: IOList.C:147
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::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::IOList
A List of objects of type <T> with automated input and output.
Definition: IOList.H:53
Foam::IOList::writeData
bool writeData(Ostream &os) const
Pure virtual writeData function.
Definition: IOList.C:138
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56