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-2019 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  //- Construct empty
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  //- Construct with an empty list
147  (
150  const Foam::string& name="input"
151  )
152  :
153  allocator_type(),
155  {}
156 
157 
158  //- Move construct from List
160  (
161  ::Foam::List<char>&& buffer, // Fully qualify (issue #1521)
164  const Foam::string& name="input"
165  )
166  :
167  allocator_type(std::move(buffer)),
169  {}
170 
171 
172  //- Move construct from DynamicList
173  template<int SizeMin>
175  (
176  DynamicList<char,SizeMin>&& buffer,
179  const Foam::string& name="input"
180  )
181  :
182  allocator_type(std::move(buffer)),
184  {}
185 
186 
187  // Member Functions
188 
189  //- The current get position in the buffer
190  using allocator_type::size;
191 
192 
193  //- Return the current get position in the buffer
194  std::streampos pos() const
195  {
196  return allocator_type::tellg();
197  }
198 
199  //- Rewind the stream, clearing any old errors
200  virtual void rewind()
201  {
203  setGood(); // resynchronize with internal state
204  }
205 
206 
207  //- Print description to Ostream
208  virtual void print(Ostream& os) const;
209 
210 
211  // Member operators
212 
213  //- A non-const reference to const Istream
214  // Needed for read-constructors where the stream argument is temporary
215  Istream& operator()() const
216  {
217  return const_cast<Istream&>(static_cast<const Istream&>(*this));
218  }
219 };
220 
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 } // End namespace Foam
225 
226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 
228 #endif
229 
230 // ************************************************************************* //
Foam::IListStream::IListStream
IListStream(streamFormat format=ASCII, versionNumber version=currentVersion, const Foam::string &name="input")
Construct with an empty list.
Definition: IListStream.H:146
Foam::ISstream::ISstream
ISstream(std::istream &is, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Construct as wrapper around std::istream.
Definition: ISstreamI.H:32
Foam::IListStream::operator()
Istream & operator()() const
A non-const reference to const Istream.
Definition: IListStream.H:214
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:57
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:273
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number.
Definition: IOstreamOption.H:193
Foam::ISstream
Generic input stream using standard (STL) streams.
Definition: ISstream.H:54
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:79
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:111
Foam::IOstreamOption::version
versionNumber version() const noexcept
Get the stream version.
Definition: IOstreamOption.H:321
Foam::Detail::IListStreamAllocator::IListStreamAllocator
IListStreamAllocator()
Construct empty.
Definition: IListStream.H:69
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
Foam::Detail::UIListStreamAllocator::reset
void reset(char *buffer, size_t nbytes)
Reset buffer pointers.
Definition: UIListStream.H:149
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:199
Foam::IOstreamOption::ASCII
"ascii"
Definition: IOstreamOption.H:66
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: HashTable.H:102
Foam::IListStream::pos
std::streampos pos() const
Return the current get position in the buffer.
Definition: IListStream.H:193
Foam::IListStream::print
virtual void print(Ostream &os) const
Print 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:54