IListStream.H
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) 2017-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::IListStream
28
29Description
30 An input stream that reads from a List and manages the List storage.
31 Similar to IStringStream but with a List for its storage instead of
32 as string to allow reuse of List contents without copying.
33
34See Also
35 Foam::OListStream
36 Foam::UIListStream
37 Foam::UOListStream
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef IListStream_H
42#define IListStream_H
43
44#include "List.H"
45#include "UIListStream.H"
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
50{
51namespace Detail
52{
53
54/*---------------------------------------------------------------------------*\
55 Class Detail::IListStreamAllocator Declaration
56\*---------------------------------------------------------------------------*/
57
58//- An stream/stream-buffer input allocator with List storage
60:
61 private List<char>,
63{
64protected:
65
66 // Constructors
67
68 //- Default construct
70 :
71 List<char>(),
72 UIListStreamAllocator(List<char>::data(), List<char>::size())
73 {}
74
75 //- Move construct from List
77 :
78 List<char>(std::move(buffer)),
79 UIListStreamAllocator(List<char>::data(), List<char>::size())
80 {}
81
82 //- Move construct from DynamicList
83 template<int SizeMin>
85 :
86 List<char>(std::move(buffer)),
87 UIListStreamAllocator(List<char>::data(), List<char>::size())
88 {}
89
90
91 // Protected Member Functions
92
93 //- Convenience method to address the underlying List storage
94 inline void reset_gbuffer()
95 {
97 (
100 );
101 }
102
103public:
104
105 // Member Functions
106
107 //- The current get position in the buffer
109
110 //- Clear storage
111 inline void clearStorage()
112 {
115 }
116
117 //- Transfer contents to other List
118 inline void swap(List<char>& list)
119 {
122 }
123};
124
125} // End namespace Detail
126
127
128/*---------------------------------------------------------------------------*\
129 Class IListStream Declaration
130\*---------------------------------------------------------------------------*/
131
132//- An ISstream with internal List storage. Always UNCOMPRESSED.
133class IListStream
134:
136 public ISstream
137{
139
140public:
141
142 // Constructors
143
144 //- Default construct with an empty list
145 explicit IListStream
146 (
147 IOstreamOption streamOpt = IOstreamOption()
148 )
149 :
151 ISstream(stream_, "input", streamOpt.format(), streamOpt.version())
152 {}
153
154 //- Move construct from List
155 explicit IListStream
156 (
157 ::Foam::List<char>&& buffer, // Fully qualify (issue #1521)
158 IOstreamOption streamOpt = IOstreamOption()
159 )
160 :
161 allocator_type(std::move(buffer)),
162 ISstream(stream_, "input", streamOpt.format(), streamOpt.version())
163 {}
164
165
166 //- Move construct from DynamicList
167 template<int SizeMin>
168 explicit IListStream
169 (
171 IOstreamOption streamOpt = IOstreamOption()
172 )
173 :
174 allocator_type(std::move(buffer)),
175 ISstream(stream_, "input", streamOpt.format(), streamOpt.version())
176 {}
177
178
179 // Member Functions
180
181 //- The current get position in the buffer
183
184
185 //- Return the current get position in the buffer
186 std::streampos pos() const
187 {
188 return allocator_type::tellg();
189 }
190
191 //- Rewind the stream, clearing any old errors
192 virtual void rewind()
193 {
195 setGood(); // resynchronize with internal state
196 }
197
198
199 //- Print stream description to Ostream
200 virtual void print(Ostream& os) const;
201
202
203 // Member Operators
204
205 //- A non-const reference to const Istream
206 // Needed for read-constructors where the stream argument is temporary
207 Istream& operator()() const
208 {
209 // Could also rewind
210 return const_cast<IListStream&>(*this);
211 }
212
213
214 // Additional constructors and methods (as per v2012 and earlier)
215 #ifdef Foam_IOstream_extras
216
217 //- Construct with an empty list
218 explicit IListStream
219 (
222 )
223 :
224 IListStream(IOstreamOption(fmt, ver))
225 {}
226
227
228 //- Move construct from List
229 IListStream
230 (
231 ::Foam::List<char>&& buffer, // Fully qualify (issue #1521)
233 IOstreamOption::versionNumber ver = IOstreamOption::currentVersion
234 )
235 :
236 IListStream(std::move(buffer), IOstreamOption(fmt, ver))
237 {}
238
239
240 //- Move construct from DynamicList
241 template<int SizeMin>
242 explicit IListStream
243 (
244 DynamicList<char,SizeMin>&& buffer,
246 IOstreamOption::versionNumber ver = IOstreamOption::currentVersion
247 )
248 :
249 IListStream(std::move(buffer), IOstreamOption(fmt, ver))
250 {}
251
252 #endif /* Foam_IOstream_extras */
253};
254
255
256// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257
258} // End namespace Foam
259
260// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261
262#endif
263
264// ************************************************************************* //
An stream/stream-buffer input allocator with List storage.
Definition: IListStream.H:62
void reset_gbuffer()
Convenience method to address the underlying List storage.
Definition: IListStream.H:93
IListStreamAllocator()
Default construct.
Definition: IListStream.H:68
void clearStorage()
Clear storage.
Definition: IListStream.H:110
IListStreamAllocator(DynamicList< char, SizeMin > &&buffer)
Move construct from DynamicList.
Definition: IListStream.H:83
label size() const
The current get position in the buffer.
Definition: UIListStream.H:175
void swap(List< char > &list)
Transfer contents to other List.
Definition: IListStream.H:117
IListStreamAllocator(List< char > &&buffer)
Move construct from List.
Definition: IListStream.H:75
An stream/stream-buffer input allocator for a externally allocated list.
Definition: UIListStream.H:121
const UList< char > list() const
Const UList access to the input characters (shallow copy).
Definition: UIListStream.H:163
label size() const
The list size.
Definition: UIListStream.H:175
stream_type stream_
The stream.
Definition: UIListStream.H:132
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
An ISstream with internal List storage. Always UNCOMPRESSED.
Definition: IListStream.H:136
Istream & operator()() const
A non-const reference to const Istream.
Definition: IListStream.H:206
IListStream(DynamicList< char, SizeMin > &&buffer, IOstreamOption streamOpt=IOstreamOption())
Move construct from DynamicList.
Definition: IListStream.H:168
virtual void print(Ostream &os) const
Print stream description to Ostream.
Definition: ListStream.C:34
IListStream(::Foam::List< char > &&buffer, IOstreamOption streamOpt=IOstreamOption())
Move construct from List.
Definition: IListStream.H:155
IListStream(IOstreamOption streamOpt=IOstreamOption())
Default construct with an empty list.
Definition: IListStream.H:145
std::streampos pos() const
Return the current get position in the buffer.
Definition: IListStream.H:185
virtual void rewind()
Rewind the stream, clearing any old errors.
Definition: IListStream.H:191
Representation of a major/minor version number.
The IOstreamOption is a simple container for options an IOstream can normally have.
versionNumber version() const noexcept
Get the stream version.
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
streamFormat format() const noexcept
Get the current stream format.
streamFormat
Data format (ascii | binary)
static const versionNumber currentVersion
The current version number (2.0)
void setGood() noexcept
Set stream state to be good.
Definition: IOstream.H:147
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
void rewind() const
Rewind the output stream (master only).
Definition: ensightCase.C:848
void reset()
Reset to defaults.
std::streamsize tellg() const
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.