Skip to content

Commit f723657

Browse files
committedAug 9, 2021
Resync more code with upstream
1 parent 507ba86 commit f723657

File tree

2 files changed

+42
-56
lines changed

2 files changed

+42
-56
lines changed
 

‎external/libdxfrw/intern/dwgbuffer.cpp

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -151,45 +151,37 @@ bool dwgCharStream::read( duint8 *s, duint64 n )
151151
return true;
152152
}
153153

154-
dwgBuffer::dwgBuffer( duint8 *buf, int size, DRW_TextCodec *dc )
155-
{
156-
filestr = new dwgCharStream( buf, size );
157-
decoder = dc;
158-
maxSize = size;
159-
bitPos = 0;
160-
}
161-
162-
dwgBuffer::dwgBuffer( std::ifstream *stream, DRW_TextCodec *dc )
163-
{
164-
filestr = new dwgFileStream( stream );
165-
decoder = dc;
166-
maxSize = filestr->size();
167-
bitPos = 0;
168-
}
169-
170-
dwgBuffer::dwgBuffer( const dwgBuffer &org )
171-
{
172-
filestr = org.filestr->clone();
173-
decoder = org.decoder;
174-
maxSize = filestr->size();
175-
currByte = org.currByte;
176-
bitPos = org.bitPos;
177-
}
154+
dwgBuffer::dwgBuffer(duint8 *buf, duint64 size, DRW_TextCodec *dc)
155+
:decoder{dc}
156+
,filestr{new dwgCharStream(buf, size)}
157+
,maxSize{size}
158+
{}
159+
160+
dwgBuffer::dwgBuffer(std::ifstream *stream, DRW_TextCodec *dc)
161+
:decoder{dc}
162+
,filestr{new dwgFileStream(stream)}
163+
,maxSize{filestr->size()}
164+
{}
165+
166+
dwgBuffer::dwgBuffer( const dwgBuffer& org )
167+
:decoder{org.decoder}
168+
,filestr{org.filestr->clone()}
169+
,maxSize{filestr->size()}
170+
,currByte{org.currByte}
171+
,bitPos{org.bitPos}
172+
{}
178173

179174
dwgBuffer &dwgBuffer::operator=( const dwgBuffer &org )
180175
{
181-
filestr = org.filestr->clone();
176+
filestr.reset(org.filestr->clone());
182177
decoder = org.decoder;
183178
maxSize = filestr->size();
184179
currByte = org.currByte;
185180
bitPos = org.bitPos;
186181
return *this;
187182
}
188183

189-
dwgBuffer::~dwgBuffer()
190-
{
191-
delete filestr;
192-
}
184+
dwgBuffer::~dwgBuffer() = default;
193185

