diff --git a/external/libdxfrw/intern/dwgbuffer.cpp b/external/libdxfrw/intern/dwgbuffer.cpp index 2b19c8d1709..c1b98ebe03d 100644 --- a/external/libdxfrw/intern/dwgbuffer.cpp +++ b/external/libdxfrw/intern/dwgbuffer.cpp @@ -151,34 +151,29 @@ bool dwgCharStream::read( duint8 *s, duint64 n ) return true; } -dwgBuffer::dwgBuffer( duint8 *buf, int size, DRW_TextCodec *dc ) -{ - filestr = new dwgCharStream( buf, size ); - decoder = dc; - maxSize = size; - bitPos = 0; -} +dwgBuffer::dwgBuffer(duint8 *buf, duint64 size, DRW_TextCodec *dc) + :decoder{dc} + ,filestr{new dwgCharStream(buf, size)} + ,maxSize{size} +{} -dwgBuffer::dwgBuffer( std::ifstream *stream, DRW_TextCodec *dc ) -{ - filestr = new dwgFileStream( stream ); - decoder = dc; - maxSize = filestr->size(); - bitPos = 0; -} +dwgBuffer::dwgBuffer(std::ifstream *stream, DRW_TextCodec *dc) + :decoder{dc} + ,filestr{new dwgFileStream(stream)} + ,maxSize{filestr->size()} +{} -dwgBuffer::dwgBuffer( const dwgBuffer &org ) -{ - filestr = org.filestr->clone(); - decoder = org.decoder; - maxSize = filestr->size(); - currByte = org.currByte; - bitPos = org.bitPos; -} +dwgBuffer::dwgBuffer( const dwgBuffer& org ) + :decoder{org.decoder} + ,filestr{org.filestr->clone()} + ,maxSize{filestr->size()} + ,currByte{org.currByte} + ,bitPos{org.bitPos} +{} dwgBuffer &dwgBuffer::operator=( const dwgBuffer &org ) { - filestr = org.filestr->clone(); + filestr.reset(org.filestr->clone()); decoder = org.decoder; maxSize = filestr->size(); currByte = org.currByte; @@ -186,10 +181,7 @@ dwgBuffer &dwgBuffer::operator=( const dwgBuffer &org ) return *this; } -dwgBuffer::~dwgBuffer() -{ - delete filestr; -} +dwgBuffer::~dwgBuffer() = default; //! Gets the current byte position in buffer duint64 dwgBuffer::getPosition() @@ -349,9 +341,9 @@ dint16 dwgBuffer::getSBitShort() { duint8 b = get2Bits(); if ( b == 0 ) - return ( dint16 )getRawShort16(); + return static_cast(getRawShort16()); else if ( b == 1 ) - return ( dint16 )getRawChar8(); + return static_cast(getRawChar8()); else if ( b == 2 ) return 0; else @@ -880,16 +872,12 @@ duint32 dwgBuffer::getCmColor( DRW::Version v ) { case 0xC0: return 256;//ByLayer - break; case 0xC1: return 0;//ByBlock - break; case 0xC2: return 256;//RGB RLZ TODO - break; case 0xC3: return rgb & 0xFF; //ACIS - break; default: break; } @@ -978,7 +966,7 @@ bool dwgBuffer::getBytes( unsigned char *buf, int size ) duint16 dwgBuffer::crc8( duint16 dx, dint32 start, dint32 end ) { - int pos = filestr->getPos(); + duint64 pos = filestr->getPos(); filestr->setPos( start ); int n = end - start; duint8 *tmpBuf = new duint8[n]; @@ -1003,7 +991,7 @@ duint16 dwgBuffer::crc8( duint16 dx, dint32 start, dint32 end ) duint32 dwgBuffer::crc32( duint32 seed, dint32 start, dint32 end ) { - int pos = filestr->getPos(); + duint64 pos = filestr->getPos(); filestr->setPos( start ); int n = end - start; duint8 *tmpBuf = new duint8[n]; diff --git a/external/libdxfrw/intern/dwgbuffer.h b/external/libdxfrw/intern/dwgbuffer.h index 37dd386c464..9b4fcdaea56 100644 --- a/external/libdxfrw/intern/dwgbuffer.h +++ b/external/libdxfrw/intern/dwgbuffer.h @@ -15,6 +15,7 @@ #include #include +#include #include "../drw_base.h" class DRW_Coord; @@ -51,20 +52,17 @@ class dwgFileStream: public dwgBasicStream virtual bool good() {return stream->good();} virtual dwgBasicStream *clone() {return new dwgFileStream( stream );} private: - std::ifstream *stream = nullptr; - duint64 sz; + std::ifstream *stream{nullptr}; + duint64 sz{0}; }; class dwgCharStream: public dwgBasicStream { public: - dwgCharStream( duint8 *buf, int s ) - { - stream = buf; - sz = s; - pos = 0; - isOk = true; - } + dwgCharStream( duint8 *buf, duint64 s ) + :stream{buf} + ,sz{s} + {} virtual bool read( duint8 *s, duint64 n ); virtual duint64 size() {return sz;} virtual duint64 getPos() {return pos;} @@ -72,17 +70,17 @@ class dwgCharStream: public dwgBasicStream virtual bool good() {return isOk;} virtual dwgBasicStream *clone() {return new dwgCharStream( stream, sz );} private: - duint8 *stream = nullptr; - duint64 sz; - duint64 pos; - bool isOk; + duint8 *stream{nullptr}; + duint64 sz{0}; + duint64 pos{0}; + bool isOk{true}; }; class dwgBuffer { public: dwgBuffer( std::ifstream *stream, DRW_TextCodec *decoder = nullptr ); - dwgBuffer( duint8 *buf, int size, DRW_TextCodec *decoder = nullptr ); + dwgBuffer( duint8 *buf, duint64 size, DRW_TextCodec *decoder = nullptr ); dwgBuffer( const dwgBuffer &org ); dwgBuffer &operator=( const dwgBuffer &org ); ~dwgBuffer(); @@ -144,13 +142,13 @@ class dwgBuffer duint32 crc32( duint32 seed, dint32 start, dint32 end ); // duint8 getCurrByte(){return currByte;} - DRW_TextCodec *decoder = nullptr; + DRW_TextCodec *decoder{nullptr}; private: - dwgBasicStream *filestr = nullptr; - int maxSize; - duint8 currByte; - duint8 bitPos; + std::unique_ptr filestr; + duint64 maxSize{0}; + duint8 currByte{0}; + duint8 bitPos{0}; UTF8STRING get8bitStr(); UTF8STRING get16bitStr( duint16 textSize, bool nullTerm = true );