libzypp: zypp::InputStream Class Reference

libzypp 17.38.7

zypp::InputStream Class Reference

Helper to create and pass std::istream. More...

`#include <zypp-core/base/inputstream.h>`

## Public Member Functions
| InputStream ()
| Default ctor providing `std::cin`.
| InputStream (std::istream &stream_r, std::string name_r=std::string())
| Ctor providing an aleady existig `std::istream`.
| InputStream (Pathname file_r)
| Ctor for reading a (gziped) file.
| InputStream (Pathname file_r, std::string name_r)
| Ctor for reading a (gziped) file.
| InputStream (const std::string &file_r)
| Ctor for reading a (gziped) file.
| InputStream (const std::string &file_r, std::string name_r)
| Ctor for reading a (gziped) file.
| InputStream (const char *file_r)
| Ctor for reading a (gziped) file.
| InputStream (const char *file_r, std::string name_r)
| Ctor for reading a (gziped) file.
| ~InputStream ()
| Dtor.
std::istream & | stream () const
| The std::istream.
| operator std::istream & () const
| Allow implicit conversion to std::istream.
const std::string & | name () const
| Name of the std::istream.
const Pathname & | path () const
| Path to the input file or empty if no file.
std::streamoff | size () const
| Size of the input stream (informal).
void | setSize (std::streamoff val_r)
| Set the size of the input stream.

## Private Attributes
Pathname | _path
shared_ptr< std::istream > | _stream
std::string | _name
DefaultIntegral< std::streamoff,-1 > | _size

## Detailed Description

Helper to create and pass std::istream.

The provided std::istream may either be std::cin, some (gziped) file or an already existing `std::istream`.

An optional `name` argument may be passed to the ctor, to identify the stream in log messages, even if it is not a file.

Per default the name is "STDIN", the path to an input file or empty.

void parse( const InputStream & input = InputStream() )
{
// process input.stream() and refer to input.name()
// in log messages.
}
parse(); // std::cin
parse( "/some/file" ); // file
parse( "/some/file.gz" ); // gziped file
std::istream & mystream;
parse( mystream ); // some existing stream
parse( InputStream( mystream,
"my stream's name" ) );
zypp::InputStream::InputStream
InputStream()
Default ctor providing std::cin.
Definition inputstream.cc:63

Definition at line 56 of file inputstream.h.

## Constructor & Destructor Documentation

## ◆ InputStream() [1/8]

zypp::InputStream::InputStream | ( |  | ) |

Default ctor providing `std::cin`.

Definition at line 63 of file inputstream.cc.

## ◆ InputStream() [2/8]

zypp::InputStream::InputStream | ( | std::istream & | stream_r,
|  | std::string | name_r = std::string() )

Ctor providing an aleady existig `std::istream`.

Definition at line 73 of file inputstream.cc.

## ◆ InputStream() [3/8]

zypp::InputStream::InputStream | ( | Pathname | file_r | ) |

Ctor for reading a (gziped) file.

Definition at line 84 of file inputstream.cc.

## ◆ InputStream() [4/8]

zypp::InputStream::InputStream | ( | Pathname | file_r,
|  | std::string | name_r )

Ctor for reading a (gziped) file.

Definition at line 96 of file inputstream.cc.

## ◆ InputStream() [5/8]

zypp::InputStream::InputStream | ( | const std::string & | file_r | ) |

Ctor for reading a (gziped) file.

Definition at line 109 of file inputstream.cc.

## ◆ InputStream() [6/8]

zypp::InputStream::InputStream | ( | const std::string & | file_r,
|  | std::string | name_r )

Ctor for reading a (gziped) file.

Definition at line 121 of file inputstream.cc.

## ◆ InputStream() [7/8]

zypp::InputStream::InputStream | ( | const char * | file_r | ) |

Ctor for reading a (gziped) file.

Definition at line 134 of file inputstream.cc.

## ◆ InputStream() [8/8]

zypp::InputStream::InputStream | ( | const char * | file_r,
|  | std::string | name_r )

Ctor for reading a (gziped) file.

Definition at line 146 of file inputstream.cc.

## ◆ ~InputStream()

zypp::InputStream::~InputStream | ( |  | ) |

Dtor.

Definition at line 159 of file inputstream.cc.

## Member Function Documentation

## ◆ stream()

std::istream & zypp::InputStream::stream | ( |  | ) | const
| inline

The std::istream.

Note
  The provided std::istream is never `const`.

Definition at line 93 of file inputstream.h.

## ◆ operator std::istream &()

zypp::InputStream::operator std::istream & | ( |  | ) | const
| inline

Allow implicit conversion to std::istream.

Definition at line 97 of file inputstream.h.

## ◆ name()

const std::string & zypp::InputStream::name | ( |  | ) | const
| inline

Name of the std::istream.

Per default this is "STDIN", the path to an input file or empty. A custom string may be provided to the ctor.

This may be used in log messages to identify the stream even even if it is not a file.

Definition at line 107 of file inputstream.h.

## ◆ path()

const Pathname & zypp::InputStream::path | ( |  | ) | const
| inline

Path to the input file or empty if no file.

Definition at line 111 of file inputstream.h.

## ◆ size()

std::streamoff zypp::InputStream::size | ( |  | ) | const
| inline

Size of the input stream (informal).

If constructed from an uncompressed file, the file size. Otherwise `-1`. See setSize;

Definition at line 118 of file inputstream.h.

## ◆ setSize()

void zypp::InputStream::setSize | ( | std::streamoff | val_r | ) |
| inline

Set the size of the input stream.

You may set it to whatever vaule is appropriate. E.g. *=10 to compensate gzip compression. or the number of items, lines, ... The value is not used here, just provided.

Definition at line 127 of file inputstream.h.

## Member Data Documentation

## ◆ _path

Pathname zypp::InputStream::_path
| private

Definition at line 131 of file inputstream.h.

## ◆ _stream

shared_ptr<std::istream> zypp::InputStream::_stream
| private

Definition at line 132 of file inputstream.h.

## ◆ _name

std::string zypp::InputStream::_name
| private

Definition at line 133 of file inputstream.h.

## ◆ _size

DefaultIntegral<std::streamoff,-1> zypp::InputStream::_size
| private

Definition at line 134 of file inputstream.h.

The documentation for this class was generated from the following files:

- zypp-core/base/inputstream.h
- zypp-core/base/inputstream.cc