libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 #include "zypp/base/LogTools.h" 00014 00015 #include "zypp/base/InputStream.h" 00016 #include "zypp/base/GzStream.h" 00017 00018 #include "zypp/PathInfo.h" 00019 00020 using std::endl; 00021 00023 namespace zypp 00024 { 00025 00027 namespace 00028 { 00029 00030 inline std::streamoff _heplerInitSize( const Pathname & file_r ) 00031 { 00032 PathInfo p( file_r ); 00033 if ( p.isFile() && filesystem::zipType( file_r ) == filesystem::ZT_NONE ) 00034 return p.size(); 00035 return -1; 00036 } 00037 00039 } // namespace 00041 00043 // 00044 // METHOD NAME : InputStream::InputStream 00045 // METHOD TYPE : Constructor 00046 // 00047 InputStream::InputStream() 00048 : _stream( &std::cin, NullDeleter() ) 00049 , _name( "STDIN" ) 00050 {} 00051 00053 // 00054 // METHOD NAME : InputStream::InputStream 00055 // METHOD TYPE : Constructor 00056 // 00057 InputStream::InputStream( std::istream & stream_r, 00058 const std::string & name_r ) 00059 : _stream( &stream_r, NullDeleter() ) 00060 , _name( name_r ) 00061 {} 00062 00064 // 00065 // METHOD NAME : InputStream::InputStream 00066 // METHOD TYPE : Constructor 00067 // 00068 InputStream::InputStream( const Pathname & file_r ) 00069 : _path( file_r ) 00070 , _stream( new ifgzstream( _path.asString().c_str() ) ) 00071 , _name( _path.asString() ) 00072 , _size( _heplerInitSize( _path ) ) 00073 {} 00074 00076 // 00077 // METHOD NAME : InputStream::InputStream 00078 // METHOD TYPE : Constructor 00079 // 00080 InputStream::InputStream( const Pathname & file_r, 00081 const std::string & name_r ) 00082 : _path( file_r ) 00083 , _stream( new ifgzstream( _path.asString().c_str() ) ) 00084 , _name( name_r ) 00085 , _size( _heplerInitSize( _path ) ) 00086 {} 00087 00089 // 00090 // METHOD NAME : InputStream::InputStream 00091 // METHOD TYPE : Constructor 00092 // 00093 InputStream::InputStream( const std::string & file_r ) 00094 : _path( file_r ) 00095 , _stream( new ifgzstream( _path.asString().c_str() ) ) 00096 , _name( _path.asString() ) 00097 , _size( _heplerInitSize( _path ) ) 00098 {} 00099 00101 // 00102 // METHOD NAME : InputStream::InputStream 00103 // METHOD TYPE : Constructor 00104 // 00105 InputStream::InputStream( const std::string & file_r, 00106 const std::string & name_r ) 00107 : _path( file_r ) 00108 , _stream( new ifgzstream( _path.asString().c_str() ) ) 00109 , _name( name_r ) 00110 , _size( _heplerInitSize( _path ) ) 00111 {} 00112 00114 // 00115 // METHOD NAME : InputStream::InputStream 00116 // METHOD TYPE : Constructor 00117 // 00118 InputStream::InputStream( const char * file_r ) 00119 : _path( file_r ) 00120 , _stream( new ifgzstream( _path.asString().c_str() ) ) 00121 , _name( _path.asString() ) 00122 , _size( _heplerInitSize( _path ) ) 00123 {} 00124 00126 // 00127 // METHOD NAME : InputStream::InputStream 00128 // METHOD TYPE : Constructor 00129 // 00130 InputStream::InputStream( const char * file_r, 00131 const std::string & name_r ) 00132 : _path( file_r ) 00133 , _stream( new ifgzstream( _path.asString().c_str() ) ) 00134 , _name( name_r ) 00135 , _size( _heplerInitSize( _path ) ) 00136 {} 00137 00139 // 00140 // METHOD NAME : InputStream::~InputStream 00141 // METHOD TYPE : Destructor 00142 // 00143 InputStream::~InputStream() 00144 {} 00145 00146 /****************************************************************** 00147 ** 00148 ** FUNCTION NAME : operator<< 00149 ** FUNCTION TYPE : std::ostream & 00150 */ 00151 std::ostream & operator<<( std::ostream & str, const InputStream & obj ) 00152 { 00153 return str << obj.name() << obj.stream(); 00154 } 00155 00157 } // namespace zypp