Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
33template<class T>
34bool Foam::IOList<T>::readIOcontents()
35{
36 if (isReadRequired() || (isReadOptional() && headerOk()))
37 {
38 readStream(typeName) >> *this;
39 close();
40 return true;
41 }
42
43 return false;
44}
45
46
47template<class T>
48Foam::label Foam::IOList<T>::readIOsize()
49{
50 label count(-1);
51
52 if (isReadRequired() || (isReadOptional() && headerOk()))
53 {
54 Istream& is = readStream(typeName);
55
56 token tok(is);
57
58 const bool quick = tok.isLabel();
59
60 if (quick)
61 {
62 // The majority of files will have lists with sizing info
63 count = tok.labelToken();
64 }
65 is.putBack(tok);
66
67 if (!quick)
68 {
69 List<T> list(is);
70 close();
71 count = list.size();
72 }
73 }
74
75 return count;
76}
77
78
79// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
80
81template<class T>
83:
85{
86 // Check for MUST_READ_IF_MODIFIED
88
89 readIOcontents();
90}
91
92
93template<class T>
95:
97{
98 // Check for MUST_READ_IF_MODIFIED
100
101 readIOcontents();
102}
103
104
105template<class T>
106Foam::IOList<T>::IOList(const IOobject& io, const label len)
107:
109{
110 // Check for MUST_READ_IF_MODIFIED
112
113 if (!readIOcontents())
115 List<T>::resize(len);
116 }
117}
118
119
120template<class T>
121Foam::IOList<T>::IOList(const IOobject& io, const UList<T>& content)
122:
123 regIOobject(io)
124{
125 // Check for MUST_READ_IF_MODIFIED
127
128 if (!readIOcontents())
130 List<T>::operator=(content);
131 }
132}
133
134
135template<class T>
136Foam::IOList<T>::IOList(const IOobject& io, List<T>&& content)
137:
138 regIOobject(io)
139{
140 // Check for MUST_READ_IF_MODIFIED
142
144
145 readIOcontents();
146}
147
148
149template<class T>
151(
152 const IOobject& io,
153 const UList<T>& content
154)
155:
157 contentRef_(content)
158{}
159
160
161// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
162
163template<class T>
165{
167 if (rio.readOpt() == IOobjectOption::READ_MODIFIED)
168 {
169 rio.readOpt(IOobjectOption::MUST_READ);
170 }
171 rio.resetHeader();
172
173 // Construct NO_READ, changing after construction
174 const auto rOpt = rio.readOpt(IOobjectOption::NO_READ);
175
176 IOList<T> reader(rio);
177 reader.readOpt(rOpt);
178
179 return reader.readIOsize();
180}
181
182
183template<class T>
185{
188 {
190 }
191 rio.resetHeader();
192
193 IOList<T> reader(rio);
194
195 return List<T>(std::move(static_cast<List<T>&>(reader)));
196}
197
198
199template<class T>
201(
202 const IOobject& io,
203 const UList<T>& content
204)
205{
207 (
209 content
210 );
211
212 writer.write();
213}
214
215
216// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
217
218template<class T>
222 return os.good();
223}
224
225
226template<class T>
228{
229 os << contentRef_;
230 return os.good();
231}
232
233
234// ************************************************************************* //
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edgesCentres")))
A IOList wrapper for writing external List data.
Definition IOList.H:186
IOListRef()=delete
No default construct.
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition IOList.C:220
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition IOList.C:212
IOList(const IOList &)=default
Default copy construct.
static List< T > readContents(const IOobject &io)
Read and return contents. The IOobject is never registered.
Definition IOList.C:177
static void writeContents(const IOobject &io, const UList< T > &content)
Write contents. The IOobject is never registered.
Definition IOList.C:194
static label readContentsSize(const IOobject &io)
Read and return content size, -1 if not read.
Definition IOList.C:157
@ NO_REGISTER
Do not request registration (bool: false).
readOption readOpt() const noexcept
Get the read option.
@ NO_READ
Nothing to be read.
@ MUST_READ
Reading required.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
void warnNoRereading() const
Helper: warn that type does not support re-reading.
void resetHeader(const word &newName=word::null)
Clear various bits (headerClassName, note, sizeof...) that would be obtained when reading from a file...
Definition IOobject.C:644
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition List.C:347
void operator=(const UList< T > &list)
Assignment to UList operator. Takes linear time.
Definition List.C:381
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
OBJstream os(runTime.globalPath()/outputName)
const auto & io
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition BitOps.H:73