194186
//! Gets the current byte position in buffer
195187
duint64 dwgBuffer::getPosition()
@@ -349,9 +341,9 @@ dint16 dwgBuffer::getSBitShort()
349341
{
350342
duint8 b = get2Bits();
351343
if ( b == 0 )
352-
return ( dint16 )getRawShort16();
344+
return static_cast<dint16>(getRawShort16());
353345
else if ( b == 1 )
354-
return ( dint16 )getRawChar8();
346+
return static_cast<dint16>(getRawChar8());
355347
else if ( b == 2 )
356348
return 0;
357349
else
@@ -880,16 +872,12 @@ duint32 dwgBuffer::getCmColor( DRW::Version v )
880872
{
881873
case 0xC0:
882874
return 256;//ByLayer
883-
break;
884875
case 0xC1:
885876
return 0;//ByBlock
886-
break;
887877
case 0xC2:
888878
return 256;//RGB RLZ TODO
889-
break;
890879
case 0xC3:
891880
return rgb & 0xFF; //ACIS
892-
break;
893881
default:
894882
break;
895883
}
@@ -978,7 +966,7 @@ bool dwgBuffer::getBytes( unsigned char *buf, int size )
978966

979967
duint16 dwgBuffer::crc8( duint16 dx, dint32 start, dint32 end )
980968
{
981-
int pos = filestr->getPos();
969+
duint64 pos = filestr->getPos();
982970
filestr->setPos( start );
983971
int n = end - start;
984972
duint8 *tmpBuf = new duint8[n];
@@ -1003,7 +991,7 @@ duint16 dwgBuffer::crc8( duint16 dx, dint32 start, dint32 end )
1003991

1004992
duint32 dwgBuffer::crc32( duint32 seed, dint32 start, dint32 end )
1005993
{
1006-
int pos = filestr->getPos();
994+
duint64 pos = filestr->getPos();
1007995
filestr->setPos( start );
1008996
int n = end - start;
1009997
duint8 *tmpBuf = new duint8[n];

‎external/libdxfrw/intern/dwgbuffer.h

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <fstream>
1717
#include <sstream>
18+
#include <memory>
1819
#include "../drw_base.h"
1920

2021
class DRW_Coord;
@@ -51,38 +52,35 @@ class dwgFileStream: public dwgBasicStream
5152
virtual bool good() {return stream->good();}
5253
virtual dwgBasicStream *clone() {return new dwgFileStream( stream );}
5354
private:
54-
std::ifstream *stream = nullptr;
55-
duint64 sz;
55+
std::ifstream *stream{nullptr};
56+
duint64 sz{0};
5657
};
5758

5859
class dwgCharStream: public dwgBasicStream
5960
{
6061
public:
61-
dwgCharStream( duint8 *buf, int s )
62-
{
63-
stream = buf;
64-
sz = s;
65-
pos = 0;
66-
isOk = true;
67-
}
62+
dwgCharStream( duint8 *buf, duint64 s )
63+
:stream{buf}
64+
,sz{s}
65+
{}
6866
virtual bool read( duint8 *s, duint64 n );
6967
virtual duint64 size() {return sz;}
7068
virtual duint64 getPos() {return pos;}
7169
virtual bool setPos( duint64 p );
7270
virtual bool good() {return isOk;}
7371
virtual dwgBasicStream *clone() {return new dwgCharStream( stream, sz );}
7472
private:
75-
duint8 *stream = nullptr;
76-
duint64 sz;
77-
duint64 pos;
78-
bool isOk;
73+
duint8 *stream{nullptr};
74+
duint64 sz{0};
75+
duint64 pos{0};
76+
bool isOk{true};
7977
};
8078

8179
class dwgBuffer
8280
{
8381
public:
8482
dwgBuffer( std::ifstream *stream, DRW_TextCodec *decoder = nullptr );
85-
dwgBuffer( duint8 *buf, int size, DRW_TextCodec *decoder = nullptr );
83+
dwgBuffer( duint8 *buf, duint64 size, DRW_TextCodec *decoder = nullptr );
8684
dwgBuffer( const dwgBuffer &org );
8785
dwgBuffer &operator=( const dwgBuffer &org );
8886
~dwgBuffer();
@@ -144,13 +142,13 @@ class dwgBuffer
144142
duint32 crc32( duint32 seed, dint32 start, dint32 end );
145143

146144
// duint8 getCurrByte(){return currByte;}
147-
DRW_TextCodec *decoder = nullptr;
145+
DRW_TextCodec *decoder{nullptr};
148146

149147
private:
150-
dwgBasicStream *filestr = nullptr;
151-
int maxSize;
152-
duint8 currByte;
153-
duint8 bitPos;
148+
std::unique_ptr<dwgBasicStream> filestr;
149+
duint64 maxSize{0};
150+
duint8 currByte{0};
151+
duint8 bitPos{0};
154152

155153
UTF8STRING get8bitStr();
156154
UTF8STRING get16bitStr( duint16 textSize, bool nullTerm = true );

0 commit comments

Comments
 (0)
Please sign in to comment.