libzypp  17.7.0
InputStream.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include "zypp/base/LogTools.h"
14 
15 #include "zypp/base/InputStream.h"
16 #include "zypp/base/GzStream.h"
17 
18 #include "zypp/PathInfo.h"
19 
20 using std::endl;
21 
23 namespace zypp
24 {
25 
27  namespace
28  {
29 
30  inline std::streamoff _heplerInitSize( const Pathname & file_r )
31  {
32  PathInfo p( file_r );
33  if ( p.isFile() && filesystem::zipType( file_r ) == filesystem::ZT_NONE )
34  return p.size();
35  return -1;
36  }
37 
39  } // namespace
41 
43  //
44  // METHOD NAME : InputStream::InputStream
45  // METHOD TYPE : Constructor
46  //
48  : _stream( &std::cin, NullDeleter() )
49  , _name( "STDIN" )
50  {}
51 
53  //
54  // METHOD NAME : InputStream::InputStream
55  // METHOD TYPE : Constructor
56  //
57  InputStream::InputStream( std::istream & stream_r,
58  const std::string & name_r )
59  : _stream( &stream_r, NullDeleter() )
60  , _name( name_r )
61  {}
62 
64  //
65  // METHOD NAME : InputStream::InputStream
66  // METHOD TYPE : Constructor
67  //
69  : _path( file_r )
70  , _stream( new ifgzstream( _path.asString().c_str() ) )
71  , _name( _path.asString() )
72  , _size( _heplerInitSize( _path ) )
73  {}
74 
76  //
77  // METHOD NAME : InputStream::InputStream
78  // METHOD TYPE : Constructor
79  //
81  const std::string & name_r )
82  : _path( file_r )
83  , _stream( new ifgzstream( _path.asString().c_str() ) )
84  , _name( name_r )
85  , _size( _heplerInitSize( _path ) )
86  {}
87 
89  //
90  // METHOD NAME : InputStream::InputStream
91  // METHOD TYPE : Constructor
92  //
93  InputStream::InputStream( const std::string & file_r )
94  : _path( file_r )
95  , _stream( new ifgzstream( _path.asString().c_str() ) )
96  , _name( _path.asString() )
97  , _size( _heplerInitSize( _path ) )
98  {}
99 
101  //
102  // METHOD NAME : InputStream::InputStream
103  // METHOD TYPE : Constructor
104  //
105  InputStream::InputStream( const std::string & file_r,
106  const std::string & name_r )
107  : _path( file_r )
108  , _stream( new ifgzstream( _path.asString().c_str() ) )
109  , _name( name_r )
110  , _size( _heplerInitSize( _path ) )
111  {}
112 
114  //
115  // METHOD NAME : InputStream::InputStream
116  // METHOD TYPE : Constructor
117  //
118  InputStream::InputStream( const char * file_r )
119  : _path( file_r )
120  , _stream( new ifgzstream( _path.asString().c_str() ) )
121  , _name( _path.asString() )
122  , _size( _heplerInitSize( _path ) )
123  {}
124 
126  //
127  // METHOD NAME : InputStream::InputStream
128  // METHOD TYPE : Constructor
129  //
130  InputStream::InputStream( const char * file_r,
131  const std::string & name_r )
132  : _path( file_r )
133  , _stream( new ifgzstream( _path.asString().c_str() ) )
134  , _name( name_r )
135  , _size( _heplerInitSize( _path ) )
136  {}
137 
139  //
140  // METHOD NAME : InputStream::~InputStream
141  // METHOD TYPE : Destructor
142  //
144  {}
145 
146  /******************************************************************
147  **
148  ** FUNCTION NAME : operator<<
149  ** FUNCTION TYPE : std::ostream &
150  */
151  std::ostream & operator<<( std::ostream & str, const InputStream & obj )
152  {
153  return str << obj.name() << obj.stream();
154  }
155 
157 } // namespace zypp
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
String related utilities and Regular expression matching.
Definition: Arch.h:344
Helper to create and pass std::istream.
Definition: InputStream.h:56
ZIP_TYPE zipType(const Pathname &file)
Definition: PathInfo.cc:1077
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
Common template to define ifgzstream/ofgzstream reading/writing gzip files.
Definition: GzStream.h:199
const std::string & name() const
Name of the std::istream.
Definition: InputStream.h:107
InputStream()
Default ctor providing std::cin.
Definition: InputStream.cc:47
shared_ptr custom deleter doing nothing.
Definition: PtrTypes.h:82
std::istream & stream() const
The std::istream.
Definition: InputStream.h:93
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1