Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.2:Update
libdxfrw
libdxfrw-LibreCad-2.1.0-changes.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File libdxfrw-LibreCad-2.1.0-changes.patch of Package libdxfrw
Taken from Fedora. diff -urp libdxfrw-0.6.3/src/drw_base.h LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/drw_base.h --- libdxfrw-0.6.3/src/drw_base.h 2015-10-19 13:30:57.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/drw_base.h 2016-06-05 02:27:45.000000000 -0400 @@ -149,19 +149,17 @@ enum TransparencyCodes { */ class DRW_Coord { public: - DRW_Coord() { x = 0; y = 0; z = 0; } - DRW_Coord(double ix, double iy, double iz) { - x = ix; y = iy; z = iz; - } + DRW_Coord():x(0), y(0),z(0) {} + DRW_Coord(double ix, double iy, double iz): x(ix), y(iy),z(iz){} - DRW_Coord operator = (const DRW_Coord& data) { + DRW_Coord& operator = (const DRW_Coord& data) { x = data.x; y = data.y; z = data.z; return *this; } /*!< convert to unitary vector */ void unitize(){ double dist; - dist = sqrt(x*x + y*y + z*z); + dist = hypot(hypot(x, y), z); if (dist > 0.0) { x= x/dist; y= y/dist; @@ -183,16 +181,9 @@ public: */ class DRW_Vertex2D { public: - DRW_Vertex2D() { -// eType = DRW::LWPOLYLINE; - stawidth = endwidth = bulge = 0; - } - DRW_Vertex2D(double sx, double sy, double b) { - stawidth = endwidth = 0; - x = sx; - y =sy; - bulge = b; - } + DRW_Vertex2D(): x(0), y(0), stawidth(0), endwidth(0), bulge(0){} + + DRW_Vertex2D(double sx, double sy, double b): x(sx), y(sy), stawidth(0), endwidth(0), bulge(b) {} public: double x; /*!< x coordinate, code 10 */ @@ -218,68 +209,61 @@ public: INVALID }; //TODO: add INT64 support - DRW_Variant() { - type = INVALID; - } + DRW_Variant(): sdata(std::string()), vdata(), content(0), vType(INVALID), vCode(0) {} - DRW_Variant(int c, dint32 i) { - code = c; addInt(i); - } - DRW_Variant(int c, duint32 i) { - code = c; addInt(static_cast<dint32>(i));//RLZ: verify if worrk with big numbers - } - DRW_Variant(int c, double d) { - code = c; addDouble(d); - } - DRW_Variant(int c, UTF8STRING s) { - code = c; addString(s); - } - DRW_Variant(int c, DRW_Coord crd) { - code = c; addCoord(crd); - } - DRW_Variant(const DRW_Variant& d) { - code = d.code; - type = d.type; - content = d.content; - if (d.type == COORD) { - vdata = d.vdata; + DRW_Variant(int c, dint32 i): sdata(std::string()), vdata(), content(i), vType(INTEGER), vCode(c){} + + DRW_Variant(int c, duint32 i): sdata(std::string()), vdata(), content(static_cast<dint32>(i)), vType(INTEGER), vCode(c) {} + + DRW_Variant(int c, double d): sdata(std::string()), vdata(), content(d), vType(DOUBLE), vCode(c) {} + + DRW_Variant(int c, UTF8STRING s): sdata(s), vdata(), content(&sdata), vType(STRING), vCode(c) {} + + DRW_Variant(int c, DRW_Coord crd): sdata(std::string()), vdata(crd), content(&vdata), vType(COORD), vCode(c) {} + + DRW_Variant(const DRW_Variant& d): sdata(d.sdata), vdata(d.vdata), content(d.content), vType(d.vType), vCode(d.vCode) { + if (d.vType == COORD) content.v = &vdata; - } - if (d.type == STRING) { - sdata = d.sdata; + if (d.vType == STRING) content.s = &sdata; - } } ~DRW_Variant() { } - void addString(UTF8STRING s) {setType(STRING); sdata = s; content.s = &sdata;} - void addInt(int i) {setType(INTEGER); content.i = i;} - void addDouble(double d) {setType(DOUBLE); content.d = d;} - void addCoord() {setType(COORD); vdata.x=0.0; vdata.y=0.0; vdata.z=0.0; content.v = &vdata;} - void addCoord(DRW_Coord v) {setType(COORD); vdata = v; content.v = &vdata;} - void setType(enum TYPE t) { type = t;} - void setCoordX(double d) { if (type == COORD) vdata.x = d;} - void setCoordY(double d) { if (type == COORD) vdata.y = d;} - void setCoordZ(double d) { if (type == COORD) vdata.z = d;} + void addString(int c, UTF8STRING s) {vType = STRING; sdata = s; content.s = &sdata; vCode=c;} + void addInt(int c, int i) {vType = INTEGER; content.i = i; vCode=c;} + void addDouble(int c, double d) {vType = DOUBLE; content.d = d; vCode=c;} + void addCoord(int c, DRW_Coord v) {vType = COORD; vdata = v; content.v = &vdata; vCode=c;} + void setCoordX(double d) { if (vType == COORD) vdata.x = d;} + void setCoordY(double d) { if (vType == COORD) vdata.y = d;} + void setCoordZ(double d) { if (vType == COORD) vdata.z = d;} + enum TYPE type() { return vType;} + int code() { return vCode;} /*!< returns dxf code of this value*/ + +private: + std::string sdata; + DRW_Coord vdata; private: - typedef union { + union DRW_VarContent{ UTF8STRING *s; dint32 i; double d; DRW_Coord *v; - } DRW_VarContent; + + DRW_VarContent(UTF8STRING *sd):s(sd){} + DRW_VarContent(dint32 id):i(id){} + DRW_VarContent(double dd):d(dd){} + DRW_VarContent(DRW_Coord *vd):v(vd){} + }; public: DRW_VarContent content; - enum TYPE type; - int code; /*!< dxf code of this value*/ - private: - std::string sdata; - DRW_Coord vdata; + enum TYPE vType; + int vCode; /*!< dxf code of this value*/ + }; //! Class to handle dwg handles diff -urp libdxfrw-0.6.3/src/drw_entities.cpp LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/drw_entities.cpp --- libdxfrw-0.6.3/src/drw_entities.cpp 2015-09-18 12:16:57.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/drw_entities.cpp 2016-06-05 02:27:45.000000000 -0400 @@ -16,7 +16,6 @@ #include "intern/dwgbuffer.h" #include "intern/drw_dbg.h" - //! Calculate arbitary axis /*! * Calculate arbitary axis for apply extrusions @@ -110,16 +109,13 @@ bool DRW_Entity::parseCode(int code, dxf case 1003: case 1004: case 1005: - extData.push_back(new DRW_Variant(code, reader->getString())); + extData.push_back(std::make_shared<DRW_Variant>(code, reader->getString())); break; case 1010: case 1011: case 1012: case 1013: - curr = new DRW_Variant(); - curr->addCoord(); - curr->setCoordX(reader->getDouble()); - curr->code = code; + curr =std::make_shared<DRW_Variant>(code, DRW_Coord(reader->getDouble(), 0.0, 0.0)); extData.push_back(curr); break; case 1020: @@ -135,16 +131,17 @@ bool DRW_Entity::parseCode(int code, dxf case 1033: if (curr) curr->setCoordZ(reader->getDouble()); - curr=NULL; + //FIXME, why do we discard curr right after setting the its Z +// curr=NULL; break; case 1040: case 1041: case 1042: - extData.push_back(new DRW_Variant(code, reader->getDouble() )); + extData.push_back(std::make_shared<DRW_Variant>(code, reader->getDouble() )); break; case 1070: case 1071: - extData.push_back(new DRW_Variant(code, reader->getInt32() )); + extData.push_back(std::make_shared<DRW_Variant>(code, reader->getInt32() )); break; default: break; @@ -159,28 +156,28 @@ bool DRW_Entity::parseDxfGroups(int code int nc; std::string appName= reader->getString(); if (!appName.empty() && appName.at(0)== '{'){ - curr.addString(appName.substr(1, (int) appName.size()-1)); - curr.code = code; + curr.addString(code, appName.substr(1, (int) appName.size()-1)); ls.push_back(curr); while (code !=102 && appName.at(0)== '}'){ - reader->readRec(&nc); - curr.code = code; + reader->readRec(&nc);//RLZ curr.code = code or nc? +// curr.code = code; + //RLZ code == 330 || code == 360 OR nc == 330 || nc == 360 ? if (code == 330 || code == 360) - curr.addInt(reader->getHandleString()); + curr.addInt(code, reader->getHandleString());//RLZ code or nc else { switch (reader->type) { case dxfReader::STRING: - curr.addString(reader->getString()); + curr.addString(code, reader->getString());//RLZ code or nc break; case dxfReader::INT32: case dxfReader::INT64: - curr.addInt(reader->getInt32()); + curr.addInt(code, reader->getInt32());//RLZ code or nc break; case dxfReader::DOUBLE: - curr.addDouble(reader->getDouble()); + curr.addDouble(code, reader->getDouble());//RLZ code or nc break; case dxfReader::BOOL: - curr.addInt(reader->getInt32()); + curr.addInt(code, reader->getInt32());//RLZ code or nc break; default: break; @@ -783,7 +780,7 @@ bool DRW_Ellipse::parseDwg(DRW::Version void DRW_Ellipse::toPolyline(DRW_Polyline *pol, int parts){ double radMajor, radMinor, cosRot, sinRot, incAngle, curAngle; double cosCurr, sinCurr; - radMajor = sqrt(secPoint.x*secPoint.x + secPoint.y*secPoint.y); + radMajor = hypot(secPoint.x, secPoint.y); radMinor = radMajor*ratio; //calculate sin & cos of included angle incAngle = atan2(secPoint.y, secPoint.x); @@ -1122,7 +1119,7 @@ void DRW_LWPolyline::applyExtrusion(){ if (haveExtrusion) { calculateAxis(extPoint); for (unsigned int i=0; i<vertlist.size(); i++) { - DRW_Vertex2D *vert = vertlist.at(i); + auto& vert = vertlist.at(i); DRW_Coord v(vert->x, vert->y, elevation); extrudePoint(extPoint, &v); vert->x = v.x; @@ -1134,24 +1131,24 @@ void DRW_LWPolyline::applyExtrusion(){ void DRW_LWPolyline::parseCode(int code, dxfReader *reader){ switch (code) { case 10: { - vertex = new DRW_Vertex2D(); + vertex = std::make_shared<DRW_Vertex2D>(); vertlist.push_back(vertex); vertex->x = reader->getDouble(); break; } case 20: - if(vertex != NULL) + if(vertex) vertex->y = reader->getDouble(); break; case 40: - if(vertex != NULL) + if(vertex) vertex->stawidth = reader->getDouble(); break; case 41: - if(vertex != NULL) + if(vertex) vertex->endwidth = reader->getDouble(); break; case 42: - if(vertex != NULL) + if(vertex) vertex->bulge = reader->getDouble(); break; case 38: @@ -1226,14 +1223,14 @@ bool DRW_LWPolyline::parseDwg(DRW::Versi if (vertexnum > 0) { //verify if is lwpol without vertex (empty) // add vertexs - vertex = new DRW_Vertex2D(); + vertex = std::make_shared<DRW_Vertex2D>(); vertex->x = buf->getRawDouble(); vertex->y = buf->getRawDouble(); vertlist.push_back(vertex); - DRW_Vertex2D* pv = vertex; + auto pv = vertex; for (int i = 1; i< vertexnum; i++){ - vertex = new DRW_Vertex2D(); - if (version < DRW::AC1015) {//14- + vertex = std::make_shared<DRW_Vertex2D>(); + if (version < DRW::AC1015) {//14- vertex->x = buf->getRawDouble(); vertex->y = buf->getRawDouble(); } else { @@ -1272,8 +1269,7 @@ bool DRW_LWPolyline::parseDwg(DRW::Versi } if (DRW_DBGGL == DRW_dbg::DEBUG){ DRW_DBG("\nVertex list: "); - for (std::vector<DRW_Vertex2D *>::iterator it = vertlist.begin() ; it != vertlist.end(); ++it){ - DRW_Vertex2D* pv = *it; + for (auto& pv: vertlist) { DRW_DBG("\n x: "); DRW_DBG(pv->x); DRW_DBG(" y: "); DRW_DBG(pv->y); DRW_DBG(" bulge: "); DRW_DBG(pv->bulge); DRW_DBG(" stawidth: "); DRW_DBG(pv->stawidth); DRW_DBG(" endwidth: "); DRW_DBG(pv->endwidth); } @@ -1792,12 +1788,12 @@ void DRW_Hatch::parseCode(int code, dxfR looplist.reserve(loopsnum); break; case 92: - loop = new DRW_HatchLoop(reader->getInt32()); + loop = std::make_shared<DRW_HatchLoop>(reader->getInt32()); looplist.push_back(loop); if (reader->getInt32() & 2) { ispol = true; clearEntities(); - pline = new DRW_LWPolyline; + pline = std::make_shared<DRW_LWPolyline>(); loop->objlist.push_back(pline); } else ispol = false; break; @@ -1869,7 +1865,7 @@ bool DRW_Hatch::parseDwg(DRW::Version ve //read loops for (dint32 i = 0 ; i < loopsnum; ++i){ - loop = new DRW_HatchLoop(buf->getBitLong()); + loop = std::make_shared<DRW_HatchLoop>(buf->getBitLong()); havePixelSize |= loop->type & 4; if (!(loop->type & 2)){ //Not polyline dint32 numPathSeg = buf->getBitLong(); @@ -1908,7 +1904,7 @@ bool DRW_Hatch::parseDwg(DRW::Version ve spline->ncontrol = buf->getBitLong(); spline->controllist.reserve(spline->ncontrol); for (dint32 j = 0; j < spline->ncontrol;++j){ - DRW_Coord* crd = new DRW_Coord(buf->get3BitDouble()); + std::shared_ptr<DRW_Coord> crd = std::make_shared<DRW_Coord>(buf->get3BitDouble()); spline->controllist.push_back(crd); if(isRational) crd->z = buf->getBitDouble(); //RLZ: investigate how store weight @@ -1918,8 +1914,8 @@ bool DRW_Hatch::parseDwg(DRW::Version ve spline->nfit = buf->getBitLong(); spline->fitlist.reserve(spline->nfit); for (dint32 j = 0; j < spline->nfit;++j){ - DRW_Coord* crd = new DRW_Coord(buf->get3BitDouble()); - spline->fitlist.push_back (crd); + std::shared_ptr<DRW_Coord> crd = std::make_shared<DRW_Coord>(buf->get3BitDouble()); + spline->fitlist.push_back(crd); } spline->tgStart = buf->get2RawDouble(); spline->tgEnd = buf->get2RawDouble(); @@ -1927,7 +1923,7 @@ bool DRW_Hatch::parseDwg(DRW::Version ve } } } else { //end not pline, start polyline - pline = new DRW_LWPolyline; + pline = std::make_shared<DRW_LWPolyline>(); bool asBulge = buf->getBit(); pline->flags = buf->getBit();//closed bit dint32 numVert = buf->getBitLong(); @@ -2055,29 +2051,29 @@ void DRW_Spline::parseCode(int code, dxf tolfit = reader->getDouble(); break; case 10: { - controlpoint = new DRW_Coord(); + controlpoint = std::make_shared<DRW_Coord>(); controllist.push_back(controlpoint); controlpoint->x = reader->getDouble(); break; } case 20: - if(controlpoint != NULL) + if(controlpoint) controlpoint->y = reader->getDouble(); break; case 30: - if(controlpoint != NULL) + if(controlpoint) controlpoint->z = reader->getDouble(); break; case 11: { - fitpoint = new DRW_Coord(); + fitpoint = std::make_shared<DRW_Coord>(); fitlist.push_back(fitpoint); fitpoint->x = reader->getDouble(); break; } case 21: - if(fitpoint != NULL) + if(fitpoint) fitpoint->y = reader->getDouble(); break; case 31: - if(fitpoint != NULL) + if(fitpoint) fitpoint->z = reader->getDouble(); break; case 40: @@ -2145,31 +2141,29 @@ bool DRW_Spline::parseDwg(DRW::Version v knotslist.push_back (buf->getBitDouble()); } controllist.reserve(ncontrol); - for (dint32 i= 0; i<ncontrol; ++i){ - DRW_Coord* crd = new DRW_Coord(buf->get3BitDouble()); - controllist.push_back(crd); - if (weight){ + for (dint32 i= 0; i<ncontrol; ++i){ + controllist.push_back(std::make_shared<DRW_Coord>(buf->get3BitDouble())); + if (weight) DRW_DBG("\n w: "); DRW_DBG(buf->getBitDouble()); //RLZ Warning: D (BD or RD) - } } fitlist.reserve(nfit); - for (dint32 i= 0; i<nfit; ++i){ - DRW_Coord* crd = new DRW_Coord(buf->get3BitDouble()); - fitlist.push_back (crd); - } + for (dint32 i= 0; i<nfit; ++i) + fitlist.push_back(std::make_shared<DRW_Coord>(buf->get3BitDouble())); + if (DRW_DBGGL == DRW_dbg::DEBUG){ - DRW_DBG("\nknots list: "); - for (std::vector<double>::iterator it = knotslist.begin() ; it != knotslist.end(); ++it){ - DRW_DBG("\n"); DRW_DBG(*it); - } + DRW_DBG("\nknots list: "); + for (auto const& v: knotslist) { + DRW_DBG("\n"); DRW_DBG(v); + } DRW_DBG("\ncontrol point list: "); - for (std::vector<DRW_Coord *>::iterator it = controllist.begin() ; it != controllist.end(); ++it){ - DRW_DBG("\n"); DRW_DBGPT((*it)->x,(*it)->y,(*it)->z); - } + for (auto const& v: controllist) { + DRW_DBG("\n"); DRW_DBGPT(v->x, v->y, v->z); + } DRW_DBG("\nfit point list: "); - for (std::vector<DRW_Coord *>::iterator it = fitlist.begin() ; it != fitlist.end(); ++it){ - DRW_DBG("\n"); DRW_DBGPT((*it)->x,(*it)->y,(*it)->z); - } + for (auto const& v: fitlist) { + DRW_DBG("\n"); DRW_DBGPT(v->x, v->y, v->z); + } + } /* Common Entity Handle Data */ @@ -2241,12 +2235,14 @@ bool DRW_Image::parseDwg(DRW::Version ve sizev = buf->getRawDouble(); DRW_DBG("\nsize U: "); DRW_DBG(sizeu); DRW_DBG("\nsize V: "); DRW_DBG(sizev); duint16 displayProps = buf->getBitShort(); + DRW_UNUSED(displayProps);//RLZ: temporary, complete API clip = buf->getBit(); brightness = buf->getRawChar8(); contrast = buf->getRawChar8(); fade = buf->getRawChar8(); if (version > DRW::AC1021){ //2010+ bool clipMode = buf->getBit(); + DRW_UNUSED(clipMode);//RLZ: temporary, complete API } duint16 clipType = buf->getBitShort(); if (clipType == 1){ @@ -2717,17 +2713,17 @@ void DRW_Leader::parseCode(int code, dxf case 41: textwidth = reader->getDouble(); break; - case 10: { - vertexpoint = new DRW_Coord(); + case 10: + vertexpoint= std::make_shared<DRW_Coord>(); vertexlist.push_back(vertexpoint); vertexpoint->x = reader->getDouble(); - break; } + break; case 20: - if(vertexpoint != NULL) + if(vertexpoint) vertexpoint->y = reader->getDouble(); break; case 30: - if(vertexpoint != NULL) + if(vertexpoint) vertexpoint->z = reader->getDouble(); break; case 340: @@ -2793,9 +2789,9 @@ bool DRW_Leader::parseDwg(DRW::Version v // add vertexs for (int i = 0; i< nPt; i++){ - DRW_Coord* vertex = new DRW_Coord(buf->get3BitDouble()); - vertexlist.push_back(vertex); - DRW_DBG("\nvertex "); DRW_DBGPT(vertex->x, vertex->y, vertex->z); + DRW_Coord vertex = buf->get3BitDouble(); + vertexlist.push_back(std::make_shared<DRW_Coord>(vertex)); + DRW_DBG("\nvertex "); DRW_DBGPT(vertex.x, vertex.y, vertex.z); } DRW_Coord Endptproj = buf->get3BitDouble(); DRW_DBG("\nEndptproj "); DRW_DBGPT(Endptproj.x, Endptproj.y, Endptproj.z); diff -urp libdxfrw-0.6.3/src/drw_entities.h LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/drw_entities.h --- libdxfrw-0.6.3/src/drw_entities.h 2015-09-18 12:16:57.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/drw_entities.h 2016-06-05 02:27:45.000000000 -0400 @@ -17,6 +17,7 @@ #include <string> #include <vector> #include <list> +#include <memory> #include "drw_base.h" class dxfReader; @@ -99,71 +100,17 @@ class DRW_Entity { SETENTFRIENDS public: //initializes default values - DRW_Entity() { - eType = DRW::UNKNOWN; - handle = parentHandle = DRW::NoHandle; //no handle (0) - lineType = "BYLAYER"; - color = DRW::ColorByLayer; // default BYLAYER (256) - ltypeScale = 1.0; - visible = true; - layer = "0"; - lWeight = DRW_LW_Conv::widthByLayer; // default BYLAYER (dxf -1, dwg 29) - space = DRW::ModelSpace; // default ModelSpace (0) - haveExtrusion = false; - color24 = -1; //default -1 not set - numProxyGraph = 0; - shadow = DRW::CastAndReceieveShadows; - material = DRW::MaterialByLayer; - plotStyle = DRW::DefaultPlotStyle; - transparency = DRW::Opaque; - nextEntLink = prevEntLink = 0; - numReactors = xDictFlag = 0; - curr = NULL; - ownerHandle= false; - } - - DRW_Entity(const DRW_Entity& e) { - eType = e.eType; - handle = e.handle; - parentHandle = e.parentHandle; //no handle (0) - lineType = e.lineType; - color = e.color; // default BYLAYER (256) - ltypeScale = e.ltypeScale; - visible = e.visible; - layer = e.layer; - lWeight = e.lWeight; - space = e.space; - haveExtrusion = e.haveExtrusion; - color24 = e.color24; //default -1 not set - numProxyGraph = e.numProxyGraph; - shadow = e.shadow; - material = e.material; - plotStyle = e.plotStyle; - transparency = e.transparency; - nextEntLink = e.nextEntLink; - prevEntLink = e.prevEntLink; - numReactors = e.numReactors; - xDictFlag = e.xDictFlag; - curr = NULL; - ownerHandle= false; -// curr = e.curr; - for (std::vector<DRW_Variant*>::const_iterator it=e.extData.begin(); it!=e.extData.end(); ++it){ - extData.push_back(new DRW_Variant(*(*it))); - } - } - - virtual ~DRW_Entity() { - for (std::vector<DRW_Variant*>::iterator it=extData.begin(); it!=extData.end(); ++it) - delete *it; + DRW_Entity() = default; + virtual ~DRW_Entity() = default; - extData.clear(); - } - - void reset(){ - for (std::vector<DRW_Variant*>::iterator it=extData.begin(); it!=extData.end(); ++it) - delete *it; - extData.clear(); - } + //removed copy/move ctors + // looks like the potential issue is the "curr" pointer is reset in previous + // versions during copy ctor + + void reset() { + extData.clear(); + curr.reset(); + } virtual void applyExtrusion() = 0; @@ -184,27 +131,27 @@ protected: bool parseDxfGroups(int code, dxfReader *reader); public: - enum DRW::ETYPE eType; /*!< enum: entity type, code 0 */ - duint32 handle; /*!< entity identifier, code 5 */ + enum DRW::ETYPE eType = DRW::UNKNOWN; /*!< enum: entity type, code 0 */ + duint32 handle = DRW::NoHandle; /*!< entity identifier, code 5 */ std::list<std::list<DRW_Variant> > appData; /*!< list of application data, code 102 */ - duint32 parentHandle; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */ - DRW::Space space; /*!< space indicator, code 67*/ - UTF8STRING layer; /*!< layer name, code 8 */ - UTF8STRING lineType; /*!< line type, code 6 */ - duint32 material; /*!< hard pointer id to material object, code 347 */ - int color; /*!< entity color, code 62 */ - enum DRW_LW_Conv::lineWidth lWeight; /*!< entity lineweight, code 370 */ - double ltypeScale; /*!< linetype scale, code 48 */ - bool visible; /*!< entity visibility, code 60 */ - int numProxyGraph; /*!< Number of bytes in proxy graphics, code 92 */ + duint32 parentHandle = DRW::NoHandle; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */ + DRW::Space space = DRW::ModelSpace; /*!< space indicator, code 67*/ + UTF8STRING layer = "0"; /*!< layer name, code 8 */ + UTF8STRING lineType = "BYLAYER"; /*!< line type, code 6 */ + duint32 material = DRW::MaterialByLayer; /*!< hard pointer id to material object, code 347 */ + int color = DRW::ColorByLayer; /*!< entity color, code 62 */ + enum DRW_LW_Conv::lineWidth lWeight = DRW_LW_Conv::widthByLayer; /*!< entity lineweight, code 370 */ + double ltypeScale = 1.0; /*!< linetype scale, code 48 */ + bool visible = true; /*!< entity visibility, code 60 */ + int numProxyGraph = 0; /*!< Number of bytes in proxy graphics, code 92 */ std::string proxyGraphics; /*!< proxy graphics bytes, code 310 */ - int color24; /*!< 24-bit color, code 420 */ + int color24 = -1; /*!< 24-bit color, code 420 */ std::string colorName; /*!< color name, code 430 */ - int transparency; /*!< transparency, code 440 */ - int plotStyle; /*!< hard pointer id to plot style object, code 390 */ - DRW::ShadowMode shadow; /*!< shadow mode, code 284 */ - bool haveExtrusion; /*!< set to true if the entity have extrusion*/ - std::vector<DRW_Variant*> extData; /*!< FIFO list of extended data, codes 1000 to 1071*/ + int transparency = DRW::Opaque; /*!< transparency, code 440 */ + int plotStyle = DRW::DefaultPlotStyle; /*!< hard pointer id to plot style object, code 390 */ + DRW::ShadowMode shadow = DRW::CastAndReceieveShadows; /*!< shadow mode, code 284 */ + bool haveExtrusion = false; /*!< set to true if the entity have extrusion*/ + std::vector<std::shared_ptr<DRW_Variant>> extData; /*!< FIFO list of extended data, codes 1000 to 1071*/ protected: //only for read dwg duint8 haveNextLinks; //aka nolinks //B @@ -214,19 +161,20 @@ protected: //only for read dwg duint8 shadowFlag; //presence of shadow handle ?? (in dwg may be plotflag)//RC dwgHandle lTypeH; dwgHandle layerH; - duint32 nextEntLink; - duint32 prevEntLink; - bool ownerHandle; + duint32 nextEntLink = 0; + duint32 prevEntLink = 0; + bool ownerHandle = false; - duint8 xDictFlag; - dint32 numReactors; // + duint8 xDictFlag = 0; + dint32 numReactors = 0; // duint32 objSize; //RL 32bits object data size in bits dint16 oType; private: - DRW_Coord extAxisX; + void init(DRW_Entity const& rhs); + DRW_Coord extAxisX; DRW_Coord extAxisY; - DRW_Variant* curr; + std::shared_ptr<DRW_Variant> curr; }; @@ -245,7 +193,7 @@ public: thickness = 0; } - virtual void applyExtrusion(){} + virtual void applyExtrusion(){} protected: void parseCode(int code, dxfReader *reader); @@ -272,8 +220,6 @@ public: secPoint.z = 0; } - virtual void applyExtrusion(){} - protected: void parseCode(int code, dxfReader *reader); virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); @@ -596,8 +542,7 @@ public: elevation = thickness = width = 0.0; flags = 0; extPoint.x = extPoint.y = 0; - extPoint.z = 1; - vertex = NULL; + extPoint.z = 1; } DRW_LWPolyline(const DRW_LWPolyline& p):DRW_Entity(p){ @@ -606,31 +551,21 @@ public: this->thickness = p.thickness; this->width = p.width; this->flags = p.flags; - this->extPoint = p.extPoint; - this->vertex = NULL; + this->extPoint = p.extPoint; for (unsigned i=0; i<p.vertlist.size(); i++)// RLZ ok or new - this->vertlist.push_back( new DRW_Vertex2D( *(p.vertlist.at(i)) ) ); - - this->vertex = NULL; + this->vertlist.push_back( + std::make_shared<DRW_Vertex2D>(*p.vertlist.at(i)) + ); } + // TODO rule of 5 - ~DRW_LWPolyline() { - while (!vertlist.empty()) { - vertlist.pop_back(); - } - } virtual void applyExtrusion(); void addVertex (DRW_Vertex2D v) { - DRW_Vertex2D *vert = new DRW_Vertex2D(); - vert->x = v.x; - vert->y = v.y; - vert->stawidth = v.stawidth; - vert->endwidth = v.endwidth; - vert->bulge = v.bulge; + std::shared_ptr<DRW_Vertex2D> vert = std::make_shared<DRW_Vertex2D>(v); vertlist.push_back(vert); } - DRW_Vertex2D *addVertex () { - DRW_Vertex2D *vert = new DRW_Vertex2D(); + std::shared_ptr<DRW_Vertex2D> addVertex () { + std::shared_ptr<DRW_Vertex2D> vert = std::make_shared<DRW_Vertex2D>(); vert->stawidth = 0; vert->endwidth = 0; vert->bulge = 0; @@ -649,8 +584,8 @@ public: double elevation; /*!< elevation, code 38 */ double thickness; /*!< thickness, code 39 */ DRW_Coord extPoint; /*!< Dir extrusion normal vector, code 210, 220 & 230 */ - DRW_Vertex2D *vertex; /*!< current vertex to add data */ - std::vector<DRW_Vertex2D *> vertlist; /*!< vertex list */ + std::shared_ptr<DRW_Vertex2D> vertex; /*!< current vertex to add data */ + std::vector<std::shared_ptr<DRW_Vertex2D>> vertlist; /*!< vertex list */ }; //! Class to handle insert entries @@ -807,14 +742,9 @@ public: basePoint.x = basePoint.y = 0.0; flags = vertexcount = facecount = 0; smoothM = smoothN = curvetype = 0; - } - ~DRW_Polyline() { - while (!vertlist.empty()) { - vertlist.pop_back(); - } - } + } void addVertex (DRW_Vertex v) { - DRW_Vertex *vert = new DRW_Vertex(); + std::shared_ptr<DRW_Vertex> vert = std::make_shared<DRW_Vertex>(); vert->basePoint.x = v.basePoint.x; vert->basePoint.y = v.basePoint.y; vert->basePoint.z = v.basePoint.z; @@ -823,7 +753,7 @@ public: vert->bulge = v.bulge; vertlist.push_back(vert); } - void appendVertex (DRW_Vertex *v) { + void appendVertex (std::shared_ptr<DRW_Vertex> const& v) { vertlist.push_back(v); } @@ -841,7 +771,7 @@ public: int smoothN; /*!< smooth surface M density, code 74, default 0 */ int curvetype; /*!< curves & smooth surface type, code 75, default 0 */ - std::vector<DRW_Vertex *> vertlist; /*!< vertex list */ + std::vector<std::shared_ptr<DRW_Vertex>> vertlist; /*!< vertex list */ private: std::list<duint32>hadlesList; //list of handles, only in 2004+ @@ -864,15 +794,7 @@ public: flags = nknots = ncontrol = nfit = 0; tolknot = tolcontrol = tolfit = 0.0000001; - } - ~DRW_Spline() { - while (!controllist.empty()) { - controllist.pop_back(); - } - while (!fitlist.empty()) { - fitlist.pop_back(); - } - } + } virtual void applyExtrusion(){} protected: @@ -902,12 +824,12 @@ public: double tolfit; /*!< fit point tolerance, code 44, default 0.0000001 */ std::vector<double> knotslist; /*!< knots list, code 40 */ - std::vector<DRW_Coord *> controllist; /*!< control points list, code 10, 20 & 30 */ - std::vector<DRW_Coord *> fitlist; /*!< fit points list, code 11, 21 & 31 */ + std::vector<std::shared_ptr<DRW_Coord>> controllist; /*!< control points list, code 10, 20 & 30 */ + std::vector<std::shared_ptr<DRW_Coord>> fitlist; /*!< fit points list, code 11, 21 & 31 */ private: - DRW_Coord *controlpoint; /*!< current control point to add data */ - DRW_Coord *fitpoint; /*!< current fit point to add data */ + std::shared_ptr<DRW_Coord> controlpoint; /*!< current control point to add data */ + std::shared_ptr<DRW_Coord> fitpoint; /*!< current fit point to add data */ }; //! Class to handle hatch loop @@ -922,15 +844,6 @@ public: numedges = 0; } - ~DRW_HatchLoop() { -/* while (!pollist.empty()) { - pollist.pop_back(); - }*/ - while (!objlist.empty()) { - objlist.pop_back(); - } - } - void update() { numedges = objlist.size(); } @@ -940,7 +853,7 @@ public: int numedges; /*!< number of edges (if not a polyline), code 93 */ //TODO: store lwpolylines as entities // std::vector<DRW_LWPolyline *> pollist; /*!< polyline list */ - std::vector<DRW_Entity *> objlist; /*!< entities list */ + std::vector<std::shared_ptr<DRW_Entity>> objlist; /*!< entities list */ }; //! Class to handle hatch entity @@ -959,17 +872,10 @@ public: loopsnum = hstyle = associative = 0; solid = hpattern = 1; deflines = doubleflag = 0; - loop = NULL; clearEntities(); } - ~DRW_Hatch() { - while (!looplist.empty()) { - looplist.pop_back(); - } - } - - void appendLoop (DRW_HatchLoop *v) { + void appendLoop (std::shared_ptr<DRW_HatchLoop> const& v) { looplist.push_back(v); } @@ -991,22 +897,23 @@ public: double scale; /*!< hatch pattern scale, code 41 */ int deflines; /*!< number of pattern definition lines, code 78 */ - std::vector<DRW_HatchLoop *> looplist; /*!< polyline list */ + std::vector<std::shared_ptr<DRW_HatchLoop>> looplist; /*!< polyline list */ private: void clearEntities(){ - pt = line = NULL; - pline = NULL; - arc = NULL; - ellipse = NULL; - spline = NULL; - plvert = NULL; + pt.reset(); + line.reset(); + pline.reset(); + arc.reset(); + ellipse.reset(); + spline.reset(); + plvert.reset(); } void addLine() { clearEntities(); if (loop) { - pt = line = new DRW_Line; + pt = line = std::make_shared<DRW_Line>(); loop->objlist.push_back(line); } } @@ -1014,7 +921,7 @@ private: void addArc() { clearEntities(); if (loop) { - pt = arc = new DRW_Arc; + pt = arc = std::make_shared<DRW_Arc>(); loop->objlist.push_back(arc); } } @@ -1022,7 +929,7 @@ private: void addEllipse() { clearEntities(); if (loop) { - pt = ellipse = new DRW_Ellipse; + pt = ellipse = std::make_shared<DRW_Ellipse>(); loop->objlist.push_back(ellipse); } } @@ -1030,20 +937,20 @@ private: void addSpline() { clearEntities(); if (loop) { - pt = NULL; - spline = new DRW_Spline; + pt.reset(); + spline = std::make_shared<DRW_Spline>(); loop->objlist.push_back(spline); } } - DRW_HatchLoop *loop; /*!< current loop to add data */ - DRW_Line *line; - DRW_Arc *arc; - DRW_Ellipse *ellipse; - DRW_Spline *spline; - DRW_LWPolyline *pline; - DRW_Point *pt; - DRW_Vertex2D *plvert; + std::shared_ptr<DRW_HatchLoop> loop; /*!< current loop to add data */ + std::shared_ptr<DRW_Line> line; + std::shared_ptr<DRW_Arc> arc; + std::shared_ptr<DRW_Ellipse> ellipse; + std::shared_ptr<DRW_Spline> spline; + std::shared_ptr<DRW_LWPolyline> pline; + std::shared_ptr<DRW_Point> pt; + std::shared_ptr<DRW_Vertex2D> plvert; bool ispol; }; @@ -1410,12 +1317,7 @@ public: extrusionPoint.x = extrusionPoint.y = 0.0; arrow = 1; extrusionPoint.z = 1.0; - } - ~DRW_Leader() { - while (!vertexlist.empty()) { - vertexlist.pop_back(); - } - } + } virtual void applyExtrusion(){} @@ -1440,10 +1342,10 @@ public: DRW_Coord offsetblock; /*!< Offset of last leader vertex from block, code 212, 222 & 232 */ DRW_Coord offsettext; /*!< Offset of last leader vertex from annotation, code 213, 223 & 233 */ - std::vector<DRW_Coord *> vertexlist; /*!< vertex points list, code 10, 20 & 30 */ + std::vector<std::shared_ptr<DRW_Coord>> vertexlist; /*!< vertex points list, code 10, 20 & 30 */ private: - DRW_Coord *vertexpoint; /*!< current control point to add data */ + std::shared_ptr<DRW_Coord> vertexpoint; /*!< current control point to add data */ dwgHandle dimStyleH; dwgHandle AnnotH; }; diff -urp libdxfrw-0.6.3/src/drw_header.cpp LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/drw_header.cpp --- libdxfrw-0.6.3/src/drw_header.cpp 2015-10-19 13:02:41.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/drw_header.cpp 2016-06-05 02:27:45.000000000 -0400 @@ -38,84 +38,66 @@ void DRW_Header::parseCode(int code, dxf vars[name]=curr; break; case 1: - curr->addString(reader->getUtf8String()); + curr->addString(code, reader->getUtf8String()); if (name =="$ACADVER") { reader->setVersion(curr->content.s, true); version = reader->getVersion(); } - curr->code = code; break; case 2: - curr->addString(reader->getUtf8String()); - curr->code = code; + curr->addString(code, reader->getUtf8String()); break; case 3: - curr->addString(reader->getUtf8String()); + curr->addString(code, reader->getUtf8String()); if (name =="$DWGCODEPAGE") { reader->setCodePage(curr->content.s); - curr->addString(reader->getCodePage()); + curr->addString(code, reader->getCodePage()); } - curr->code = code; break; case 6: - curr->addString(reader->getUtf8String()); - curr->code = code; + curr->addString(code, reader->getUtf8String()); break; case 7: - curr->addString(reader->getUtf8String()); - curr->code = code; + curr->addString(code, reader->getUtf8String()); break; case 8: - curr->addString(reader->getUtf8String()); - curr->code = code; + curr->addString(code, reader->getUtf8String()); break; case 10: - curr->addCoord(); - curr->setCoordX(reader->getDouble()); - curr->code = code; + curr->addCoord(code, DRW_Coord(reader->getDouble(), 0.0, 0.0)); break; case 20: curr->setCoordY(reader->getDouble()); break; case 30: curr->setCoordZ(reader->getDouble()); - curr->code = code; break; case 40: - curr->addDouble(reader->getDouble()); - curr->code = code; + curr->addDouble(code, reader->getDouble()); break; case 50: - curr->addDouble(reader->getDouble()); - curr->code = code; + curr->addDouble(code, reader->getDouble()); break; case 62: - curr->addInt(reader->getInt32()); - curr->code = code; + curr->addInt(code, reader->getInt32()); break; case 70: - curr->addInt(reader->getInt32()); - curr->code = code; + curr->addInt(code, reader->getInt32()); break; case 280: - curr->addInt(reader->getInt32()); - curr->code = code; + curr->addInt(code, reader->getInt32()); break; case 290: - curr->addInt(reader->getInt32()); - curr->code = code; + curr->addInt(code, reader->getInt32()); break; case 370: - curr->addInt(reader->getInt32()); - curr->code = code; + curr->addInt(code, reader->getInt32()); break; case 380: - curr->addInt(reader->getInt32()); - curr->code = code; + curr->addInt(code, reader->getInt32()); break; case 390: - curr->addString(reader->getUtf8String()); - curr->code = code; + curr->addString(code, reader->getUtf8String()); break; default: break; @@ -1687,30 +1669,22 @@ void DRW_Header::write(dxfWriter *writer } void DRW_Header::addDouble(std::string key, double value, int code){ - curr = new DRW_Variant(); - curr->addDouble( value ); - curr->code = code; + curr = new DRW_Variant(code, value); vars[key] =curr; } void DRW_Header::addInt(std::string key, int value, int code){ - curr = new DRW_Variant(); - curr->addInt( value ); - curr->code = code; + curr = new DRW_Variant(code, value); vars[key] =curr; } void DRW_Header::addStr(std::string key, std::string value, int code){ - curr = new DRW_Variant(); - curr->addString( value ); - curr->code = code; + curr = new DRW_Variant(code, value); vars[key] =curr; } void DRW_Header::addCoord(std::string key, DRW_Coord value, int code){ - curr = new DRW_Variant(); - curr->addCoord( value ); - curr->code = code; + curr = new DRW_Variant(code, value); vars[key] =curr; } @@ -1720,7 +1694,7 @@ bool DRW_Header::getDouble(std::string k it=vars.find( key); if (it != vars.end()) { DRW_Variant *var = (*it).second; - if (var->type == DRW_Variant::DOUBLE) { + if (var->type() == DRW_Variant::DOUBLE) { *varDouble = var->content.d; result = true; } @@ -1736,7 +1710,7 @@ bool DRW_Header::getInt(std::string key, it=vars.find( key); if (it != vars.end()) { DRW_Variant *var = (*it).second; - if (var->type == DRW_Variant::INTEGER) { + if (var->type() == DRW_Variant::INTEGER) { *varInt = var->content.i; result = true; } @@ -1752,7 +1726,7 @@ bool DRW_Header::getStr(std::string key, it=vars.find( key); if (it != vars.end()) { DRW_Variant *var = (*it).second; - if (var->type == DRW_Variant::STRING) { + if (var->type() == DRW_Variant::STRING) { *varStr = *var->content.s; result = true; } @@ -1768,7 +1742,7 @@ bool DRW_Header::getCoord(std::string ke it=vars.find( key); if (it != vars.end()) { DRW_Variant *var = (*it).second; - if (var->type == DRW_Variant::COORD) { + if (var->type() == DRW_Variant::COORD) { *varCoord = *var->content.v; result = true; } @@ -2391,7 +2365,7 @@ bool DRW_Header::parseDwg(DRW::Version v if (DRW_DBGGL == DRW_dbg::DEBUG){ for (std::map<std::string,DRW_Variant*>::iterator it=vars.begin(); it!=vars.end(); ++it){ DRW_DBG("\n"); DRW_DBG(it->first); DRW_DBG(": "); - switch (it->second->type){ + switch (it->second->type()){ case DRW_Variant::INTEGER: DRW_DBG(it->second->content.i); break; @@ -2409,7 +2383,7 @@ bool DRW_Header::parseDwg(DRW::Version v default: break; } - DRW_DBG(" code: ");DRW_DBG(it->second->code); + DRW_DBG(" code: ");DRW_DBG(it->second->code()); } } @@ -2426,8 +2400,9 @@ bool DRW_Header::parseDwg(DRW::Version v } //temporary code to show header end sentinel - duint64 sz= buf->size()-1; - if (version < DRW::AC1018) {//pre 2004 +// duint64 sz= buf->size()-1; + duint64 sz; + if (version < DRW::AC1018) {//pre 2004 sz= buf->size()-16; buf->setPosition(sz); DRW_DBG("\nseting position to: "); DRW_DBG(buf->getPosition()); diff -urp libdxfrw-0.6.3/src/drw_objects.cpp LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/drw_objects.cpp --- libdxfrw-0.6.3/src/drw_objects.cpp 2015-10-19 12:51:28.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/drw_objects.cpp 2016-06-05 02:27:45.000000000 -0400 @@ -50,10 +50,7 @@ void DRW_TableEntry::parseCode(int code, case 1011: case 1012: case 1013: - curr = new DRW_Variant(); - curr->addCoord(); - curr->setCoordX(reader->getDouble()); - curr->code = code; + curr = new DRW_Variant(code, DRW_Coord(reader->getDouble(), 0.0, 0.0)); extData.push_back(curr); break; case 1020: @@ -1170,6 +1167,7 @@ bool DRW_ImageDef::parseDwg(DRW::Version dint32 imgVersion = buf->getBitLong(); DRW_DBG("class Version: "); DRW_DBG(imgVersion); DRW_Coord size = buf->get2RawDouble(); + DRW_UNUSED(size);//RLZ: temporary, complete API name = sBuf->getVariableText(version, false); DRW_DBG("appId name: "); DRW_DBG(name.c_str()); DRW_DBG("\n"); loaded = buf->getBit(); diff -urp libdxfrw-0.6.3/src/intern/dwgbuffer.cpp LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgbuffer.cpp --- libdxfrw-0.6.3/src/intern/dwgbuffer.cpp 2015-07-27 03:15:40.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgbuffer.cpp 2016-06-05 02:27:45.000000000 -0400 @@ -144,22 +144,25 @@ bool dwgCharStream::read(duint8* s, duin return true; } -dwgBuffer::dwgBuffer(duint8 *buf, int size, DRW_TextCodec *dc){ - filestr = new dwgCharStream(buf, size); +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); +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(); +dwgBuffer::dwgBuffer( const dwgBuffer& org ): + filestr{org.filestr->clone()} +{ decoder = org.decoder; maxSize = filestr->size(); currByte = org.currByte; @@ -167,7 +170,7 @@ dwgBuffer::dwgBuffer( const dwgBuffer& o } dwgBuffer& dwgBuffer::operator=( const dwgBuffer& org ){ - filestr = org.filestr->clone(); + filestr.reset(org.filestr->clone()); decoder = org.decoder; maxSize = filestr->size(); currByte = org.currByte; @@ -175,9 +178,7 @@ dwgBuffer& dwgBuffer::operator=( const d return *this; } -dwgBuffer::~dwgBuffer(){ - delete filestr; -} +dwgBuffer::~dwgBuffer() = default; /**Gets the current byte position in buffer **/ duint64 dwgBuffer::getPosition(){ diff -urp libdxfrw-0.6.3/src/intern/dwgbuffer.h LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgbuffer.h --- libdxfrw-0.6.3/src/intern/dwgbuffer.h 2015-07-27 03:15:10.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgbuffer.h 2016-06-05 02:27:45.000000000 -0400 @@ -15,6 +15,7 @@ #include <fstream> #include <sstream> +#include <memory> #include "../drw_base.h" class DRW_Coord; @@ -22,9 +23,9 @@ class DRW_TextCodec; class dwgBasicStream{ protected: - dwgBasicStream(){} + dwgBasicStream() = default; public: - virtual ~dwgBasicStream(){} + virtual ~dwgBasicStream() = default; virtual bool read(duint8* s, duint64 n) = 0; virtual duint64 size() = 0; virtual duint64 getPos() = 0; @@ -61,7 +62,7 @@ public: pos = 0; isOk = true; } - virtual ~dwgCharStream(){} + virtual ~dwgCharStream() = default; virtual bool read(duint8* s, duint64 n); virtual duint64 size(){return sz;} virtual duint64 getPos(){return pos;} @@ -143,7 +144,7 @@ public: DRW_TextCodec *decoder; private: - dwgBasicStream *filestr; + std::unique_ptr<dwgBasicStream> filestr; int maxSize; duint8 currByte; duint8 bitPos; diff -urp libdxfrw-0.6.3/src/intern/dwgreader15.cpp LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader15.cpp --- libdxfrw-0.6.3/src/intern/dwgreader15.cpp 2015-07-23 10:39:11.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader15.cpp 2016-06-05 02:27:45.000000000 -0400 @@ -15,6 +15,9 @@ #include <fstream> #include <string> #include <sstream> +#include <vector> +#include <map> +#include <list> #include "drw_dbg.h" #include "dwgreader15.h" #include "drw_textcodec.h" @@ -24,7 +27,7 @@ bool dwgReader15::readMetaData() { version = parent->getVersion(); decoder.setVersion(version, false); DRW_DBG("dwgReader15::readMetaData\n"); - if (! fileBuf->setPosition(13)) + if (!fileBuf->setPosition(13)) return false; previewImagePos = fileBuf->getRawLong32(); DRW_DBG("previewImagePos (seekerImageData) = "); DRW_DBG(previewImagePos); @@ -106,7 +109,7 @@ bool dwgReader15::readFileHeader() { DRW_DBG("\nfile header crc8 xor result= "); DRW_DBG(ckcrc); DRW_DBG("\nfile header CRC= "); DRW_DBG(fileBuf->getRawShort16()); DRW_DBG("\nfile header sentinel= "); - checkSentinel(fileBuf, secEnum::FILEHEADER, false); + checkSentinel(fileBuf.get(), secEnum::FILEHEADER, false); DRW_DBG("\nposition after read file header sentinel= "); DRW_DBG(fileBuf->getPosition()); DRW_DBG(", bit are= "); DRW_DBG(fileBuf->getBitPos()); @@ -121,14 +124,13 @@ bool dwgReader15::readDwgHeader(DRW_Head if (si.Id<0)//not found, ends return false; if (!fileBuf->setPosition(si.address)) - return false; - duint8 *tmpByteStr = new duint8[si.size]; - fileBuf->getBytes(tmpByteStr, si.size); - dwgBuffer buff(tmpByteStr, si.size, &decoder); + return false; + std::vector<duint8> tmpByteStr(si.size); + fileBuf->getBytes(tmpByteStr.data(), si.size); + dwgBuffer buff(tmpByteStr.data(), si.size, &decoder); DRW_DBG("Header section sentinel= "); checkSentinel(&buff, secEnum::HEADER, true); - bool ret = dwgReader::readDwgHeader(hdr, &buff, &buff); - delete[]tmpByteStr; + bool ret = dwgReader::readDwgHeader(hdr, &buff, &buff); return ret; } @@ -142,16 +144,17 @@ bool dwgReader15::readDwgClasses(){ return false; DRW_DBG("classes section sentinel= "); - checkSentinel(fileBuf, secEnum::CLASSES, true); + checkSentinel(fileBuf.get(), secEnum::CLASSES, true); duint32 size = fileBuf->getRawLong32(); if (size != (si.size - 38)) { DRW_DBG("\nWARNING dwgReader15::readDwgClasses size are "); DRW_DBG(size); DRW_DBG(" and secSize - 38 are "); DRW_DBG(si.size - 38); DRW_DBG("\n"); - } - duint8 *tmpByteStr = new duint8[size]; - fileBuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + } + std::vector<duint8> tmpByteStr(size); + + fileBuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); size--; //reduce 1 byte instead of check pos + bitPos while (size > buff.getPosition()) { DRW_Class *cl = new DRW_Class(); @@ -160,9 +163,8 @@ bool dwgReader15::readDwgClasses(){ } DRW_DBG("\nCRC: "); DRW_DBGH(fileBuf->getRawShort16()); DRW_DBG("\nclasses section end sentinel= "); - checkSentinel(fileBuf, secEnum::CLASSES, false); - bool ret = buff.isGood(); - delete[]tmpByteStr; + checkSentinel(fileBuf.get(), secEnum::CLASSES, false); + bool ret = buff.isGood(); return ret; } @@ -172,7 +174,7 @@ bool dwgReader15::readDwgHandles() { if (si.Id<0)//not found, ends return false; - bool ret = dwgReader::readDwgHandles(fileBuf, si.address, si.size); + bool ret = dwgReader::readDwgHandles(fileBuf.get(), si.address, si.size); return ret; } @@ -182,7 +184,7 @@ bool dwgReader15::readDwgHandles() { * (using their object file offsets) */ bool dwgReader15::readDwgTables(DRW_Header& hdr) { - bool ret = dwgReader::readDwgTables(hdr, fileBuf); + bool ret = dwgReader::readDwgTables(hdr, fileBuf.get()); return ret; } @@ -193,7 +195,7 @@ bool dwgReader15::readDwgTables(DRW_Head */ bool dwgReader15::readDwgBlocks(DRW_Interface& intfa) { bool ret = true; - ret = dwgReader::readDwgBlocks(intfa, fileBuf); + ret = dwgReader::readDwgBlocks(intfa, fileBuf.get()); return ret; } diff -urp libdxfrw-0.6.3/src/intern/dwgreader15.h LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader15.h --- libdxfrw-0.6.3/src/intern/dwgreader15.h 2015-04-09 14:32:22.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader15.h 2016-06-05 02:27:45.000000000 -0400 @@ -13,31 +13,28 @@ #ifndef DWGREADER15_H #define DWGREADER15_H -#include <map> -#include <list> #include "drw_textcodec.h" #include "dwgbuffer.h" #include "dwgreader.h" class dwgReader15 : public dwgReader { public: - dwgReader15(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ } - virtual ~dwgReader15() {} - bool readMetaData(); - bool readFileHeader(); - bool readDwgHeader(DRW_Header& hdr); - bool readDwgClasses(); - bool readDwgHandles(); - bool readDwgTables(DRW_Header& hdr); - bool readDwgBlocks(DRW_Interface& intfa); - bool readDwgEntities(DRW_Interface& intfa){ + dwgReader15(std::ifstream *stream, dwgR *p):dwgReader(stream, p){} + bool readMetaData() override; + bool readFileHeader() override; + bool readDwgHeader(DRW_Header& hdr) override; + bool readDwgClasses() override; + bool readDwgHandles() override; + bool readDwgTables(DRW_Header& hdr) override; + bool readDwgBlocks(DRW_Interface& intfa) override; + bool readDwgEntities(DRW_Interface& intfa) override{ bool ret = true; - ret = dwgReader::readDwgEntities(intfa, fileBuf); + ret = dwgReader::readDwgEntities(intfa, fileBuf.get()); return ret; } - bool readDwgObjects(DRW_Interface& intfa){ + bool readDwgObjects(DRW_Interface& intfa) override{ bool ret = true; - ret = dwgReader::readDwgObjects(intfa, fileBuf); + ret = dwgReader::readDwgObjects(intfa, fileBuf.get()); return ret; } // bool readDwgEntity(objHandle& obj, DRW_Interface& intfa); diff -urp libdxfrw-0.6.3/src/intern/dwgreader18.cpp LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader18.cpp --- libdxfrw-0.6.3/src/intern/dwgreader18.cpp 2015-09-03 12:32:09.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader18.cpp 2016-06-05 02:27:45.000000000 -0400 @@ -15,6 +15,9 @@ #include <fstream> #include <string> #include <sstream> +#include <vector> +#include <map> +#include <list> #include "drw_dbg.h" #include "dwgreader18.h" #include "dwgutil.h" @@ -22,9 +25,9 @@ #include "../libdwgr.h" void dwgReader18::genMagicNumber(){ - int size =0x114; - duint8 *tmpMagicStr = new duint8[size]; - duint8 *p = tmpMagicStr; + int size =0x114; + std::vector<duint8> tmpMagicStr(size); + duint8 *p = tmpMagicStr.data(); int rSeed =1; while (size--) { rSeed *= 0x343fd; @@ -42,8 +45,7 @@ void dwgReader18::genMagicNumber(){ DRW_DBG(", "); j++; } - } - delete[]tmpMagicStr; + } } duint32 dwgReader18::checksum(duint32 seed, duint8* data, duint32 sz){ @@ -79,9 +81,9 @@ void dwgReader18::parseSysPage(duint8 *d hdrData[i]=0; duint32 calcsH = checksum(0, hdrData, 20); DRW_DBG("Calc hdr checksum= "); DRW_DBGH(calcsH); - duint8 *tmpCompSec = new duint8[compSize]; - fileBuf->getBytes(tmpCompSec, compSize); - duint32 calcsD = checksum(calcsH, tmpCompSec, compSize); + std::vector<duint8> tmpCompSec(compSize); + fileBuf->getBytes(tmpCompSec.data(), compSize); + duint32 calcsD = checksum(calcsH, tmpCompSec.data(), compSize); DRW_DBG("\nCalc data checksum= "); DRW_DBGH(calcsD); DRW_DBG("\n"); #ifdef DRW_DBG_DUMP @@ -93,7 +95,7 @@ void dwgReader18::parseSysPage(duint8 *d #endif DRW_DBG("decompresing "); DRW_DBG(compSize); DRW_DBG(" bytes in "); DRW_DBG(decompSize); DRW_DBG(" bytes\n"); dwgCompressor comp; - comp.decompress18(tmpCompSec, decompSec, compSize, decompSize); + comp.decompress18(tmpCompSec.data(), decompSec, compSize, decompSize); #ifdef DRW_DBG_DUMP for (unsigned int i=0, j=0; i< decompSize;i++) { DRW_DBGH( decompSec[i]); @@ -101,13 +103,12 @@ void dwgReader18::parseSysPage(duint8 *d } else { DRW_DBG(", "); j++; } } DRW_DBG("\n"); #endif - delete[]tmpCompSec; } //called ???: Section map: 0x4163003b bool dwgReader18::parseDataPage(dwgSectionInfo si/*, duint8 *dData*/){ DRW_DBG("\nparseDataPage\n "); - objData = new duint8 [si.pageCount * si.maxSize]; + objData.resize(si.pageCount * si.maxSize); for (std::map<duint32, dwgPageInfo>::iterator it=si.pages.begin(); it!=si.pages.end(); ++it){ dwgPageInfo pi = it->second; @@ -147,25 +148,24 @@ bool dwgReader18::parseDataPage(dwgSecti DRW_DBG("\n data checksum= "); DRW_DBGH(bufHdr.getRawLong32()); DRW_DBG("\n"); //get compresed data - duint8 *cData = new duint8[pi.cSize]; + std::vector<duint8> cData(pi.cSize); if (!fileBuf->setPosition(pi.address+32)) return false; - fileBuf->getBytes(cData, pi.cSize); + fileBuf->getBytes(cData.data(), pi.cSize); //calculate checksum - duint32 calcsD = checksum(0, cData, pi.cSize); + duint32 calcsD = checksum(0, cData.data(), pi.cSize); for (duint8 i= 24; i<28; ++i) hdrData[i]=0; duint32 calcsH = checksum(calcsD, hdrData, 32); DRW_DBG("Calc header checksum= "); DRW_DBGH(calcsH); DRW_DBG("\nCalc data checksum= "); DRW_DBGH(calcsD); DRW_DBG("\n"); - duint8* oData = objData + pi.startOffset; + duint8* oData = &objData[pi.startOffset]; pi.uSize = si.maxSize; DRW_DBG("decompresing "); DRW_DBG(pi.cSize); DRW_DBG(" bytes in "); DRW_DBG(pi.uSize); DRW_DBG(" bytes\n"); dwgCompressor comp; - comp.decompress18(cData, oData, pi.cSize, pi.uSize); - delete[]cData; + comp.decompress18(cData.data(), oData, pi.cSize, pi.uSize); } return true; } @@ -301,11 +301,11 @@ bool dwgReader18::readFileHeader() { DRW_DBG("Warning, bad page type, was expected 0x41630e3b instead of"); DRW_DBGH(pageType); DRW_DBG("\n"); return false; } - duint8 *tmpDecompSec = new duint8[decompSize]; - parseSysPage(tmpDecompSec, decompSize); + std::vector<duint8> tmpDecompSec(decompSize); + parseSysPage(tmpDecompSec.data(), decompSize); //parses "Section page map" decompresed data - dwgBuffer buff2(tmpDecompSec, decompSize, &decoder); + dwgBuffer buff2(tmpDecompSec.data(), decompSize, &decoder); duint32 address = 0x100; //stores temporaly info of all pages: std::map<duint32, dwgPageInfo >sectionPageMapTmp; @@ -329,7 +329,6 @@ bool dwgReader18::readFileHeader() { sectionPageMapTmp[id] = dwgPageInfo(id, address, size); address += size; } - delete[]tmpDecompSec; DRW_DBG("\n*** dwgReader18: Processing Data Section Map ***\n"); dwgPageInfo sectionMap = sectionPageMapTmp[secMapId]; @@ -344,12 +343,12 @@ bool dwgReader18::readFileHeader() { DRW_DBG("Warning, bad page type, was expected 0x4163003b instead of"); DRW_DBGH(pageType); DRW_DBG("\n"); return false; } - tmpDecompSec = new duint8[decompSize]; - parseSysPage(tmpDecompSec, decompSize); + tmpDecompSec.resize(decompSize); + parseSysPage(tmpDecompSec.data(), decompSize); //reads sections: DRW_DBG("\n*** dwgReader18: reads sections:"); - dwgBuffer buff3(tmpDecompSec, decompSize, &decoder); + dwgBuffer buff3(tmpDecompSec.data(), decompSize, &decoder); duint32 numDescriptions = buff3.getRawLong32(); DRW_DBG("\nnumDescriptions (sections)= "); DRW_DBG(numDescriptions); DRW_DBG("\n0x02 long= "); DRW_DBGH(buff3.getRawLong32()); @@ -395,8 +394,7 @@ bool dwgReader18::readFileHeader() { DRW_DBG("Saved section Name= "); DRW_DBG( secInfo.name.c_str() ); DRW_DBG("\n"); sections[secEnum::getEnum(secInfo.name)] = secInfo; } - } - delete[]tmpDecompSec; + } if (! fileBuf->isGood()) return false; @@ -413,21 +411,18 @@ bool dwgReader18::readDwgHeader(DRW_Head //global store for uncompressed data of all pages uncompSize=si.size; if (ret) { - dwgBuffer dataBuf(objData, si.size, &decoder); + dwgBuffer dataBuf(objData.data(), si.size, &decoder); DRW_DBG("Header section sentinel= "); checkSentinel(&dataBuf, secEnum::HEADER, true); if (version == DRW::AC1018){ ret = dwgReader::readDwgHeader(hdr, &dataBuf, &dataBuf); } else { - dwgBuffer handleBuf(objData, si.size, &decoder); + dwgBuffer handleBuf(objData.data(), si.size, &decoder); ret = dwgReader::readDwgHeader(hdr, &dataBuf, &handleBuf); } } //Cleanup: global store for uncompressed data of all pages - if (objData != NULL){ - delete[] objData; - objData = NULL; - } + objData.clear(); return ret; } @@ -442,7 +437,7 @@ bool dwgReader18::readDwgClasses(){ uncompSize=si.size; if (ret) { - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); DRW_DBG("classes section sentinel= "); checkSentinel(&dataBuf, secEnum::CLASSES, true); @@ -466,7 +461,7 @@ bool dwgReader18::readDwgClasses(){ /*******************************/ dwgBuffer *strBuf = &dataBuf; - dwgBuffer strBuff(objData, uncompSize, &decoder); + dwgBuffer strBuff(objData.data(), uncompSize, &decoder); //prepare string stream for 2007+ if (version > DRW::AC1021) {//2007+ strBuf = &strBuff; @@ -529,10 +524,7 @@ bool dwgReader18::readDwgClasses(){ ret = strBuf->isGood(); } //Cleanup: global store for uncompressed data of all pages - if (objData != NULL){ - delete[] objData; - objData = NULL; - } + objData.clear(); return ret; } @@ -553,17 +545,12 @@ bool dwgReader18::readDwgHandles() { //global store for uncompressed data of all pages uncompSize=si.size; if (ret) { - - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); ret = dwgReader::readDwgHandles(&dataBuf, 0, si.size); } //Cleanup: global store for uncompressed data of all pages - if (objData != NULL){ - delete[] objData; - objData = NULL; - uncompSize = 0; - } + objData.clear(); return ret; } @@ -584,7 +571,7 @@ bool dwgReader18::readDwgTables(DRW_Head uncompSize=si.size; if (ret) { - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); ret = dwgReader::readDwgTables(hdr, &dataBuf); diff -urp libdxfrw-0.6.3/src/intern/dwgreader18.h LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader18.h --- libdxfrw-0.6.3/src/intern/dwgreader18.h 2015-07-23 10:30:08.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader18.h 2016-06-05 02:27:45.000000000 -0400 @@ -13,8 +13,6 @@ #ifndef DWGREADER18_H #define DWGREADER18_H -#include <map> -#include <list> #include "dwgreader.h" //#include "../drw_textcodec.h" #include "dwgbuffer.h" @@ -43,35 +41,30 @@ static const int DRW_magicNumEnd18[] = { class dwgReader18 : public dwgReader { public: - dwgReader18(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ - objData = NULL; - } - virtual ~dwgReader18(){ - if (objData != NULL) - delete[] objData; - } - bool readMetaData(); - bool readFileHeader(); - bool readDwgHeader(DRW_Header& hdr); - bool readDwgClasses(); - bool readDwgHandles(); - bool readDwgTables(DRW_Header& hdr); - bool readDwgBlocks(DRW_Interface& intfa){ + dwgReader18(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ + } + bool readMetaData() override; + bool readFileHeader() override; + bool readDwgHeader(DRW_Header& hdr) override; + bool readDwgClasses() override; + bool readDwgHandles() override; + bool readDwgTables(DRW_Header& hdr) override; + bool readDwgBlocks(DRW_Interface& intfa) override{ bool ret = true; - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); ret = dwgReader::readDwgBlocks(intfa, &dataBuf); return ret; } - virtual bool readDwgEntities(DRW_Interface& intfa){ + virtual bool readDwgEntities(DRW_Interface& intfa) override{ bool ret = true; - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); ret = dwgReader::readDwgEntities(intfa, &dataBuf); return ret; } - virtual bool readDwgObjects(DRW_Interface& intfa){ + virtual bool readDwgObjects(DRW_Interface& intfa) override{ bool ret = true; - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); ret = dwgReader::readDwgObjects(intfa, &dataBuf); return ret; } @@ -82,7 +75,7 @@ public: // } protected: - duint8 *objData; + std::vector<duint8> objData; duint64 uncompSize; private: diff -urp libdxfrw-0.6.3/src/intern/dwgreader21.cpp LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader21.cpp --- libdxfrw-0.6.3/src/intern/dwgreader21.cpp 2015-07-23 10:39:11.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader21.cpp 2016-06-05 02:27:45.000000000 -0400 @@ -15,6 +15,8 @@ #include <fstream> #include <string> #include <sstream> +#include <map> +#include <vector> #include "drw_dbg.h" #include "dwgreader21.h" #include "drw_textcodec.h" @@ -63,14 +65,12 @@ bool dwgReader21::parseSysPage(duint64 s duint64 fpsize = chunks * 255; if (! fileBuf->setPosition(offset)) - return false; - duint8 *tmpDataRaw = new duint8[fpsize]; - fileBuf->getBytes(tmpDataRaw, fpsize); - duint8 *tmpDataRS = new duint8[fpsize]; - dwgRSCodec::decode239I(tmpDataRaw, tmpDataRS, fpsize/255); - dwgCompressor::decompress21(tmpDataRS, decompData, sizeCompressed, sizeUncompressed); - delete[]tmpDataRaw; - delete[]tmpDataRS; + return false; + std::vector<duint8> tmpDataRaw(fpsize); + fileBuf->getBytes(&tmpDataRaw.front(), fpsize); + std::vector<duint8> tmpDataRS(fpsize); + dwgRSCodec::decode239I(&tmpDataRaw.front(), &tmpDataRS.front(), fpsize/255); + dwgCompressor::decompress21(&tmpDataRS.front(), decompData, sizeCompressed, sizeUncompressed); return true; } @@ -81,8 +81,8 @@ bool dwgReader21::parseDataPage(dwgSecti if (!fileBuf->setPosition(pi.address)) return false; - duint8 *tmpPageRaw = new duint8[pi.size]; - fileBuf->getBytes(tmpPageRaw, pi.size); + std::vector<duint8> tmpPageRaw(pi.size); + fileBuf->getBytes(&tmpPageRaw.front(), pi.size); #ifdef DRW_DBG_DUMP DRW_DBG("\nSection OBJECTS raw data=\n"); for (unsigned int i=0, j=0; i< pi.size;i++) { @@ -92,9 +92,10 @@ bool dwgReader21::parseDataPage(dwgSecti } DRW_DBG("\n"); #endif - duint8 *tmpPageRS = new duint8[pi.size]; + std::vector<duint8> tmpPageRS(pi.size); + duint8 chunks =pi.size / 255; - dwgRSCodec::decode251I(tmpPageRaw, tmpPageRS, chunks); + dwgRSCodec::decode251I(&tmpPageRaw.front(), &tmpPageRS.front(), chunks); #ifdef DRW_DBG_DUMP DRW_DBG("\nSection OBJECTS RS data=\n"); for (unsigned int i=0, j=0; i< pi.size;i++) { @@ -107,7 +108,7 @@ bool dwgReader21::parseDataPage(dwgSecti DRW_DBG("\npage uncomp size: "); DRW_DBG(pi.uSize); DRW_DBG(" comp size: "); DRW_DBG(pi.cSize); DRW_DBG("\noffset: "); DRW_DBG(pi.startOffset); duint8 *pageData = dData + pi.startOffset; - dwgCompressor::decompress21(tmpPageRS, pageData, pi.cSize, pi.uSize); + dwgCompressor::decompress21(&tmpPageRS.front(), pageData, pi.cSize, pi.uSize); #ifdef DRW_DBG_DUMP DRW_DBG("\n\nSection OBJECTS decompresed data=\n"); @@ -118,8 +119,6 @@ bool dwgReader21::parseDataPage(dwgSecti } DRW_DBG("\n"); #endif - delete[]tmpPageRaw; - delete[]tmpPageRS; } DRW_DBG("\n"); return true; @@ -155,18 +154,18 @@ bool dwgReader21::readFileHeader() { DRW_DBG("\nlength2 4bytes= "); DRW_DBG(fileHdrCompLength2); int fileHdrDataLength = 0x110; - duint8 *fileHdrData; + std::vector<duint8> fileHdrData; if (fileHdrCompLength < 0) { fileHdrDataLength = fileHdrCompLength * -1; - fileHdrData = new duint8[fileHdrDataLength]; - fileHdrBuf.getBytes(fileHdrData, fileHdrDataLength); + fileHdrData.resize(fileHdrDataLength); + fileHdrBuf.getBytes(&fileHdrData.front(), fileHdrDataLength); }else { DRW_DBG("\ndwgReader21:: file header are compresed:\n"); - duint8 *compByteStr = new duint8[fileHdrCompLength]; - fileHdrBuf.getBytes(compByteStr, fileHdrCompLength); - fileHdrData = new duint8[fileHdrDataLength]; - dwgCompressor::decompress21(compByteStr, fileHdrData, fileHdrCompLength, fileHdrDataLength); - delete[] compByteStr; + std::vector<duint8> compByteStr(fileHdrCompLength); + fileHdrBuf.getBytes(compByteStr.data(), fileHdrCompLength); + fileHdrData.resize(fileHdrDataLength); + dwgCompressor::decompress21(compByteStr.data(), &fileHdrData.front(), + fileHdrCompLength, fileHdrDataLength); } #ifdef DRW_DBG_DUMP @@ -178,7 +177,7 @@ bool dwgReader21::readFileHeader() { } DRW_DBG("\n"); #endif - dwgBuffer fileHdrDataBuf(fileHdrData, fileHdrDataLength, &decoder); + dwgBuffer fileHdrDataBuf(&fileHdrData.front(), fileHdrDataLength, &decoder); DRW_DBG("\nHeader size = "); DRW_DBGH(fileHdrDataBuf.getRawLong64()); DRW_DBG("\nFile size = "); DRW_DBGH(fileHdrDataBuf.getRawLong64()); DRW_DBG("\nPagesMapCrcCompressed = "); DRW_DBGH(fileHdrDataBuf.getRawLong64()); @@ -223,20 +222,19 @@ bool dwgReader21::readFileHeader() { DRW_DBG("\nRandomSeed = "); DRW_DBGH(fileHdrDataBuf.getRawLong64()); DRW_DBG("\nHeader CRC64 = "); DRW_DBGH(fileHdrDataBuf.getRawLong64()); DRW_DBG("\n"); - delete[] fileHdrData; - DRW_DBG("\ndwgReader21::parse page map:\n"); - duint8 *PagesMapData = new duint8[PagesMapSizeUncompressed]; + DRW_DBG("\ndwgReader21::parse page map:\n"); + std::vector<duint8> PagesMapData(PagesMapSizeUncompressed); - bool ret = parseSysPage(PagesMapSizeCompressed, PagesMapSizeUncompressed, PagesMapCorrectionFactor, 0x480+PagesMapOffset, PagesMapData); - if (!ret) { - delete[]PagesMapData; - return false; - } + bool ret = parseSysPage(PagesMapSizeCompressed, PagesMapSizeUncompressed, + PagesMapCorrectionFactor, 0x480+PagesMapOffset, + &PagesMapData.front()); + if (!ret) + return false; duint64 address = 0x480; duint64 i = 0; - dwgBuffer PagesMapBuf(PagesMapData, PagesMapSizeUncompressed, &decoder); + dwgBuffer PagesMapBuf(&PagesMapData.front(), PagesMapSizeUncompressed, &decoder); //stores temporaly info of all pages: std::map<duint32, dwgPageInfo >sectionPageMapTmp; @@ -254,19 +252,19 @@ bool dwgReader21::readFileHeader() { //TODO num can be negative indicating gap // seek += offset; } - delete[]PagesMapData; DRW_DBG("\n*** dwgReader21: Processing Section Map ***\n"); - duint8 *SectionsMapData = new duint8[SectionsMapSizeUncompressed]; + std::vector<duint8> SectionsMapData(SectionsMapSizeUncompressed); dwgPageInfo sectionMap = sectionPageMapTmp[SectionsMapId]; - ret = parseSysPage(SectionsMapSizeCompressed, SectionsMapSizeUncompressed, SectionsMapCorrectionFactor, sectionMap.address, SectionsMapData); - if (!ret) + ret = parseSysPage(SectionsMapSizeCompressed, SectionsMapSizeUncompressed, + SectionsMapCorrectionFactor, sectionMap.address, &SectionsMapData.front()); + if (!ret) return false; //reads sections: //Note: compressed value are not stored in file then, commpresed field are use to store // encoding value - dwgBuffer SectionsMapBuf(SectionsMapData, SectionsMapSizeUncompressed, &decoder); + dwgBuffer SectionsMapBuf(&SectionsMapData.front(), SectionsMapSizeUncompressed, &decoder); duint8 nextId =1; while(SectionsMapBuf.getPosition() < SectionsMapBuf.size()){ dwgSectionInfo secInfo; @@ -317,7 +315,6 @@ bool dwgReader21::readFileHeader() { sections[secEnum::getEnum(secInfo.name)] = secInfo; } } - delete[]SectionsMapData; if (! fileBuf->isGood()) return false; @@ -331,20 +328,18 @@ bool dwgReader21::readDwgHeader(DRW_Head dwgSectionInfo si = sections[secEnum::HEADER]; if (si.Id<0)//not found, ends return false; - DRW_DBG("\nprepare section of size "); DRW_DBG(si.size);DRW_DBG("\n"); - duint8 *tmpHeaderData = new duint8[si.size]; - bool ret = dwgReader21::parseDataPage(si, tmpHeaderData); - if (!ret) { - delete[]tmpHeaderData; + DRW_DBG("\nprepare section of size "); DRW_DBG(si.size);DRW_DBG("\n"); + std::vector<duint8> tmpHeaderData(si.size); + + bool ret = dwgReader21::parseDataPage(si, &tmpHeaderData.front()); + if (!ret) return ret; - } - dwgBuffer dataBuf(tmpHeaderData, si.size, &decoder); - dwgBuffer handleBuf(tmpHeaderData, si.size, &decoder); + dwgBuffer dataBuf(&tmpHeaderData.front(), si.size, &decoder); + dwgBuffer handleBuf(&tmpHeaderData.front(), si.size, &decoder); DRW_DBG("Header section sentinel= "); checkSentinel(&dataBuf, secEnum::HEADER, true); ret = dwgReader::readDwgHeader(hdr, &dataBuf, &handleBuf); - delete[]tmpHeaderData; return ret; } @@ -355,12 +350,12 @@ bool dwgReader21::readDwgClasses(){ return false; DRW_DBG("\nprepare section of size "); DRW_DBG(si.size);DRW_DBG("\n"); - duint8 *tmpClassesData = new duint8[si.size]; - bool ret = dwgReader21::parseDataPage(si, tmpClassesData); + std::vector<duint8> tmpClassesData(si.size); + bool ret = dwgReader21::parseDataPage(si, tmpClassesData.data()); if (!ret) return ret; - dwgBuffer buff(tmpClassesData, si.size, &decoder); + dwgBuffer buff(tmpClassesData.data(), si.size, &decoder); DRW_DBG("classes section sentinel= "); checkSentinel(&buff, secEnum::CLASSES, true); @@ -378,7 +373,7 @@ bool dwgReader21::readDwgClasses(){ /*******************************/ //prepare string stream - dwgBuffer strBuff(tmpClassesData, si.size, &decoder); + dwgBuffer strBuff(tmpClassesData.data(), si.size, &decoder); duint32 strStartPos = bitSize + 159;//size in bits + 20 bytes (sn+size) - 1 bit (endbit) DRW_DBG("\nstrStartPos: "); DRW_DBG(strStartPos); strBuff.setPosition(strStartPos >> 3); @@ -426,8 +421,7 @@ bool dwgReader21::readDwgClasses(){ buff.setPosition(size+20);//sizeVal+sn+32bSize DRW_DBG("\nCRC: "); DRW_DBGH(buff.getRawShort16()); DRW_DBG("\nclasses section end sentinel= "); - checkSentinel(&buff, secEnum::CLASSES, true); - delete[]tmpClassesData; + checkSentinel(&buff, secEnum::CLASSES, true); return buff.isGood(); } @@ -439,15 +433,14 @@ bool dwgReader21::readDwgHandles(){ return false; DRW_DBG("\nprepare section of size "); DRW_DBG(si.size);DRW_DBG("\n"); - duint8 *tmpHandlesData = new duint8[si.size]; - bool ret = dwgReader21::parseDataPage(si, tmpHandlesData); + std::vector<duint8> tmpHandlesData(si.size); + bool ret = dwgReader21::parseDataPage(si, tmpHandlesData.data()); if (!ret) return ret; - dwgBuffer dataBuf(tmpHandlesData, si.size, &decoder); + dwgBuffer dataBuf(tmpHandlesData.data(), si.size, &decoder); ret = dwgReader::readDwgHandles(&dataBuf, 0, si.size); - delete[]tmpHandlesData; return ret; } @@ -464,13 +457,13 @@ bool dwgReader21::readDwgTables(DRW_Head DRW_DBG("\nprepare section of size "); DRW_DBG(si.size);DRW_DBG("\n"); dataSize = si.size; - objData = new duint8 [dataSize]; - bool ret = dwgReader21::parseDataPage(si, objData); + objData.resize(dataSize); + bool ret = dwgReader21::parseDataPage(si, objData.data()); if (!ret) return ret; DRW_DBG("readDwgTables total data size= "); DRW_DBG(dataSize); DRW_DBG("\n"); - dwgBuffer dataBuf(objData, dataSize, &decoder); + dwgBuffer dataBuf(objData.data(), dataSize, &decoder); ret = dwgReader::readDwgTables(hdr, &dataBuf); return ret; @@ -479,7 +472,7 @@ bool dwgReader21::readDwgTables(DRW_Head bool dwgReader21::readDwgBlocks(DRW_Interface& intfa){ bool ret = true; - dwgBuffer dataBuf(objData, dataSize, &decoder); + dwgBuffer dataBuf(objData.data(), dataSize, &decoder); ret = dwgReader::readDwgBlocks(intfa, &dataBuf); return ret; diff -urp libdxfrw-0.6.3/src/intern/dwgreader21.h LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader21.h --- libdxfrw-0.6.3/src/intern/dwgreader21.h 2015-07-23 10:30:08.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader21.h 2016-06-05 02:27:45.000000000 -0400 @@ -13,8 +13,7 @@ #ifndef DWGREADER21_H #define DWGREADER21_H -#include <map> -#include <list> +#include <vector> #include "drw_textcodec.h" #include "dwgbuffer.h" #include "dwgreader.h" @@ -23,29 +22,23 @@ class dwgReader21 : public dwgReader { public: dwgReader21(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ - objData = NULL; - dataSize = 0; - } - virtual ~dwgReader21(){ - if (objData != NULL) - delete[] objData; - } - bool readMetaData(); - bool readFileHeader(); - bool readDwgHeader(DRW_Header& hdr); - bool readDwgClasses(); - bool readDwgHandles(); - bool readDwgTables(DRW_Header& hdr); - bool readDwgBlocks(DRW_Interface& intfa); - virtual bool readDwgEntities(DRW_Interface& intfa){ + } + bool readMetaData() override; + bool readFileHeader() override; + bool readDwgHeader(DRW_Header& hdr) override; + bool readDwgClasses() override; + bool readDwgHandles() override; + bool readDwgTables(DRW_Header& hdr) override; + bool readDwgBlocks(DRW_Interface& intfa) override; + virtual bool readDwgEntities(DRW_Interface& intfa) override{ bool ret = true; - dwgBuffer dataBuf(objData, dataSize, &decoder); + dwgBuffer dataBuf(&objData.front(), dataSize, &decoder); ret = dwgReader::readDwgEntities(intfa, &dataBuf); return ret; } - virtual bool readDwgObjects(DRW_Interface& intfa){ + virtual bool readDwgObjects(DRW_Interface& intfa) override{ bool ret = true; - dwgBuffer dataBuf(objData, dataSize, &decoder); + dwgBuffer dataBuf(&objData.front(), dataSize, &decoder); ret = dwgReader::readDwgObjects(intfa, &dataBuf); return ret; } @@ -57,8 +50,8 @@ private: bool parseSysPage(duint64 sizeCompressed, duint64 sizeUncompressed, duint64 correctionFactor, duint64 offset, duint8 *decompData); bool parseDataPage(dwgSectionInfo si, duint8 *dData); - duint8 *objData; - duint64 dataSize; + std::vector<duint8> objData; + duint64 dataSize = 0; }; diff -urp libdxfrw-0.6.3/src/intern/dwgreader24.h LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader24.h --- libdxfrw-0.6.3/src/intern/dwgreader24.h 2015-07-23 10:30:08.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader24.h 2016-06-05 02:27:45.000000000 -0400 @@ -22,27 +22,26 @@ class dwgReader24 : public dwgReader18 { public: dwgReader24(std::ifstream *stream, dwgR *p):dwgReader18(stream, p){ } - virtual ~dwgReader24(){} - bool readFileHeader(); - bool readDwgHeader(DRW_Header& hdr); - bool readDwgClasses(); + bool readFileHeader() override; + bool readDwgHeader(DRW_Header& hdr) override; + bool readDwgClasses() override; // bool readDwgHandles(){return false;} // bool readDwgTables(){return false;} - bool readDwgBlocks(DRW_Interface& intfa){ + bool readDwgBlocks(DRW_Interface& intfa) override{ bool ret = true; - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); ret = dwgReader::readDwgBlocks(intfa, &dataBuf); return ret; } - virtual bool readDwgEntities(DRW_Interface& intfa){ + virtual bool readDwgEntities(DRW_Interface& intfa) override{ bool ret = true; - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); ret = dwgReader::readDwgEntities(intfa, &dataBuf); return ret; } - virtual bool readDwgObjects(DRW_Interface& intfa){ + virtual bool readDwgObjects(DRW_Interface& intfa) override{ bool ret = true; - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); ret = dwgReader::readDwgObjects(intfa, &dataBuf); return ret; } diff -urp libdxfrw-0.6.3/src/intern/dwgreader27.h LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader27.h --- libdxfrw-0.6.3/src/intern/dwgreader27.h 2015-07-23 10:30:08.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader27.h 2016-06-05 02:27:45.000000000 -0400 @@ -22,27 +22,26 @@ class dwgReader27 : public dwgReader18 { public: dwgReader27(std::ifstream *stream, dwgR *p):dwgReader18(stream, p){ } - virtual ~dwgReader27(){} - bool readFileHeader(); - bool readDwgHeader(DRW_Header& hdr); - bool readDwgClasses(); + bool readFileHeader() override; + bool readDwgHeader(DRW_Header& hdr) override; + bool readDwgClasses() override; // bool readDwgHandles(){return false;} // bool readDwgTables(){return false;} - bool readDwgBlocks(DRW_Interface& intfa){ + bool readDwgBlocks(DRW_Interface& intfa) override{ bool ret = true; - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); ret = dwgReader::readDwgBlocks(intfa, &dataBuf); return ret; } - virtual bool readDwgEntities(DRW_Interface& intfa){ + virtual bool readDwgEntities(DRW_Interface& intfa) override{ bool ret = true; - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); ret = dwgReader::readDwgEntities(intfa, &dataBuf); return ret; } - virtual bool readDwgObjects(DRW_Interface& intfa){ + virtual bool readDwgObjects(DRW_Interface& intfa) override{ bool ret = true; - dwgBuffer dataBuf(objData, uncompSize, &decoder); + dwgBuffer dataBuf(objData.data(), uncompSize, &decoder); ret = dwgReader::readDwgObjects(intfa, &dataBuf); return ret; } diff -urp libdxfrw-0.6.3/src/intern/dwgreader.cpp LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader.cpp --- libdxfrw-0.6.3/src/intern/dwgreader.cpp 2015-10-19 13:28:08.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader.cpp 2016-06-05 02:27:45.000000000 -0400 @@ -15,46 +15,44 @@ #include <fstream> #include <string> #include <sstream> +#include <map> #include "dwgreader.h" #include "drw_textcodec.h" #include "drw_dbg.h" +namespace { +//helper function to cleanup pointers in Look Up Tables +template<typename T> +void mapCleanUp(std::map<duint32, T*>& table) +{ + for (auto& item: table) + delete item.second; +} +} dwgReader::~dwgReader(){ - for (std::map<duint32, DRW_LType*>::iterator it=ltypemap.begin(); it!=ltypemap.end(); ++it) - delete(it->second); - for (std::map<duint32, DRW_Layer*>::iterator it=layermap.begin(); it!=layermap.end(); ++it) - delete(it->second); - for (std::map<duint32, DRW_Block*>::iterator it=blockmap.begin(); it!=blockmap.end(); ++it) - delete(it->second); - for (std::map<duint32, DRW_Textstyle*>::iterator it=stylemap.begin(); it!=stylemap.end(); ++it) - delete(it->second); - for (std::map<duint32, DRW_Dimstyle*>::iterator it=dimstylemap.begin(); it!=dimstylemap.end(); ++it) - delete(it->second); - for (std::map<duint32, DRW_Vport*>::iterator it=vportmap.begin(); it!=vportmap.end(); ++it) - delete(it->second); - for (std::map<duint32, DRW_Class*>::iterator it=classesmap.begin(); it!=classesmap.end(); ++it) - delete(it->second); - for (std::map<duint32, DRW_Block_Record*>::iterator it=blockRecordmap.begin(); it!=blockRecordmap.end(); ++it) - delete(it->second); - for (std::map<duint32, DRW_AppId*>::iterator it=appIdmap.begin(); it!=appIdmap.end(); ++it) - delete(it->second); - - delete fileBuf; + mapCleanUp(ltypemap); + mapCleanUp(layermap); + mapCleanUp(blockmap); + mapCleanUp(stylemap); + mapCleanUp(dimstylemap); + mapCleanUp(vportmap); + mapCleanUp(classesmap); + mapCleanUp(blockRecordmap); + mapCleanUp(appIdmap); } void dwgReader::parseAttribs(DRW_Entity* e){ - if (e != NULL){ - duint32 ltref =e->lTypeH.ref; - duint32 lyref =e->layerH.ref; - std::map<duint32, DRW_LType*>::iterator lt_it = ltypemap.find(ltref); - if (lt_it != ltypemap.end()){ - e->lineType = (lt_it->second)->name; - } - std::map<duint32, DRW_Layer*>::iterator ly_it = layermap.find(lyref); - if (ly_it != layermap.end()){ - e->layer = (ly_it->second)->name; - } - } + if (!e) return; + duint32 ltref =e->lTypeH.ref; + duint32 lyref =e->layerH.ref; + std::map<duint32, DRW_LType*>::iterator lt_it = ltypemap.find(ltref); + if (lt_it != ltypemap.end()){ + e->lineType = (lt_it->second)->name; + } + std::map<duint32, DRW_Layer*>::iterator ly_it = layermap.find(lyref); + if (ly_it != layermap.end()){ + e->layer = (ly_it->second)->name; + } } std::string dwgReader::findTableName(DRW::TTYPE table, dint32 handle){ @@ -98,14 +96,14 @@ std::string dwgReader::findTableName(DRW return name; } -bool dwgReader::readDwgHeader(DRW_Header& hdr, dwgBuffer *buf, dwgBuffer *hBuf){ +bool dwgReader::readDwgHeader(DRW_Header& hdr, dwgBuffer* buf, dwgBuffer* hBuf){ bool ret = hdr.parseDwg(version, buf, hBuf, maintenanceVersion); //RLZ: copy objectControl handles return ret; } //RLZ: TODO add check instead print -bool dwgReader::checkSentinel(dwgBuffer *buf, enum secEnum::DWGSection, bool start){ +bool dwgReader::checkSentinel(dwgBuffer* buf, enum secEnum::DWGSection, bool start){ DRW_UNUSED(start); for (int i=0; i<16;i++) { DRW_DBGH(buf->getRawChar8()); DRW_DBG(" "); @@ -120,7 +118,7 @@ bool dwgReader::checkSentinel(dwgBuffer * 2 bytes size + data bytes * last section are 2 bytes size + 2 bytes crc (size value always 2) **/ -bool dwgReader::readDwgHandles(dwgBuffer *dbuf, duint32 offset, duint32 size) { +bool dwgReader::readDwgHandles(dwgBuffer* dbuf, duint32 offset, duint32 size) { DRW_DBG("\ndwgReader::readDwgHandles\n"); if (!dbuf->setPosition(offset)) return false; @@ -132,14 +130,15 @@ bool dwgReader::readDwgHandles(dwgBuffer int startPos = offset; - while (maxPos > dbuf->getPosition()) { + std::vector<duint8> tmpByteStr; + while (maxPos > dbuf->getPosition()) { DRW_DBG("\nstart handles section buf->curPosition()= "); DRW_DBG(dbuf->getPosition()); DRW_DBG("\n"); duint16 size = dbuf->getBERawShort16(); DRW_DBG("object map section size= "); DRW_DBG(size); DRW_DBG("\n"); dbuf->setPosition(startPos); - duint8 *tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); if (size != 2){ buff.setPosition(2); int lastHandle = 0; @@ -155,7 +154,6 @@ bool dwgReader::readDwgHandles(dwgBuffer } //verify crc duint16 crcCalc = buff.crc8(0xc0c1,0,size); - delete[]tmpByteStr; duint16 crcRead = dbuf->getBERawShort16(); DRW_DBG("object map section crc8 read= "); DRW_DBG(crcRead); DRW_DBG("\nobject map section crc8 calculated= "); DRW_DBG(crcCalc); @@ -172,7 +170,7 @@ bool dwgReader::readDwgHandles(dwgBuffer * Reads all the object referenced in the object map section of the DWG file * (using their object file offsets) */ -bool dwgReader::readDwgTables(DRW_Header& hdr, dwgBuffer *dbuf) { +bool dwgReader::readDwgTables(DRW_Header& hdr, dwgBuffer* dbuf) { DRW_DBG("\ndwgReader::readDwgTables start\n"); bool ret = true; bool ret2 = true; @@ -180,7 +178,7 @@ bool dwgReader::readDwgTables(DRW_Header std::map<duint32, objHandle>::iterator mit; dint16 oType; duint32 bs = 0; //bit size of handle stream 2010+ - duint8 *tmpByteStr; + std::vector<duint8> tmpByteStr; //parse linetypes, start with linetype Control mit = ObjectMap.find(hdr.linetypeCtrl); @@ -198,9 +196,9 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[csize]; - dbuf->getBytes(tmpByteStr, csize); - dwgBuffer cbuff(tmpByteStr, csize, &decoder); + tmpByteStr.resize(csize); + dbuf->getBytes(tmpByteStr.data(), csize); + dwgBuffer cbuff(tmpByteStr.data(), csize, &decoder); //verify if object are correct oType = cbuff.getObjType(version); if (oType != 0x38) { @@ -213,7 +211,6 @@ bool dwgReader::readDwgTables(DRW_Header if(ret) ret = ret2; } - delete[]tmpByteStr; for (std::list<duint32>::iterator it=ltControl.hadlesList.begin(); it != ltControl.hadlesList.end(); ++it){ mit = ObjectMap.find(*it); if (mit==ObjectMap.end()) { @@ -231,14 +228,13 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[lsize]; - dbuf->getBytes(tmpByteStr, lsize); - dwgBuffer lbuff(tmpByteStr, lsize, &decoder); + tmpByteStr.resize(lsize); + dbuf->getBytes(tmpByteStr.data(), lsize); + dwgBuffer lbuff(tmpByteStr.data(), lsize, &decoder); ret2 = lt->parseDwg(version, &lbuff, bs); ltypemap[lt->handle] = lt; if(ret) ret = ret2; - delete[]tmpByteStr; } } } @@ -259,9 +255,9 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); //verify if object are correct oType = buff.getObjType(version); if (oType != 0x32) { @@ -274,7 +270,6 @@ bool dwgReader::readDwgTables(DRW_Header if(ret) ret = ret2; } - delete[]tmpByteStr; for (std::list<duint32>::iterator it=layControl.hadlesList.begin(); it != layControl.hadlesList.end(); ++it){ mit = ObjectMap.find(*it); if (mit==ObjectMap.end()) { @@ -291,14 +286,13 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); ret2 = la->parseDwg(version, &buff, bs); layermap[la->handle] = la; if(ret) - ret = ret2; - delete[]tmpByteStr; + ret = ret2; } } } @@ -329,9 +323,9 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); //verify if object are correct oType = buff.getObjType(version); if (oType != 0x34) { @@ -344,7 +338,6 @@ bool dwgReader::readDwgTables(DRW_Header if(ret) ret = ret2; } - delete[]tmpByteStr; for (std::list<duint32>::iterator it=styControl.hadlesList.begin(); it != styControl.hadlesList.end(); ++it){ mit = ObjectMap.find(*it); if (mit==ObjectMap.end()) { @@ -361,14 +354,13 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); ret2 = sty->parseDwg(version, &buff, bs); stylemap[sty->handle] = sty; if(ret) - ret = ret2; - delete[]tmpByteStr; + ret = ret2; } } } @@ -389,9 +381,9 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); //verify if object are correct oType = buff.getObjType(version); if (oType != 0x44) { @@ -404,7 +396,6 @@ bool dwgReader::readDwgTables(DRW_Header if(ret) ret = ret2; } - delete[]tmpByteStr; for (std::list<duint32>::iterator it=dimstyControl.hadlesList.begin(); it != dimstyControl.hadlesList.end(); ++it){ mit = ObjectMap.find(*it); if (mit==ObjectMap.end()) { @@ -421,14 +412,13 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); ret2 = sty->parseDwg(version, &buff, bs); dimstylemap[sty->handle] = sty; if(ret) - ret = ret2; - delete[]tmpByteStr; + ret = ret2; } } } @@ -449,9 +439,9 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); //verify if object are correct oType = buff.getObjType(version); if (oType != 0x40) { @@ -464,7 +454,6 @@ bool dwgReader::readDwgTables(DRW_Header if(ret) ret = ret2; } - delete[]tmpByteStr; for (std::list<duint32>::iterator it=vportControl.hadlesList.begin(); it != vportControl.hadlesList.end(); ++it){ mit = ObjectMap.find(*it); if (mit==ObjectMap.end()) { @@ -481,14 +470,13 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); ret2 = vp->parseDwg(version, &buff, bs); vportmap[vp->handle] = vp; if(ret) - ret = ret2; - delete[]tmpByteStr; + ret = ret2; } } } @@ -509,9 +497,9 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[csize]; - dbuf->getBytes(tmpByteStr, csize); - dwgBuffer buff(tmpByteStr, csize, &decoder); + tmpByteStr.resize(csize); + dbuf->getBytes(tmpByteStr.data(), csize); + dwgBuffer buff(tmpByteStr.data(), csize, &decoder); //verify if object are correct oType = buff.getObjType(version); if (oType != 0x30) { @@ -523,8 +511,7 @@ bool dwgReader::readDwgTables(DRW_Header ret2 = blockControl.parseDwg(version, &buff, bs); if(ret) ret = ret2; - } - delete[]tmpByteStr; + } for (std::list<duint32>::iterator it=blockControl.hadlesList.begin(); it != blockControl.hadlesList.end(); ++it){ mit = ObjectMap.find(*it); if (mit==ObjectMap.end()) { @@ -541,14 +528,13 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); ret2 = br->parseDwg(version, &buff, bs); blockRecordmap[br->handle] = br; if(ret) - ret = ret2; - delete[]tmpByteStr; + ret = ret2; } } } @@ -570,9 +556,9 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); //verify if object are correct oType = buff.getObjType(version); if (oType != 0x42) { @@ -585,7 +571,6 @@ bool dwgReader::readDwgTables(DRW_Header if(ret) ret = ret2; } - delete[]tmpByteStr; for (std::list<duint32>::iterator it=appIdControl.hadlesList.begin(); it != appIdControl.hadlesList.end(); ++it){ mit = ObjectMap.find(*it); if (mit==ObjectMap.end()) { @@ -602,14 +587,13 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); ret2 = ai->parseDwg(version, &buff, bs); appIdmap[ai->handle] = ai; if(ret) ret = ret2; - delete[]tmpByteStr; } } } @@ -632,9 +616,9 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); //verify if object are correct oType = buff.getObjType(version); if (oType != 0x3C) { @@ -647,7 +631,6 @@ bool dwgReader::readDwgTables(DRW_Header if(ret) ret = ret2; } - delete[]tmpByteStr; } mit = ObjectMap.find(hdr.ucsCtrl); @@ -666,9 +649,9 @@ bool dwgReader::readDwgTables(DRW_Header bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); //verify if object are correct oType = buff.getObjType(version); if (oType != 0x3E) { @@ -681,7 +664,6 @@ bool dwgReader::readDwgTables(DRW_Header if(ret) ret = ret2; } - delete[]tmpByteStr; } if (version < DRW::AC1018) {//r2000- @@ -698,12 +680,11 @@ bool dwgReader::readDwgTables(DRW_Header dbuf->setPosition(oc.loc); int size = dbuf->getModularShort(); if (version > DRW::AC1021) //2010+ - bs = dbuf->getUModularChar(); - else - bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + /*bs =*/ dbuf->getUModularChar(); +// else bs = 0; + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); //verify if object are correct oType = buff.getObjType(version); if (oType != 0x46) { @@ -716,7 +697,6 @@ bool dwgReader::readDwgTables(DRW_Header if(ret) ret = ret2;*/ } - delete[]tmpByteStr; } } } @@ -724,11 +704,10 @@ bool dwgReader::readDwgTables(DRW_Header return ret; } -bool dwgReader::readDwgBlocks(DRW_Interface& intfa, dwgBuffer *dbuf){ +bool dwgReader::readDwgBlocks(DRW_Interface& intfa, dwgBuffer* dbuf){ bool ret = true; bool ret2 = true; duint32 bs =0; - duint8 *tmpByteStr; std::map<duint32, objHandle>::iterator mit; DRW_DBG("\nobject map total size= "); DRW_DBG(ObjectMap.size()); @@ -755,12 +734,12 @@ bool dwgReader::readDwgBlocks(DRW_Interf bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + + std::vector<duint8> tmpByteStr(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); DRW_Block bk; ret2 = bk.parseDwg(version, &buff, bs); - delete[]tmpByteStr; ret = ret && ret2; parseAttribs(&bk); //complete block entity with block record data @@ -832,13 +811,12 @@ bool dwgReader::readDwgBlocks(DRW_Interf bs = dbuf->getUModularChar(); else bs = 0; - tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff1(tmpByteStr, size, &decoder); + tmpByteStr.resize(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff1(tmpByteStr.data(), size, &decoder); DRW_Block end; end.isEnd = true; ret2 = end.parseDwg(version, &buff1, bs); - delete[]tmpByteStr; ret = ret && ret2; if (bk.parentHandle == DRW::NoHandle) bk.parentHandle= bkr->handle; parseAttribs(&end); @@ -848,7 +826,7 @@ bool dwgReader::readDwgBlocks(DRW_Interf return ret; } -bool dwgReader::readPlineVertex(DRW_Polyline& pline, dwgBuffer *dbuf){ +bool dwgReader::readPlineVertex(DRW_Polyline& pline, dwgBuffer* dbuf){ bool ret = true; bool ret2 = true; objHandle oc; @@ -874,14 +852,13 @@ bool dwgReader::readPlineVertex(DRW_Poly if (version > DRW::AC1021) {//2010+ bs = dbuf->getUModularChar(); } - duint8 *tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + std::vector<duint8> tmpByteStr(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); dint16 oType = buff.getObjType(version); buff.resetPosition(); DRW_DBG(" object type= "); DRW_DBG(oType); DRW_DBG("\n"); ret2 = vt.parseDwg(version, &buff, bs, pline.basePoint.z); - delete[]tmpByteStr; pline.addVertex(vt); nextEntLink = vt.nextEntLink; \ prevEntLink = vt.prevEntLink; @@ -911,14 +888,13 @@ bool dwgReader::readPlineVertex(DRW_Poly if (version > DRW::AC1021) {//2010+ bs = dbuf->getUModularChar(); } - duint8 *tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); - dwgBuffer buff(tmpByteStr, size, &decoder); + std::vector<duint8> tmpByteStr(size); + dbuf->getBytes(tmpByteStr.data(), size); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); dint16 oType = buff.getObjType(version); buff.resetPosition(); DRW_DBG(" object type= "); DRW_DBG(oType); DRW_DBG("\n"); ret2 = vt.parseDwg(version, &buff, bs, pline.basePoint.z); - delete[]tmpByteStr; pline.addVertex(vt); nextEntLink = vt.nextEntLink; \ prevEntLink = vt.prevEntLink; @@ -932,11 +908,12 @@ bool dwgReader::readPlineVertex(DRW_Poly return ret; } -bool dwgReader::readDwgEntities(DRW_Interface& intfa, dwgBuffer *dbuf){ +bool dwgReader::readDwgEntities(DRW_Interface& intfa, dwgBuffer* dbuf){ bool ret = true; bool ret2 = true; DRW_DBG("\nobject map total size= "); DRW_DBG(ObjectMap.size()); + std::map<duint32, objHandle>::iterator itB=ObjectMap.begin(); std::map<duint32, objHandle>::iterator itE=ObjectMap.end(); while (itB != itE){ @@ -952,7 +929,7 @@ bool dwgReader::readDwgEntities(DRW_Inte /** * Reads a dwg drawing entity (dwg object entity) given its offset in the file */ -bool dwgReader::readDwgEntity(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa){ +bool dwgReader::readDwgEntity(dwgBuffer* dbuf, objHandle& obj, DRW_Interface& intfa){ bool ret = true; duint32 bs = 0; @@ -973,15 +950,14 @@ bool dwgReader::readDwgEntity(dwgBuffer if (version > DRW::AC1021) {//2010+ bs = dbuf->getUModularChar(); } - duint8 *tmpByteStr = new duint8[size]; - dbuf->getBytes(tmpByteStr, size); + std::vector<duint8> tmpByteStr(size); + dbuf->getBytes(tmpByteStr.data(), size); //verify if getBytes is ok: if (!dbuf->isGood()){ DRW_DBG(" Warning: readDwgEntity, bad size\n"); - delete[]tmpByteStr; return false; } - dwgBuffer buff(tmpByteStr, size, &decoder); + dwgBuffer buff(tmpByteStr.data(), size, &decoder); dint16 oType = buff.getObjType(version); buff.resetPosition(); @@ -989,7 +965,6 @@ bool dwgReader::readDwgEntity(dwgBuffer std::map<duint32, DRW_Class*>::iterator it = classesmap.find(oType); if (it == classesmap.end()){//fail, not found in classes set error DRW_DBG("Class "); DRW_DBG(oType);DRW_DBG("not found, handle: "); DRW_DBG(obj.handle); DRW_DBG("\n"); - delete[]tmpByteStr; return false; } else { DRW_Class *cl = it->second; @@ -1164,11 +1139,10 @@ bool dwgReader::readDwgEntity(dwgBuffer if (!ret){ DRW_DBG("Warning: Entity type "); DRW_DBG(oType);DRW_DBG("has failed, handle: "); DRW_DBG(obj.handle); DRW_DBG("\n"); } - delete[]tmpByteStr; return ret; } -bool dwgReader::readDwgObjects(DRW_Interface& intfa, dwgBuffer *dbuf){ +bool dwgReader::readDwgObjects(DRW_Interface& intfa, dwgBuffer* dbuf){ bool ret = true; bool ret2 = true; @@ -1197,7 +1171,7 @@ bool dwgReader::readDwgObjects(DRW_Inter /** * Reads a dwg drawing object (dwg object object) given its offset in the file */ -bool dwgReader::readDwgObject(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa){ +bool dwgReader::readDwgObject(dwgBuffer* dbuf, objHandle& obj, DRW_Interface& intfa){ bool ret = true; duint32 bs = 0; @@ -1243,7 +1217,7 @@ bool dwgReader::readDwgObject(dwgBuffer -bool DRW_ObjControl::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ +bool DRW_ObjControl::parseDwg(DRW::Version version, dwgBuffer* buf, duint32 bs){ int unkData=0; bool ret = DRW_TableEntry::parseDwg(version, buf, NULL, bs); DRW_DBG("\n***************************** parsing object control entry *********************************************\n"); diff -urp libdxfrw-0.6.3/src/intern/dwgreader.h LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader.h --- libdxfrw-0.6.3/src/intern/dwgreader.h 2015-04-09 14:32:22.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgreader.h 2016-06-05 02:27:45.000000000 -0400 @@ -22,15 +22,15 @@ class objHandle{ public: - objHandle(){ handle = type = loc = 0; } - objHandle(duint32 t, duint32 h, duint32 l){ - type = t; - handle = h; - loc = l; - } - duint32 type; - duint32 handle; - duint32 loc; + objHandle(){ handle = type = loc = 0; } + objHandle(duint32 t, duint32 h, duint32 l){ + type = t; + handle = h; + loc = l; + } + duint32 type; + duint32 handle; + duint32 loc; }; //until 2000 = 2000- @@ -55,18 +55,18 @@ public: * */ class dwgPageInfo { public: - dwgPageInfo(){} - dwgPageInfo(duint64 i, duint64 ad, duint32 sz){ - Id=i; address=ad; size=sz; - } - ~dwgPageInfo(){} - duint64 Id; - duint64 address; //in file stream, for rd18, rd21 - duint64 size; //in file stream, for rd18, rd21 - duint64 dataSize; //for rd18, rd21 - duint32 startOffset; //for rd18, rd21 - duint64 cSize; //compresed page size, for rd21 - duint64 uSize; //uncompresed page size, for rd21 + dwgPageInfo(){} + dwgPageInfo(duint64 i, duint64 ad, duint32 sz){ + Id=i; address=ad; size=sz; + } + ~dwgPageInfo(){} + duint64 Id; + duint64 address; //in file stream, for rd18, rd21 + duint64 size; //in file stream, for rd18, rd21 + duint64 dataSize; //for rd18, rd21 + duint32 startOffset; //for rd18, rd21 + duint64 cSize; //compresed page size, for rd21 + duint64 uSize; //uncompresed page size, for rd21 }; // sections of file @@ -82,22 +82,22 @@ public: * */ class dwgSectionInfo { public: - dwgSectionInfo(){ - compresed = 1;//1=no, 2=yes - encrypted = 0;//??? - pageCount = 0; - Id=-1; - } - ~dwgSectionInfo(){} - dint32 Id; //section Id, 2000- rd15 rd18 - std::string name; //section name rd18 - duint32 compresed;//is compresed? 1=no, 2=yes rd18, rd21(encoding) - duint32 encrypted;//encrypted (doc: 0=no, 1=yes, 2=unkn) on read: objects 0 and encrypted yes rd18 - std::map<duint32, dwgPageInfo >pages;//index, size, offset - duint64 size;//size of section, 2000- rd15, rd18, rd21 (data size) - duint64 pageCount; //number of pages (dwgPageInfo) in section rd18, rd21 - duint64 maxSize; //max decompressed size (needed??) rd18 rd21 - duint64 address; //address (seek) , 2000- + dwgSectionInfo(){ + compresed = 1;//1=no, 2=yes + encrypted = 0;//??? + pageCount = 0; + Id=-1; + } + ~dwgSectionInfo(){} + dint32 Id; //section Id, 2000- rd15 rd18 + std::string name; //section name rd18 + duint32 compresed;//is compresed? 1=no, 2=yes rd18, rd21(encoding) + duint32 encrypted;//encrypted (doc: 0=no, 1=yes, 2=unkn) on read: objects 0 and encrypted yes rd18 + std::map<duint32, dwgPageInfo >pages;//index, size, offset + duint64 size;//size of section, 2000- rd15, rd18, rd21 (data size) + duint64 pageCount; //number of pages (dwgPageInfo) in section rd18, rd21 + duint64 maxSize; //max decompressed size (needed??) rd18 rd21 + duint64 address; //address (seek) , 2000- }; @@ -108,94 +108,95 @@ public: */ class DRW_ObjControl : public DRW_TableEntry { public: - DRW_ObjControl() { reset();} + DRW_ObjControl() { reset();} - void reset(){ - } - bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); - std::list<duint32>hadlesList; + void reset(){ + } + bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + std::list<duint32>hadlesList; }; class dwgReader { - friend class dwgR; + friend class dwgR; public: - dwgReader(std::ifstream *stream, dwgR *p){ - fileBuf = new dwgBuffer(stream); - parent = p; - decoder.setVersion(DRW::AC1021, false);//default 2007 in utf8(no convert) - decoder.setCodePage("UTF-16", false); + dwgReader(std::ifstream *stream, dwgR *p): + fileBuf{new dwgBuffer(stream)} + { + parent = p; + decoder.setVersion(DRW::AC1021, false);//default 2007 in utf8(no convert) + decoder.setCodePage("UTF-16", false); // blockCtrl=0; //RLZ: temporary // blockCtrl=layerCtrl=styleCtrl=linetypeCtrl=viewCtrl=0; // ucsCtrl=vportCtrl=appidCtrl=dimstyleCtrl=vpEntHeaderCtrl=0; - nextEntLink = prevEntLink = 0; - maintenanceVersion=0; - } - virtual ~dwgReader(); + nextEntLink = prevEntLink = 0; + maintenanceVersion=0; + } + virtual ~dwgReader(); protected: - virtual bool readMetaData() = 0; - virtual bool readPreview(){return false;} - virtual bool readFileHeader() = 0; - virtual bool readDwgHeader(DRW_Header& hdr)=0; - virtual bool readDwgClasses() = 0; - virtual bool readDwgHandles() = 0; - virtual bool readDwgTables(DRW_Header& hdr)=0; - virtual bool readDwgBlocks(DRW_Interface& intfa) = 0; - virtual bool readDwgEntities(DRW_Interface& intfa) = 0; - virtual bool readDwgObjects(DRW_Interface& intfa) = 0; - - virtual bool readDwgEntity(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa); - bool readDwgObject(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa); - void parseAttribs(DRW_Entity* e); - std::string findTableName(DRW::TTYPE table, dint32 handle); - - void setCodePage(std::string *c){decoder.setCodePage(c, false);} - std::string getCodePage(){ return decoder.getCodePage();} - bool readDwgHeader(DRW_Header& hdr, dwgBuffer *buf, dwgBuffer *hBuf); - bool readDwgHandles(dwgBuffer *dbuf, duint32 offset, duint32 size); - bool readDwgTables(DRW_Header& hdr, dwgBuffer *dbuf); - bool checkSentinel(dwgBuffer *buf, enum secEnum::DWGSection, bool start); - - bool readDwgBlocks(DRW_Interface& intfa, dwgBuffer *dbuf); - bool readDwgEntities(DRW_Interface& intfa, dwgBuffer *dbuf); - bool readDwgObjects(DRW_Interface& intfa, dwgBuffer *dbuf); - bool readPlineVertex(DRW_Polyline& pline, dwgBuffer *dbuf); - -public: - std::map<duint32, objHandle>ObjectMap; - std::map<duint32, objHandle>objObjectMap; //stores the ojects & entities not read in readDwgEntities - std::map<duint32, objHandle>remainingMap; //stores the ojects & entities not read in all proces, for debug only - std::map<duint32, DRW_LType*> ltypemap; - std::map<duint32, DRW_Layer*> layermap; - std::map<duint32, DRW_Block*> blockmap; - std::map<duint32, DRW_Textstyle*> stylemap; - std::map<duint32, DRW_Dimstyle*> dimstylemap; - std::map<duint32, DRW_Vport*> vportmap; - std::map<duint32, DRW_Block_Record*> blockRecordmap; - std::map<duint32, DRW_AppId*> appIdmap; + virtual bool readMetaData() = 0; + virtual bool readPreview(){return false;} + virtual bool readFileHeader() = 0; + virtual bool readDwgHeader(DRW_Header& hdr)=0; + virtual bool readDwgClasses() = 0; + virtual bool readDwgHandles() = 0; + virtual bool readDwgTables(DRW_Header& hdr)=0; + virtual bool readDwgBlocks(DRW_Interface& intfa) = 0; + virtual bool readDwgEntities(DRW_Interface& intfa) = 0; + virtual bool readDwgObjects(DRW_Interface& intfa) = 0; + + virtual bool readDwgEntity(dwgBuffer* dbuf, objHandle& obj, DRW_Interface& intfa); + bool readDwgObject(dwgBuffer* dbuf, objHandle& obj, DRW_Interface& intfa); + void parseAttribs(DRW_Entity* e); + std::string findTableName(DRW::TTYPE table, dint32 handle); + + void setCodePage(std::string *c){decoder.setCodePage(c, false);} + std::string getCodePage(){ return decoder.getCodePage();} + bool readDwgHeader(DRW_Header& hdr, dwgBuffer* buf, dwgBuffer* hBuf); + bool readDwgHandles(dwgBuffer* dbuf, duint32 offset, duint32 size); + bool readDwgTables(DRW_Header& hdr, dwgBuffer* dbuf); + bool checkSentinel(dwgBuffer* buf, enum secEnum::DWGSection, bool start); + + bool readDwgBlocks(DRW_Interface& intfa, dwgBuffer* dbuf); + bool readDwgEntities(DRW_Interface& intfa, dwgBuffer* dbuf); + bool readDwgObjects(DRW_Interface& intfa, dwgBuffer* dbuf); + bool readPlineVertex(DRW_Polyline& pline, dwgBuffer* dbuf); + +public: + std::map<duint32, objHandle>ObjectMap; + std::map<duint32, objHandle>objObjectMap; //stores the ojects & entities not read in readDwgEntities + std::map<duint32, objHandle>remainingMap; //stores the ojects & entities not read in all proces, for debug only + std::map<duint32, DRW_LType*> ltypemap; + std::map<duint32, DRW_Layer*> layermap; + std::map<duint32, DRW_Block*> blockmap; + std::map<duint32, DRW_Textstyle*> stylemap; + std::map<duint32, DRW_Dimstyle*> dimstylemap; + std::map<duint32, DRW_Vport*> vportmap; + std::map<duint32, DRW_Block_Record*> blockRecordmap; + std::map<duint32, DRW_AppId*> appIdmap; // duint32 currBlock; - duint8 maintenanceVersion; + duint8 maintenanceVersion; protected: - dwgBuffer *fileBuf; - dwgR *parent; - DRW::Version version; + std::unique_ptr<dwgBuffer> fileBuf; + dwgR *parent; + DRW::Version version; //seeker (position) for the beginning sentinel of the image data (R13 to R15) - duint32 previewImagePos; + duint32 previewImagePos; //sections map - std::map<enum secEnum::DWGSection, dwgSectionInfo >sections; - std::map<duint32, DRW_Class*> classesmap; + std::map<enum secEnum::DWGSection, dwgSectionInfo >sections; + std::map<duint32, DRW_Class*> classesmap; protected: - DRW_TextCodec decoder; + DRW_TextCodec decoder; protected: // duint32 blockCtrl; - duint32 nextEntLink; - duint32 prevEntLink; + duint32 nextEntLink; + duint32 prevEntLink; }; diff -urp libdxfrw-0.6.3/src/intern/dwgutil.cpp LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgutil.cpp --- libdxfrw-0.6.3/src/intern/dwgutil.cpp 2015-04-10 10:29:59.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgutil.cpp 2016-06-05 02:27:45.000000000 -0400 @@ -176,8 +176,8 @@ void dwgCompressor::decompress18(duint8 compOffset = twoByteOffset(&litCount); if (litCount == 0) litCount= litLength18(); - else - oc = 0x00; +// else +// oc = 0x00; } else if (oc > 0x20 && oc< 0x40){ compBytes = oc - 0x1E; compOffset = twoByteOffset(&litCount); diff -urp libdxfrw-0.6.3/src/intern/dwgutil.h LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgutil.h --- libdxfrw-0.6.3/src/intern/dwgutil.h 2015-04-09 14:26:21.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/intern/dwgutil.h 2016-06-05 02:27:45.000000000 -0400 @@ -19,18 +19,13 @@ namespace DRW { std::string toHexStr(int n); } -class dwgRSCodec { -public: - dwgRSCodec(){} - ~dwgRSCodec(){} - static void decode239I(duint8 *in, duint8 *out, duint32 blk); - static void decode251I(duint8 *in, duint8 *out, duint32 blk); +namespace dwgRSCodec { +void decode239I(duint8 *in, duint8 *out, duint32 blk); +void decode251I(duint8 *in, duint8 *out, duint32 blk); }; class dwgCompressor { public: - dwgCompressor(){} - ~dwgCompressor(){} void decompress18(duint8 *cbuf, duint8 *dbuf, duint32 csize, duint32 dsize); static void decrypt18Hdr(duint8 *buf, duint32 size, duint32 offset); @@ -56,8 +51,7 @@ private: }; -class secEnum { -public: +namespace secEnum { enum DWGSection { UNKNOWNS, /*!< UNKNOWN section. */ FILEHEADER, /*!< File Header (in R3-R15*/ @@ -82,10 +76,7 @@ public: PROXYGRAPHICS /*!< PROXY ENTITY GRAPHICS */ }; - secEnum(){} - ~secEnum(){} - - static DWGSection getEnum(std::string nameSec); + DWGSection getEnum(std::string nameSec); }; #endif // DWGUTIL_H diff -urp libdxfrw-0.6.3/src/libdxfrw.cpp LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/libdxfrw.cpp --- libdxfrw-0.6.3/src/libdxfrw.cpp 2015-09-03 12:25:13.000000000 -0400 +++ LibreCAD-dbf1cc7c9597740d34a068f6f09c36841054e903/libraries/libdxfrw/src/libdxfrw.cpp 2016-06-05 02:27:45.000000000 -0400 @@ -423,6 +423,8 @@ bool dxfRW::writeDimstyle(DRW_Dimstyle * writer->writeDouble(46, ent->dimdle); writer->writeDouble(47, ent->dimtp); writer->writeDouble(48, ent->dimtm); + if ( version > DRW::AC1018 || ent->dimfxl !=0 ) + writer->writeDouble(49, ent->dimfxl); writer->writeDouble(140, ent->dimtxt); writer->writeDouble(141, ent->dimcen); writer->writeDouble(142, ent->dimtsz); @@ -487,6 +489,8 @@ bool dxfRW::writeDimstyle(DRW_Dimstyle * if (version > DRW::AC1014) { writer->writeInt16(289, ent->dimatfit); } + if ( version > DRW::AC1018 && ent->dimfxlon !=0 ) + writer->writeInt16(290, ent->dimfxlon); if (version > DRW::AC1009) { writer->writeUtf8String(340, ent->dimtxsty); } @@ -740,7 +744,7 @@ bool dxfRW::writeLWPolyline(DRW_LWPolyli if (ent->thickness != 0) writer->writeDouble(39, ent->thickness); for (int i = 0; i< ent->vertexnum; i++){ - DRW_Vertex2D *v = ent->vertlist.at(i); + auto& v = ent->vertlist.at(i); writer->writeDouble(10, v->x); writer->writeDouble(20, v->y); if (v->stawidth != 0) @@ -801,7 +805,7 @@ bool dxfRW::writePolyline(DRW_Polyline * int vertexnum = ent->vertlist.size(); for (int i = 0; i< vertexnum; i++){ - DRW_Vertex *v = ent->vertlist.at(i); + auto& v = ent->vertlist.at(i); writer->writeString(0, "VERTEX"); writeEntity(ent); if (version > DRW::AC1009) @@ -871,8 +875,7 @@ bool dxfRW::writeSpline(DRW_Spline *ent) for (int i = 0; i< ent->nknots; i++){ writer->writeDouble(40, ent->knotslist.at(i)); } - for (int i = 0; i< ent->ncontrol; i++){ - DRW_Coord *crd = ent->controllist.at(i); + for (auto const& crd: ent->controllist) { writer->writeDouble(10, crd->x); writer->writeDouble(20, crd->y); writer->writeDouble(30, crd->z); @@ -901,7 +904,7 @@ bool dxfRW::writeHatch(DRW_Hatch *ent){ writer->writeInt16(91, ent->loopsnum); //write paths data for (int i = 0; i< ent->loopsnum; i++){ - DRW_HatchLoop *loop = ent->looplist.at(i); + auto const& loop = ent->looplist.at(i); writer->writeInt16(92, loop->type); if ( (loop->type & 2) == 2){ //RLZ: polyline boundary writeme @@ -913,7 +916,7 @@ bool dxfRW::writeHatch(DRW_Hatch *ent){ switch ( (loop->objlist.at(j))->eType) { case DRW::LINE: { writer->writeInt16(72, 1); - DRW_Line* l = (DRW_Line*)loop->objlist.at(j); + DRW_Line* l = (DRW_Line*)loop->objlist.at(j).get(); writer->writeDouble(10, l->basePoint.x); writer->writeDouble(20, l->basePoint.y); writer->writeDouble(11, l->secPoint.x); @@ -921,7 +924,7 @@ bool dxfRW::writeHatch(DRW_Hatch *ent){ break; } case DRW::ARC: { writer->writeInt16(72, 2); - DRW_Arc* a = (DRW_Arc*)loop->objlist.at(j); + DRW_Arc* a = (DRW_Arc*)loop->objlist.at(j).get(); writer->writeDouble(10, a->basePoint.x); writer->writeDouble(20, a->basePoint.y); writer->writeDouble(40, a->radious); @@ -931,7 +934,7 @@ bool dxfRW::writeHatch(DRW_Hatch *ent){ break; } case DRW::ELLIPSE: { writer->writeInt16(72, 3); - DRW_Ellipse* a = (DRW_Ellipse*)loop->objlist.at(j); + DRW_Ellipse* a = (DRW_Ellipse*)loop->objlist.at(j).get(); a->correctAxis(); writer->writeDouble(10, a->basePoint.x); writer->writeDouble(20, a->basePoint.y); @@ -986,8 +989,7 @@ bool dxfRW::writeLeader(DRW_Leader *ent) writer->writeDouble(41, ent->textwidth); writer->writeDouble(76, ent->vertnum); writer->writeDouble(76, ent->vertexlist.size()); - for (unsigned int i=0; i<ent->vertexlist.size(); i++) { - DRW_Coord *vert = ent->vertexlist.at(i); + for (auto const& vert: ent->vertexlist) { writer->writeDouble(10, vert->x); writer->writeDouble(20, vert->y); writer->writeDouble(30, vert->z); @@ -1761,15 +1763,15 @@ bool dxfRW::writeObjects() { bool dxfRW::writeExtData(const std::vector<DRW_Variant*> &ed){ for (std::vector<DRW_Variant*>::const_iterator it=ed.begin(); it!=ed.end(); ++it){ - switch ((*it)->code) { + switch ((*it)->code()) { case 1000: case 1001: case 1002: case 1003: case 1004: case 1005: - {int cc = (*it)->code; - if ((*it)->type == DRW_Variant::STRING) + {int cc = (*it)->code(); + if ((*it)->type() == DRW_Variant::STRING) writer->writeUtf8String(cc, *(*it)->content.s); // writer->writeUtf8String((*it)->code, (*it)->content.s); break;} @@ -1777,25 +1779,25 @@ bool dxfRW::writeExtData(const std::vect case 1011: case 1012: case 1013: - if ((*it)->type == DRW_Variant::COORD) { - writer->writeDouble((*it)->code, (*it)->content.v->x); - writer->writeDouble((*it)->code+10 , (*it)->content.v->y); - writer->writeDouble((*it)->code+20 , (*it)->content.v->z); + if ((*it)->type() == DRW_Variant::COORD) { + writer->writeDouble((*it)->code(), (*it)->content.v->x); + writer->writeDouble((*it)->code()+10 , (*it)->content.v->y); + writer->writeDouble((*it)->code()+20 , (*it)->content.v->z); } break; case 1040: case 1041: case 1042: - if ((*it)->type == DRW_Variant::DOUBLE) - writer->writeDouble((*it)->code, (*it)->content.d); + if ((*it)->type() == DRW_Variant::DOUBLE) + writer->writeDouble((*it)->code(), (*it)->content.d); break; case 1070: - if ((*it)->type == DRW_Variant::INTEGER) - writer->writeInt16((*it)->code, (*it)->content.i); + if ((*it)->type() == DRW_Variant::INTEGER) + writer->writeInt16((*it)->code(), (*it)->content.i); break; case 1071: - if ((*it)->type == DRW_Variant::INTEGER) - writer->writeInt32((*it)->code, (*it)->content.i); + if ((*it)->type() == DRW_Variant::INTEGER) + writer->writeInt32((*it)->code(), (*it)->content.i); break; default: break; @@ -2508,22 +2510,21 @@ bool dxfRW::processPolyline() { bool dxfRW::processVertex(DRW_Polyline *pl) { DRW_DBG("dxfRW::processVertex"); int code; - DRW_Vertex *v = new DRW_Vertex(); + std::shared_ptr<DRW_Vertex> v = std::make_shared<DRW_Vertex>(); while (reader->readRec(&code)) { - DRW_DBG(code); DRW_DBG("\n"); + DRW_DBG(code); DRW_DBG("\n"); switch (code) { - case 0: { - pl->appendVertex(v); - nextentity = reader->getString(); - DRW_DBG(nextentity); DRW_DBG("\n"); - if (nextentity == "SEQEND") { - return true; //found SEQEND no more vertex, terminate - } else if (nextentity == "VERTEX"){ - v = new DRW_Vertex(); //another vertex - } - } + case 0: + pl->appendVertex(v); + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + if (nextentity == "SEQEND") + return true; //found SEQEND no more vertex, terminate + else if (nextentity == "VERTEX") + v->reset(); //another vertex + default: - v->parseCode(code, reader); + v->parseCode(code, reader); break; } }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor