Skip to content

Commit

Permalink
Resync more code with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 9, 2021
1 parent 507ba86 commit f723657
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 56 deletions.
62 changes: 25 additions & 37 deletions external/libdxfrw/intern/dwgbuffer.cpp
Expand Up @@ -151,45 +151,37 @@ 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( std::ifstream *stream, DRW_TextCodec *dc )
{
filestr = new dwgFileStream( stream );
decoder = dc;
maxSize = filestr->size();
bitPos = 0;
}

dwgBuffer::dwgBuffer( const dwgBuffer &org )
{
filestr = org.filestr->clone();
decoder = org.decoder;
maxSize = filestr->size();
currByte = org.currByte;
bitPos = org.bitPos;
}
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)
:decoder{dc}
,filestr{new dwgFileStream(stream)}
,maxSize{filestr->size()}
{}

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;
bitPos = org.bitPos;
return *this;
}

dwgBuffer::~dwgBuffer()
{
delete filestr;
}
dwgBuffer::~dwgBuffer() = default;

//! Gets the current byte position in buffer
duint64 dwgBuffer::getPosition()
Expand Down Expand Up @@ -349,9 +341,9 @@ dint16 dwgBuffer::getSBitShort()
{
duint8 b = get2Bits();
if ( b == 0 )
return ( dint16 )getRawShort16();
return static_cast<dint16>(getRawShort16());
else if ( b == 1 )
return ( dint16 )getRawChar8();
return static_cast<dint16>(getRawChar8());
else if ( b == 2 )
return 0;
else
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand Down
36 changes: 17 additions & 19 deletions external/libdxfrw/intern/dwgbuffer.h
Expand Up @@ -15,6 +15,7 @@

#include <fstream>
#include <sstream>
#include <memory>
#include "../drw_base.h"

class DRW_Coord;
Expand Down Expand Up @@ -51,38 +52,35 @@ 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;}
virtual bool setPos( duint64 p );
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();
Expand Down Expand Up @@ -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<dwgBasicStream> filestr;
duint64 maxSize{0};
duint8 currByte{0};
duint8 bitPos{0};

UTF8STRING get8bitStr();
UTF8STRING get16bitStr( duint16 textSize, bool nullTerm = true );
Expand Down

0 comments on commit f723657

Please sign in to comment.