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-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::IListStream
28 
29 Description
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 
34 See 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 
49 namespace Foam
50 {
51 
52 namespace Detail
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class Detail::IListStreamAllocator Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 //- An stream/stream-buffer input allocator with List storage
61 :
62  private List<char>,
64 {
65 protected:
66 
67  // Constructors
68 
69  //- Default construct
71  :
72  List<char>(),
73  UIListStreamAllocator(List<char>::data(), List<char>::size())
74  {}
75 
76  //- Move construct from List
78  :
79  List<char>(std::move(buffer)),
80  UIListStreamAllocator(List<char>::data(), List<char>::size())
81  {}
82 
83  //- Move construct from DynamicList
84  template<int SizeMin>
86  :
87  List<char>(std::move(buffer)),
88  UIListStreamAllocator(List<char>::data(), List<char>::size())
89  {}
90 
91 
92  // Protected Member Functions
93 
94  //- Convenience method to address the underlying List storage
95  inline void reset_gbuffer()
96  {
98  (
101  );
102  }
103 
104 public:
105 
106  // Member Functions
107 
108  //- The current get position in the buffer
110 
111  //- Clear storage
112  inline void clearStorage()
113  {
115  reset_gbuffer();
116  }
117 
118  //- Transfer contents to other List
119  inline void swap(List<char>& list)
120  {
122  reset_gbuffer();
123  }
124 };
125 
126 } // End namespace Detail
127 
128 
129 /*---------------------------------------------------------------------------*\
130  Class IListStream Declaration
131 \*---------------------------------------------------------------------------*/
132 
133 //- An ISstream with internal List storage
134 class IListStream
135 :
137  public ISstream
138 {
140 
141 public:
142 
143  // Constructors
144 
145  //- Default construct with an empty list
146  explicit IListStream
147  (
150  )
151  :
152  allocator_type(),
153  ISstream(stream_, "input", format, version)
154  {}
155 
156 
157  //- Move construct from List
158  explicit IListStream
159  (
160  ::Foam::List<char>&& buffer, // Fully qualify (issue #1521)
163  const Foam::string& name="input"
164  )
165  :
166  allocator_type(std::move(buffer)),
168  {}
169 
170 
171  //- Move construct from DynamicList
172  template<int SizeMin>
173  explicit IListStream
174  (
175  DynamicList<char,SizeMin>&& buffer,
178  const Foam::string& name="input"
179  )
180  :
181  allocator_type(std::move(buffer)),
183  {}
184 
185 
186  // Member Functions
187 
188  //- The current get position in the buffer
189  using allocator_type::size;
190 
191 
192  //- Return the current get position in the buffer
193  std::streampos pos() const
194  {
195  return allocator_type::tellg();
196  }
197 
198  //- Rewind the stream, clearing any old errors
199  virtual void rewind()
200  {
202  setGood(); // resynchronize with internal state
203  }
204 
205 
206  //- Print stream description to Ostream
207  virtual void print(Ostream& os) const;
208 
209 
210  // Member Operators
211 
212  //- A non-const reference to const Istream
213  // Needed for read-constructors where the stream argument is temporary
214  Istream& operator()() const
215  {
216  return const_cast<Istream&>(static_cast<const Istream&>(*this));
217  }
218 };
219 
220 
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 
223 } // End namespace Foam
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 #endif
228 
229 // ************************************************************************* //
Foam::IListStream::operator()
Istream & operator()() const
A non-const reference to const Istream.
Definition: IListStream.H:213
List.H
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::Detail::IListStreamAllocator
An stream/stream-buffer input allocator with List storage.
Definition: IListStream.H:59
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:289
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number (2.0)
Definition: IOstreamOption.H:168
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
Foam::Detail::UIListStreamAllocator::list
const UList< char > list() const
Const UList access to the input characters (shallow copy).
Definition: UIListStream.H:164
Foam::IListStream
An ISstream with internal List storage.
Definition: IListStream.H:133
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:73
Foam::Detail::IListStreamAllocator::IListStreamAllocator
IListStreamAllocator(List< char > &&buffer)
Move construct from List.
Definition: IListStream.H:76
Foam::Detail::UIListStreamAllocator
An stream/stream-buffer input allocator for a externally allocated list.
Definition: UIListStream.H:121
Foam::Detail::UIListStreamAllocator::tellg
std::streampos tellg() const
Position of the get buffer.
Definition: UIListStream.H:182
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
UIListStream.H
Foam::ISstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: ISstream.H:124
Foam::IOstreamOption::version
versionNumber version() const noexcept
Get the stream version.
Definition: IOstreamOption.H:341
Foam::Detail::IListStreamAllocator::IListStreamAllocator
IListStreamAllocator()
Default construct.
Definition: IListStream.H:69
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam::Detail::UIListStreamAllocator::reset
void reset(char *buffer, size_t nbytes)
Reset buffer pointers.
Definition: UIListStream.H:149
Foam::ISstream::ISstream
ISstream(std::istream &is, const string &streamName, IOstreamOption streamOpt=IOstreamOption())
Construct wrapper around std::istream, set stream status.
Definition: ISstreamI.H:32
Foam::IListStream::IListStream
IListStream(streamFormat format=ASCII, versionNumber version=currentVersion)
Default construct with an empty list.
Definition: IListStream.H:146
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Detail::UIListStreamAllocator::stream_
stream_type stream_
The stream.
Definition: UIListStream.H:133
Foam::Detail::IListStreamAllocator::IListStreamAllocator
IListStreamAllocator(DynamicList< char, SizeMin > &&buffer)
Move construct from DynamicList.
Definition: IListStream.H:84
Foam::IListStream::rewind
virtual void rewind()
Rewind the stream, clearing any old errors.
Definition: IListStream.H:198
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
Foam::Detail::IListStreamAllocator::swap
void swap(List< char > &list)
Transfer contents to other List.
Definition: IListStream.H:118
Foam::IOstream::setGood
void setGood()
Set stream to be good.
Definition: IOstream.H:141
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::IListStream::pos
std::streampos pos() const
Return the current get position in the buffer.
Definition: IListStream.H:192
Foam::IListStream::print
virtual void print(Ostream &os) const
Print stream description to Ostream.
Definition: ListStream.C:34
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:115
Foam::Detail::IListStreamAllocator::reset_gbuffer
void reset_gbuffer()
Convenience method to address the underlying List storage.
Definition: IListStream.H:94
Foam::Detail::IListStreamAllocator::clearStorage
void clearStorage()
Clear storage.
Definition: IListStream.H:111
Foam::Detail::UIListStreamAllocator::size
label size() const
The list size.
Definition: UIListStream.H:176
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Detail::UIListStreamAllocator::rewind
void rewind()
Move to buffer start, clear errors.
Definition: UIListStream.H:188
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55