libdxfrw. C++14 support

This commit is contained in:
Roman Telezhynskyi 2023-11-20 12:23:56 +02:00
parent d704cf9322
commit f5256c514c
8 changed files with 1556 additions and 1543 deletions

View File

@ -71,7 +71,7 @@ void DRW_Entity::extrudePoint(DRW_Coord extPoint, DRW_Coord *point) const
point->z = pz;
}
auto DRW_Entity::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Entity::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -160,7 +160,7 @@ auto DRW_Entity::parseCode(int code, dxfReader *reader) -> bool
}
// parses dxf 102 groups to read entity
auto DRW_Entity::parseDxfGroups(int code, dxfReader *reader) -> bool
auto DRW_Entity::parseDxfGroups(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
std::list<DRW_Variant> ls;
DRW_Variant c;
@ -206,7 +206,7 @@ auto DRW_Entity::parseDxfGroups(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Point::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Point::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -239,7 +239,7 @@ auto DRW_Point::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_ASTMNotch::parseCode(int code, dxfReader *reader) -> bool
auto DRW_ASTMNotch::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -253,7 +253,7 @@ auto DRW_ASTMNotch::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Line::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Line::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -284,7 +284,7 @@ void DRW_Circle::applyExtrusion()
}
}
auto DRW_Circle::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Circle::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -321,7 +321,7 @@ void DRW_Arc::applyExtrusion()
}
}
auto DRW_Arc::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Arc::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -338,7 +338,7 @@ auto DRW_Arc::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Ellipse::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Ellipse::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -453,7 +453,7 @@ void DRW_Trace::applyExtrusion()
}
}
auto DRW_Trace::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Trace::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -482,7 +482,7 @@ auto DRW_Trace::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_3Dface::parseCode(int code, dxfReader *reader) -> bool
auto DRW_3Dface::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -496,7 +496,7 @@ auto DRW_3Dface::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Block::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Block::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -513,7 +513,7 @@ auto DRW_Block::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Insert::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Insert::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -568,7 +568,7 @@ void DRW_LWPolyline::applyExtrusion()
}
}
auto DRW_LWPolyline::parseCode(int code, dxfReader *reader) -> bool
auto DRW_LWPolyline::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -627,7 +627,7 @@ auto DRW_LWPolyline::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Text::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Text::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -665,7 +665,7 @@ auto DRW_Text::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_MText::parseCode(int code, dxfReader *reader) -> bool
auto DRW_MText::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -758,7 +758,7 @@ void DRW_MText::updateAngle()
}
}
auto DRW_Polyline::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Polyline::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -793,7 +793,7 @@ auto DRW_Polyline::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Vertex::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Vertex::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -834,7 +834,7 @@ auto DRW_Vertex::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Hatch::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Hatch::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -974,7 +974,7 @@ auto DRW_Hatch::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Spline::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Spline::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -1072,7 +1072,7 @@ auto DRW_Spline::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Image::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Image::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -1113,7 +1113,7 @@ auto DRW_Image::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Dimension::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Dimension::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -1236,7 +1236,7 @@ auto DRW_Dimension::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Leader::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Leader::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{
@ -1331,7 +1331,7 @@ auto DRW_Leader::parseCode(int code, dxfReader *reader) -> bool
return true;
}
auto DRW_Viewport::parseCode(int code, dxfReader *reader) -> bool
auto DRW_Viewport::parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool
{
switch (code)
{

View File

@ -18,6 +18,7 @@
#include <QtGlobal>
#include <algorithm>
#include <list>
#include <memory>
#include <string>
#include <vector>
@ -195,14 +196,14 @@ public:
protected:
// parses dxf pair to read entity
virtual auto parseCode(int code, dxfReader *reader) -> bool;
virtual auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool;
// calculates extrusion axis (normal vector)
void calculateAxis(DRW_Coord extPoint);
// apply extrusion to @extPoint and return data in @point
void extrudePoint(DRW_Coord extPoint, DRW_Coord *point) const;
// parses dxf 102 groups to read entity
auto parseDxfGroups(int code, dxfReader *reader) -> bool;
auto parseDxfGroups(int code, const std::unique_ptr<dxfReader> &reader) -> bool;
public:
DRW::ETYPE eType; /*!< enum: entity type, code 0 */
@ -249,7 +250,7 @@ public:
void applyExtrusion() override {}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
DRW_Coord basePoint{}; /*!< base point, code 10, 20 & 30 */
@ -267,7 +268,7 @@ public:
DRW_ASTMNotch() { eType = DRW::ASTMNOTCH; }
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
double angle{0}; /*!< angle, code 50 */
@ -292,7 +293,7 @@ public:
void applyExtrusion() override {}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
DRW_Coord secPoint; /*!< second point, code 11, 21 & 31 */
@ -341,7 +342,7 @@ public:
void applyExtrusion() override;
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
double radious; /*!< radius, code 40 */
@ -382,7 +383,7 @@ public:
protected:
//! interpret code in dxf reading process or dispatch to inherited class
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
double staangle; /*!< start angle, code 50 in radians*/
@ -416,7 +417,7 @@ public:
protected:
//! interpret code in dxf reading process or dispatch to inherited class
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
private:
void correctAxis();
@ -448,7 +449,7 @@ public:
void applyExtrusion() override;
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
DRW_Coord thirdPoint; /*!< third point, code 12, 22 & 32 */
@ -525,7 +526,7 @@ public:
protected:
//! interpret code in dxf reading process or dispatch to inherited class
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
int invisibleflag; /*!< invisible edge flag, code 70 */
@ -552,7 +553,7 @@ public:
void applyExtrusion() override {}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
UTF8STRING name; /*!< block name, code 2 */
@ -584,7 +585,7 @@ public:
}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
UTF8STRING name; /*!< block name, code 2 */
@ -664,7 +665,7 @@ public:
}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
int vertexnum; /*!< number of vertex, code 90 */
@ -727,7 +728,7 @@ public:
void applyExtrusion() override {} // RLZ TODO
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
double height; /*!< height text, code 40 */
@ -775,7 +776,7 @@ public:
}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
void updateAngle(); // recalculate angle if 'haveXAxis' is true
public:
@ -828,7 +829,7 @@ public:
}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
double stawidth; /*!< Start width, code 40 */
@ -910,7 +911,7 @@ public:
void appendVertex(DRW_Vertex *v) { vertlist.push_back(v); }
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
int flags; /*!< polyline flag, code 70, default 0 */
@ -1003,7 +1004,7 @@ public:
void applyExtrusion() override {}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
// double ex; /*!< normal vector x coordinate, code 210 */
@ -1119,7 +1120,7 @@ public:
void applyExtrusion() override {}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
UTF8STRING name; /*!< hatch pattern name, code 2 */
@ -1225,7 +1226,7 @@ public:
}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
duint32 ref; /*!< Hard reference to imagedef object, code 340 */
@ -1307,12 +1308,12 @@ public:
eType = DRW::DIMENSION;
// RLZ needed a def value for this: hdir = ???
}
virtual ~DRW_Dimension() = default;
~DRW_Dimension() override = default;
void applyExtrusion() override {}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
auto getDefPoint() const -> DRW_Coord { return defPoint; } /*!< Definition point, code 10, 20 & 30 */
@ -1671,7 +1672,7 @@ public:
void applyExtrusion() override {}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
UTF8STRING style; /*!< Dimension style name, code 3 */
@ -1734,7 +1735,7 @@ public:
void applyExtrusion() override {}
protected:
auto parseCode(int code, dxfReader *reader) -> bool override;
auto parseCode(int code, const std::unique_ptr<dxfReader> &reader) -> bool override;
public:
double pswidth; /*!< Width in paper space units, code 40 */

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@
#include <map>
#include <memory>
#include "drw_base.h"
class dxfReader;
@ -111,11 +112,11 @@ public:
void addStr(std::string key, const std::string &value, int code);
void addCoord(std::string key, const DRW_Coord &value, int code);
auto getComments() const -> std::string { return comments; }
void write(dxfWriter *writer, DRW::Version ver);
void write(const std::unique_ptr<dxfWriter>& writer, DRW::Version ver);
void addComment(const std::string &c);
protected:
auto parseCode(int code, dxfReader *reader) -> bool;
auto parseCode(int code, const std::unique_ptr<dxfReader>& reader) -> bool;
private:
auto getDouble(const std::string &key, double *varDouble) const -> bool;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -40,8 +40,6 @@ dxfRW::dxfRW(const char *name)
dxfRW::~dxfRW()
{
delete reader;
delete writer;
for (auto &it : imageDef)
{
delete it;
@ -92,19 +90,19 @@ auto dxfRW::read(DRW_Interface *interface_, bool ext) -> bool
binFile = true;
// skip sentinel
filestr.seekg(22, std::ios::beg);
reader = new dxfReaderBinary(&filestr);
reader = std::make_unique<dxfReaderBinary>(&filestr);
DRW_DBG("dxfRW::read binary file\n");
}
else
{
binFile = false;
filestr.open(fileName.c_str(), std::ios_base::in);
reader = new dxfReaderAscii(&filestr);
reader = std::make_unique<dxfReaderAscii>(&filestr);
}
bool isOk = processDxf();
filestr.close();
delete reader;
reader.reset();
reader = nullptr;
return isOk;
}
@ -124,13 +122,13 @@ auto dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin) -> bool
filestr.open(fileName.c_str(), std::ios_base::out | std::ios::binary | std::ios::trunc);
// write sentinel
filestr << "AutoCAD Binary DXF\r\n" << static_cast<char>(26) << '\0';
writer = new dxfWriterBinary(&filestr);
writer = std::make_unique<dxfWriterBinary>(&filestr);
DRW_DBG("dxfRW::read binary file\n");
}
else
{
filestr.open(fileName.c_str(), std::ios_base::out | std::ios::trunc);
writer = new dxfWriterAscii(&filestr);
writer = std::make_unique<dxfWriterAscii>(&filestr);
std::string comm = std::string("dxfrw ") + std::string(DRW_VERSION);
writer->writeString(999, comm);
}
@ -174,13 +172,11 @@ auto dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin) -> bool
catch (std::ofstream::failure &writeErr)
{
errorString = writeErr.what();
delete writer;
writer = nullptr;
writer.reset();
return isOk;
}
isOk = true;
delete writer;
writer = nullptr;
writer.reset();
return isOk;
}

View File

@ -146,8 +146,8 @@ private:
std::string codePage{};
bool binFile{false};
bool m_xSpaceBlock{true};
dxfReader *reader{nullptr};
dxfWriter *writer{nullptr};
std::unique_ptr<dxfReader> reader{};
std::unique_ptr<dxfWriter> writer{};
DRW_Interface *iface{nullptr};
DRW_Header header{};
// int section;