1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/InputStream.h
12 #ifndef ZYPP_BASE_INPUTSTREAM_H
13 #define ZYPP_BASE_INPUTSTREAM_H
17 #include "zypp/base/PtrTypes.h"
18 #include "zypp/base/DefaultIntegral.h"
19 #include "zypp/Pathname.h"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 // CLASS NAME : InputStream
29 /** Helper to create and pass std::istream.
30 * The provided std::istream may either be std::cin,
31 * sone (gziped) file or an aleady existig \c std::istream.
33 * An optional \c name arument may be passed to the ctor,
34 * to identify the stream in log messages, even if it is
37 * Per default the name is "STDIN", the path to an input file
41 * void parse( const InputStream & input = InputStream() )
43 * // process input.stream() and refer to input.name()
47 * parse(); // std::cin
48 * parse( "/some/file" ); // file
49 * parse( "/some/file.gz" ); // gziped file
50 * std::istream & mystream;
51 * parse( mystream ); // some existing stream
52 * parse( InputStream( mystream,
53 * "my stream's name" ) );
59 /** Default ctor providing \c std::cin. */
62 /** Ctor providing an aleady existig \c std::istream. */
63 InputStream( std::istream & stream_r,
64 const std::string & name_r = std::string() );
66 /** Ctor for reading a (gziped) file. */
67 InputStream( const Pathname & file_r );
69 /** Ctor for reading a (gziped) file. */
70 InputStream( const Pathname & file_r,
71 const std::string & name_r );
73 /** Ctor for reading a (gziped) file. */
74 InputStream( const std::string & file_r );
76 /** Ctor for reading a (gziped) file. */
77 InputStream( const std::string & file_r,
78 const std::string & name_r );
80 /** Ctor for reading a (gziped) file. */
81 InputStream( const char * file_r );
83 /** Ctor for reading a (gziped) file. */
84 InputStream( const char * file_r,
85 const std::string & name_r );
91 * \note The provided std::istream is never \c const.
93 std::istream & stream() const
96 /** Allow implicit conversion to std::istream.*/
97 operator std::istream &() const
100 /** Name of the std::istream.
101 * Per default this is "STDIN", the path to an input file or
102 * empty. A custom string may be provided to the ctor.
104 * This may be used in log messages to identify the stream even
105 * even if it is not a file.
107 const std::string & name() const
110 /** Path to the input file or empty if no file. */
111 const Pathname & path() const
114 /** Size of the input stream (informal).
115 * If constructed from an uncompressed file, the file size.
116 * Otherwise \c -1. See \ref setSize;
118 std::streamoff size() const
121 /** Set the size of the input stream.
122 * You may set it to whatever vaule is appropriate. E.g.
123 * <tt>*=10</tt> to compensate gzip comression. or the
124 * number of items, lines, ... The value is not used here,
127 void setSize( std::streamoff val_r )
132 shared_ptr<std::istream> _stream;
134 DefaultIntegral<std::streamoff,-1> _size;
136 ///////////////////////////////////////////////////////////////////
138 /** \relates InputStream Stream output */
139 std::ostream & operator<<( std::ostream & str, const InputStream & obj );
141 /////////////////////////////////////////////////////////////////
143 ///////////////////////////////////////////////////////////////////
144 #endif // ZYPP_BASE_INPUTSTREAM_H