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-2023 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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 template<class T>
35 {
36  if (isReadRequired() || (isReadOptional() && headerOk()))
37  {
38  readStream(typeName) >> *this;
39  close();
40  return true;
41  }
42 
43  return false;
44 }
45 
46 
47 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
48 
49 template<class T>
51 :
53 {
54  // Check for MUST_READ_IF_MODIFIED
55  warnNoRereading<IOList<T>>();
56 
57  readContents();
58 }
59 
60 
61 template<class T>
63 :
65 {
66  // Check for MUST_READ_IF_MODIFIED
67  warnNoRereading<IOList<T>>();
68 
69  readContents();
70 }
71 
72 
73 template<class T>
74 Foam::IOList<T>::IOList(const IOobject& io, const label len)
75 :
77 {
78  // Check for MUST_READ_IF_MODIFIED
79  warnNoRereading<IOList<T>>();
80 
81  if (!readContents())
82  {
83  List<T>::resize(len);
84  }
85 }
86 
87 
88 template<class T>
89 Foam::IOList<T>::IOList(const IOobject& io, const UList<T>& content)
90 :
91  regIOobject(io)
92 {
93  // Check for MUST_READ_IF_MODIFIED
94  warnNoRereading<IOList<T>>();
95 
96  if (!readContents())
97  {
98  List<T>::operator=(content);
99  }
100 }
101 
102 
103 template<class T>
104 Foam::IOList<T>::IOList(const IOobject& io, List<T>&& content)
105 :
106  regIOobject(io)
107 {
108  // Check for MUST_READ_IF_MODIFIED
109  warnNoRereading<IOList<T>>();
110 
111  List<T>::transfer(content);
113  readContents();
114 }
115 
116 
117 template<class T>
119 (
120  const IOobject& io,
121  const List<T>& content
122 )
123 :
124  regIOobject(io),
125  contentRef_(content)
126 {}
127 
128 
129 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
130 
131 template<class T>
133 {
134  IOobject rio(io, IOobjectOption::NO_REGISTER);
135  if (rio.readOpt() == IOobjectOption::MUST_READ_IF_MODIFIED)
136  {
137  rio.readOpt(IOobjectOption::MUST_READ);
138  }
139 
140  IOList<T> reader(rio);
141 
142  return List<T>(std::move(static_cast<List<T>&>(reader)));
143 }
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
148 template<class T>
150 {
151  os << static_cast<const List<T>&>(*this);
152  return os.good();
153 }
154 
155 
156 template<class T>
158 {
159  os << contentRef_.cref();
160  return os.good();
161 }
162 
163 
164 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
165 
166 template<class T>
167 void Foam::IOList<T>::operator=(const IOList<T>& rhs)
168 {
169  List<T>::operator=(rhs);
170 }
171 
172 
173 // ************************************************************************* //
patchWriters resize(patchIds.size())
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOList.C:150
A List of objects of type <T> with automated input and output.
Definition: IOList.H:49
IOListRef()=delete
No default construct.
void operator=(const IOList< T > &rhs)
Copy assignment of entries.
Definition: IOList.C:160
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: IOList.C:142
IOList(const IOList &)=default
Default copy construct.
OBJstream os(runTime.globalPath()/outputName)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172