duplicate code removed
[platform/upstream/libzypp.git] / zypp / base / InputStream.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/base/InputStream.cc
10  *
11 */
12 #include <iostream>
13 #include "zypp/base/LogTools.h"
14
15 #include "zypp/base/InputStream.h"
16 #include "zypp/base/GzStream.h"
17
18 using std::endl;
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24   ///////////////////////////////////////////////////////////////////
25   //
26   //    METHOD NAME : InputStream::InputStream
27   //    METHOD TYPE : Constructor
28   //
29   InputStream::InputStream()
30   : _stream( &std::cin, NullDeleter() )
31   , _name( "STDIN" )
32   {}
33
34   ///////////////////////////////////////////////////////////////////
35   //
36   //    METHOD NAME : InputStream::InputStream
37   //    METHOD TYPE : Constructor
38   //
39   InputStream::InputStream( std::istream & stream_r,
40                             const std::string & name_r )
41   : _stream( &stream_r, NullDeleter() )
42   , _name( name_r )
43   {}
44
45   ///////////////////////////////////////////////////////////////////
46   //
47   //    METHOD NAME : InputStream::InputStream
48   //    METHOD TYPE : Constructor
49   //
50   InputStream::InputStream( const Pathname & file_r )
51   : _path( file_r )
52   , _stream( new ifgzstream( _path.asString().c_str() ) )
53   , _name( _path.asString() )
54   {}
55
56   ///////////////////////////////////////////////////////////////////
57   //
58   //    METHOD NAME : InputStream::InputStream
59   //    METHOD TYPE : Constructor
60   //
61   InputStream::InputStream( const Pathname & file_r,
62                             const std::string & name_r )
63   : _path( file_r )
64   , _stream( new ifgzstream( _path.asString().c_str() ) )
65   , _name( name_r )
66   {}
67
68   ///////////////////////////////////////////////////////////////////
69   //
70   //    METHOD NAME : InputStream::InputStream
71   //    METHOD TYPE : Constructor
72   //
73   InputStream::InputStream( const std::string & file_r )
74   : _path( file_r )
75   , _stream( new ifgzstream( _path.asString().c_str() ) )
76   , _name( _path.asString() )
77   {}
78
79   ///////////////////////////////////////////////////////////////////
80   //
81   //    METHOD NAME : InputStream::InputStream
82   //    METHOD TYPE : Constructor
83   //
84   InputStream::InputStream( const std::string & file_r,
85                             const std::string & name_r )
86   : _path( file_r )
87   , _stream( new ifgzstream( _path.asString().c_str() ) )
88   , _name( name_r )
89   {}
90
91   ///////////////////////////////////////////////////////////////////
92   //
93   //    METHOD NAME : InputStream::InputStream
94   //    METHOD TYPE : Constructor
95   //
96   InputStream::InputStream( const char * file_r )
97   : _path( file_r )
98   , _stream( new ifgzstream( _path.asString().c_str() ) )
99   , _name( _path.asString() )
100   {}
101
102   ///////////////////////////////////////////////////////////////////
103   //
104   //    METHOD NAME : InputStream::InputStream
105   //    METHOD TYPE : Constructor
106   //
107   InputStream::InputStream( const char * file_r,
108                             const std::string & name_r )
109   : _path( file_r )
110   , _stream( new ifgzstream( _path.asString().c_str() ) )
111   , _name( name_r )
112   {}
113
114   ///////////////////////////////////////////////////////////////////
115   //
116   //    METHOD NAME : InputStream::~InputStream
117   //    METHOD TYPE : Destructor
118   //
119   InputStream::~InputStream()
120   {}
121
122   /******************************************************************
123    **
124    **   FUNCTION NAME : operator<<
125    **   FUNCTION TYPE : std::ostream &
126   */
127   std::ostream & operator<<( std::ostream & str, const InputStream & obj )
128   {
129     return str << obj.name() << obj.stream();
130   }
131
132   /////////////////////////////////////////////////////////////////
133 } // namespace zypp
134 ///////////////////////////////////////////////////////////////////