zipios++: modernize C++11

* use nullptr
* replace deprecated headers
This commit is contained in:
wmayer
2022-01-26 21:54:52 +01:00
parent 2f5e499868
commit f0f115cbf9
12 changed files with 38 additions and 38 deletions

View File

@@ -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 )

View File

@@ -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 ;
}

View File

@@ -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<uname>(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<uname>(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<gname>(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<gname>(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);

View File

@@ -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 ;
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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() ) ;

View File

@@ -1,5 +1,5 @@
#include <time.h>
#include <ctime>
#include "zipios-config.h"

View File

@@ -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 ;

View File

@@ -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();

View File

@@ -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() ) ;

View File

@@ -3,7 +3,7 @@
#include <algorithm>
#include <vector>
#include <time.h>
#include <ctime>
#include "meta-iostreams.h"
#include <zlib.h>