From 3a4100d656182667ac4efd8d4b127ad03f7edf46 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 26 Jan 2022 21:54:52 +0100 Subject: [PATCH] zipios++: modernize C++11 * use nullptr * replace deprecated headers --- src/zipios++/collcoll.cpp | 10 +++++----- src/zipios++/dircoll.cpp | 8 ++++---- src/zipios++/directory.cpp | 18 +++++++++--------- src/zipios++/fcoll.cpp | 2 +- src/zipios++/filterinputstreambuf.cpp | 2 +- src/zipios++/filteroutputstreambuf.cpp | 2 +- src/zipios++/gzipoutputstream.cpp | 8 ++++---- src/zipios++/gzipoutputstreambuf.cpp | 2 +- src/zipios++/zipfile.cpp | 6 +++--- src/zipios++/zipinputstream.cpp | 8 ++++---- src/zipios++/zipoutputstream.cpp | 8 ++++---- src/zipios++/zipoutputstreambuf.cpp | 2 +- 12 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/zipios++/collcoll.cpp b/src/zipios++/collcoll.cpp index c193d82d48..25f784bef9 100644 --- a/src/zipios++/collcoll.cpp +++ b/src/zipios++/collcoll.cpp @@ -10,7 +10,7 @@ namespace zipios { using std::ifstream ; -CollectionCollection *CollectionCollection::_inst = 0 ; +CollectionCollection *CollectionCollection::_inst = nullptr ; CollectionCollection::CollectionCollection() { @@ -31,7 +31,7 @@ bool CollectionCollection::addCollection( const FileCollection &collection ) { bool CollectionCollection::addCollection( FileCollection *collection ) { if ( ! _valid ) throw InvalidStateException( "Attempt to add a FileCollection to an invalid CollectionCollection" ) ; - if ( collection == 0 || this == collection || ! collection->isValid() ) + if ( collection == nullptr || this == collection || ! collection->isValid() ) return false ; _collections.push_back( collection ) ; return true ; @@ -87,8 +87,8 @@ istream *CollectionCollection::getInputStream( const string &entry_name, getEntry( entry_name, cep, it, matchpath ) ; - if ( cep == 0 ) - return 0 ; + if ( cep == nullptr ) + return nullptr ; else return (*it)->getInputStream( entry_name ) ; @@ -126,7 +126,7 @@ void CollectionCollection::getEntry( const string &name, MatchPath matchpath ) const { // Returns the first matching entry. - cep = 0 ; + cep = nullptr ; for ( it = _collections.begin() ; it != _collections.end() ; it++ ) { cep = (*it)->getEntry( name, matchpath ) ; if ( cep ) diff --git a/src/zipios++/dircoll.cpp b/src/zipios++/dircoll.cpp index f669d79722..7460e0a598 100644 --- a/src/zipios++/dircoll.cpp +++ b/src/zipios++/dircoll.cpp @@ -55,7 +55,7 @@ DirectoryCollection::getEntry( const string &name, if ( ent->isValid() ) return ent ; else - return 0 ; + return nullptr ; } } @@ -81,8 +81,8 @@ std::istream *DirectoryCollection::getInputStream( const string &entry_name, ConstEntryPointer ent = getEntry( entry_name, matchpath ) ; - if ( ent == 0 ) - return 0 ; + if ( ent == nullptr ) + return nullptr ; else { string real_path( _filepath + entry_name ) ; return new ifstream( real_path.c_str(), ios::in | ios::binary ) ; @@ -94,7 +94,7 @@ std::istream *DirectoryCollection::getInputStream( const string &entry_name, ifstream *ifs = new ifstream( real_path.c_str(), ios::in | ios::binary ) ; if( ! *ifs ) { delete ifs ; - return 0 ; + return nullptr ; } else return ifs ; } diff --git a/src/zipios++/directory.cpp b/src/zipios++/directory.cpp index ec05488fe2..34b70d7106 100644 --- a/src/zipios++/directory.cpp +++ b/src/zipios++/directory.cpp @@ -51,7 +51,7 @@ struct boost::filesystem::dir_it::representation { representation(): - m_handle(0), + m_handle(nullptr), m_refcount(1), m_stat_p(false) { @@ -77,7 +77,7 @@ struct boost::filesystem::dir_it::representation ++m_refcount; return this; } - representation *release() { return --m_refcount? 0: this; } + representation *release() { return --m_refcount? nullptr: this; } representation &operator++() { @@ -85,13 +85,13 @@ struct boost::filesystem::dir_it::representation { m_stat_p = false; dirent *rc = readdir(m_handle); - if (rc != 0) + if (rc != nullptr) m_current = rc->d_name; else { m_current = ""; closedir(m_handle); - m_handle = 0; + m_handle = nullptr; } } @@ -100,7 +100,7 @@ struct boost::filesystem::dir_it::representation bool operator== (representation const &rep) const { - return (m_handle == 0) == (rep.m_handle == 0); + return (m_handle == nullptr) == (rep.m_handle == nullptr); } std::string const &operator* () { return m_current; } @@ -183,14 +183,14 @@ namespace boost template <> std::string get(dir_it const &it) { struct passwd *pw = getpwuid(it.rep->get_stat().st_uid); - if (pw == 0) + if (pw == nullptr) throw unknown_uid(it.rep->get_stat().st_uid); return pw->pw_name; } template <> void set(dir_it const &it, std::string name) { struct passwd *pw = getpwnam(name.c_str()); - if (pw != 0) + if (pw != nullptr) it.rep->change_owner(pw->pw_uid); else throw unknown_uname(name); @@ -201,14 +201,14 @@ namespace boost template <> std::string get(dir_it const &it) { struct group *grp = getgrgid(it.rep->get_stat().st_gid); - if (grp == 0) + if (grp == nullptr) throw unknown_gid(it.rep->get_stat().st_gid); return grp->gr_name; } template <> void set(dir_it const &it, std::string name) { struct group *grp = getgrnam(name.c_str()); - if (grp != 0) + if (grp != nullptr) it.rep->change_group(grp->gr_gid); else throw unknown_gname(name); diff --git a/src/zipios++/fcoll.cpp b/src/zipios++/fcoll.cpp index 3ac9cd30a6..cc5c94d174 100644 --- a/src/zipios++/fcoll.cpp +++ b/src/zipios++/fcoll.cpp @@ -66,7 +66,7 @@ ConstEntryPointer FileCollection::getEntry( const string &name, else iter = find_if( _entries.begin(), _entries.end(), FileEntry::MatchFileName( name ) ) ; if ( iter == _entries.end() ) - return 0 ; + return nullptr ; else return *iter ; } diff --git a/src/zipios++/filterinputstreambuf.cpp b/src/zipios++/filterinputstreambuf.cpp index a0212ee5e8..b7dc00d6bd 100644 --- a/src/zipios++/filterinputstreambuf.cpp +++ b/src/zipios++/filterinputstreambuf.cpp @@ -10,7 +10,7 @@ FilterInputStreambuf::FilterInputStreambuf( streambuf *inbuf, bool del_inbuf ) _del_inbuf( del_inbuf ) { _s_pos = 0; - if ( _inbuf == NULL ) { + if ( _inbuf == nullptr ) { // throw an exception } } diff --git a/src/zipios++/filteroutputstreambuf.cpp b/src/zipios++/filteroutputstreambuf.cpp index ffb6e04a52..7f2ed3707a 100644 --- a/src/zipios++/filteroutputstreambuf.cpp +++ b/src/zipios++/filteroutputstreambuf.cpp @@ -9,7 +9,7 @@ FilterOutputStreambuf::FilterOutputStreambuf( streambuf *outbuf, bool del_outbuf : _outbuf( outbuf), _del_outbuf( del_outbuf ) { - if ( _outbuf == NULL ) { + if ( _outbuf == nullptr ) { // throw an exception } } diff --git a/src/zipios++/gzipoutputstream.cpp b/src/zipios++/gzipoutputstream.cpp index 15ed013e27..6c3598b92f 100644 --- a/src/zipios++/gzipoutputstream.cpp +++ b/src/zipios++/gzipoutputstream.cpp @@ -11,8 +11,8 @@ using std::ostream; namespace zipios { GZIPOutputStream::GZIPOutputStream( std::ostream &os ) - : ostream( 0 ), - ofs( 0 ) + : ostream( nullptr ), + ofs( nullptr ) { ozf = new GZIPOutputStreambuf( os.rdbuf() ) ; @@ -20,8 +20,8 @@ GZIPOutputStream::GZIPOutputStream( std::ostream &os ) } GZIPOutputStream::GZIPOutputStream( const std::string &filename ) - : ostream( 0 ), - ofs( 0 ) + : ostream( nullptr ), + ofs( nullptr ) { ofs = new std::ofstream( filename.c_str(), std::ios::out | std::ios::binary ) ; ozf = new GZIPOutputStreambuf( ofs->rdbuf() ) ; diff --git a/src/zipios++/gzipoutputstreambuf.cpp b/src/zipios++/gzipoutputstreambuf.cpp index 1e7f3bc76a..9b46edbe19 100644 --- a/src/zipios++/gzipoutputstreambuf.cpp +++ b/src/zipios++/gzipoutputstreambuf.cpp @@ -1,5 +1,5 @@ -#include +#include #include "zipios-config.h" diff --git a/src/zipios++/zipfile.cpp b/src/zipios++/zipfile.cpp index 498d81d610..3fbd1605bf 100644 --- a/src/zipios++/zipfile.cpp +++ b/src/zipios++/zipfile.cpp @@ -73,8 +73,8 @@ istream *ZipFile::getInputStream( const string &entry_name, ConstEntryPointer ent = getEntry( entry_name, matchpath ) ; - if ( ent == 0 ) - return 0 ; + if ( ent == nullptr ) + return nullptr ; else return new ZipInputStream( _filename, static_cast< const ZipCDirEntry * >( ent.get() )-> @@ -110,7 +110,7 @@ bool ZipFile::readCentralDirectory ( istream &_zipfile ) { int entry_num = 0 ; // Giving the default argument in the next line to keep Visual C++ quiet - _entries.resize ( _eocd.totalCount(), 0 ) ; + _entries.resize ( _eocd.totalCount(), nullptr ) ; while ( ( entry_num < _eocd.totalCount() ) ) { ZipCDirEntry *ent = new ZipCDirEntry ; _entries[ entry_num ] = ent ; diff --git a/src/zipios++/zipinputstream.cpp b/src/zipios++/zipinputstream.cpp index f16f993c19..4f70585371 100644 --- a/src/zipios++/zipinputstream.cpp +++ b/src/zipios++/zipinputstream.cpp @@ -14,9 +14,9 @@ using std::istream; namespace zipios { ZipInputStream::ZipInputStream( std::istream &is, std::streampos pos ) - : std::istream( 0 ), + : std::istream( nullptr ), // SGIs basic_ifstream calls istream with 0, but calls basic_ios constructor first?? - ifs( 0 ) + ifs( nullptr ) { izf = new ZipInputStreambuf( is.rdbuf(), pos ) ; // this->rdbuf( izf ) ; is replaced by: @@ -24,8 +24,8 @@ ZipInputStream::ZipInputStream( std::istream &is, std::streampos pos ) } ZipInputStream::ZipInputStream( const std::string &filename, std::streampos pos ) - : std::istream( 0 ), - ifs( 0 ) + : std::istream( nullptr ), + ifs( nullptr ) { #if defined(_WIN32) && defined(ZIPIOS_UTF8) std::wstring wsname = Base::FileInfo(filename).toStdWString(); diff --git a/src/zipios++/zipoutputstream.cpp b/src/zipios++/zipoutputstream.cpp index efc15f2670..d8104395ba 100644 --- a/src/zipios++/zipoutputstream.cpp +++ b/src/zipios++/zipoutputstream.cpp @@ -11,9 +11,9 @@ using std::ostream; namespace zipios { ZipOutputStream::ZipOutputStream( std::ostream &os ) - : std::ostream( 0 ), + : std::ostream( nullptr ), // SGIs basic_ifstream calls istream with 0, but calls basic_ios constructor first?? - ofs( 0 ) + ofs( nullptr ) { ozf = new ZipOutputStreambuf( os.rdbuf() ) ; @@ -22,8 +22,8 @@ ZipOutputStream::ZipOutputStream( std::ostream &os ) ZipOutputStream::ZipOutputStream( const std::string &filename ) - : std::ostream( 0 ), - ofs( 0 ) + : std::ostream( nullptr ), + ofs( nullptr ) { ofs = new std::ofstream( filename.c_str(), std::ios::out | std::ios::binary ) ; ozf = new ZipOutputStreambuf( ofs->rdbuf() ) ; diff --git a/src/zipios++/zipoutputstreambuf.cpp b/src/zipios++/zipoutputstreambuf.cpp index 6ab0089ae2..e62d585559 100644 --- a/src/zipios++/zipoutputstreambuf.cpp +++ b/src/zipios++/zipoutputstreambuf.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include "meta-iostreams.h" #include