More modernization and cleanups.

This commit is contained in:
Roman Telezhynskyi 2021-11-22 19:28:51 +02:00
parent 5f6445cf93
commit c51d9d5b30
7 changed files with 42 additions and 57 deletions

View File

@ -51,7 +51,7 @@ void DRW_Header::parseCode(int code, dxfReader *reader){
case 1:
curr->addString(reader->getUtf8String());
if (name =="$ACADVER") {
reader->setVersion(curr->content.s, true);
reader->setVersion(*curr->content.s, true);
version = reader->getVersion();
}
curr->code = code;
@ -67,7 +67,7 @@ void DRW_Header::parseCode(int code, dxfReader *reader){
case 3:
curr->addString(reader->getUtf8String());
if (name =="$DWGCODEPAGE") {
reader->setCodePage(curr->content.s);
reader->setCodePage(*curr->content.s);
curr->addString(reader->getCodePage());
}
curr->code = code;
@ -138,7 +138,7 @@ void DRW_Header::write(dxfWriter *writer, DRW::Version ver){
break;
}
writer->writeString(1, varStr);
writer->setVersion(&varStr, true);
writer->setVersion(varStr, true);
getStr("$ACADVER", &varStr);
getStr("$ACADMAINTVER", &varStr);
@ -147,7 +147,7 @@ void DRW_Header::write(dxfWriter *writer, DRW::Version ver){
varStr = "ANSI_1252";
}
writer->writeString(9, "$DWGCODEPAGE");
writer->setCodePage(&varStr);
writer->setCodePage(varStr);
writer->writeString(3, writer->getCodePage() );
writer->writeString(9, "$INSBASE");
if (getCoord("$INSBASE", &varCoord)) {

View File

@ -12,9 +12,10 @@
#include <iostream>
#include <iomanip>
#include <memory>
#include "drw_dbg.h"
DRW_dbg *DRW_dbg::instance= NULL;
DRW_dbg *DRW_dbg::instance{nullptr};
/*********private clases*************/
class print_none {
@ -27,54 +28,45 @@ public:
virtual void printB(int i){(void)i;}
virtual void printHL(int c, int s, int h){(void)c;(void)s;(void)h;}
virtual void printPT(double x, double y, double z){(void)x;(void)y;(void)z;}
print_none(){}
virtual ~print_none(){}
print_none()= default;
virtual ~print_none()=default;
};
class print_debug : public print_none {
public:
virtual void printS(const std::string &s) override;
virtual void printI(long long int i) override;
virtual void printUI(long long unsigned int i) override;
virtual void printD(double d) override;
virtual void printH(long long int i) override;
virtual void printB(int i) override;
virtual void printHL(int c, int s, int h) override;
virtual void printPT(double x, double y, double z) override;
print_debug();
virtual ~print_debug() = default;
void printS(const std::string &s) override;
void printI(long long int i) override;
void printUI(long long unsigned int i) override;
void printD(double d) override;
void printH(long long int i) override;
void printB(int i) override;
void printHL(int c, int s, int h) override;
void printPT(double x, double y, double z) override;
print_debug()=default;
private:
std::ios_base::fmtflags flags;
std::ios_base::fmtflags flags{std::cerr.flags()};
};
/********* debug class *************/
DRW_dbg *DRW_dbg::getInstance(){
if (instance == NULL){
if (instance == nullptr){
instance = new DRW_dbg;
}
return instance;
}
DRW_dbg::DRW_dbg()
: level(NONE),
flags(std::cerr.flags()),
prClass(new print_none)
DRW_dbg::DRW_dbg() :
prClass(std::make_unique<print_none>())
{}
DRW_dbg::~DRW_dbg()
{
delete prClass;
}
void DRW_dbg::setLevel(LEVEL lvl){
level = lvl;
delete prClass;
switch (level){
case DEBUG:
prClass = new print_debug;
prClass = std::make_unique<print_debug>();
break;
default:
prClass = new print_none;
prClass = std::make_unique<print_none>();
}
}
@ -125,10 +117,6 @@ void DRW_dbg::printPT(double x, double y, double z){
prClass->printPT(x, y, z);
}
print_debug::print_debug()
: flags(std::cerr.flags())
{}
void print_debug::printS(const std::string &s){
std::cerr << s;
}

View File

@ -16,6 +16,7 @@
#include <string>
#include <iostream>
#include <QtGlobal>
#include <memory>
//#include <iomanip>
#define DRW_DBGSL(a) DRW_dbg::getInstance()->setLevel(a)
@ -55,9 +56,9 @@ private:
DRW_dbg();
~DRW_dbg();
static DRW_dbg *instance;
LEVEL level;
std::ios_base::fmtflags flags;
print_none* prClass;
LEVEL level{NONE};
std::ios_base::fmtflags flags{std::cerr.flags()};
std::unique_ptr<print_none> prClass;
};

View File

@ -45,22 +45,20 @@ QMap<QString, QStringList> QtCodecs()
}
DRW_TextCodec::DRW_TextCodec()
: version(DRW::AC1021),
cp(),
conv(nullptr)
: version(DRW::AC1021)
{}
void DRW_TextCodec::setVersion(int v, bool dxfFormat){
if (v == DRW::AC1009 || v == DRW::AC1006) {
version = DRW::AC1009;
cp = "ANSI_1252";
setCodePage(&cp, dxfFormat);
setCodePage(cp, dxfFormat);
} else if (v == DRW::AC1012 || v == DRW::AC1014
|| v == DRW::AC1015 || v == DRW::AC1018) {
version = DRW::AC1015;
// if (cp.empty()) { //codepage not set, initialize
cp = "ANSI_1252";
setCodePage(&cp, dxfFormat);
setCodePage(cp, dxfFormat);
// }
} else {
version = DRW::AC1021;
@ -68,12 +66,11 @@ void DRW_TextCodec::setVersion(int v, bool dxfFormat){
cp = "UTF-8";//RLZ: can be UCS2 or UTF-16 16bits per char
else
cp = "UTF-16";//RLZ: can be UCS2 or UTF-16 16bits per char
setCodePage(&cp, dxfFormat);
setCodePage(cp, dxfFormat);
}
}
void DRW_TextCodec::setVersion(std::string *v, bool dxfFormat){
std::string versionStr = *v;
void DRW_TextCodec::setVersion(const std::string &versionStr, bool dxfFormat){
if (versionStr == "AC1009" || versionStr == "AC1006") {
setVersion(DRW::AC1009, dxfFormat);
} else if (versionStr == "AC1012" || versionStr == "AC1014"
@ -86,8 +83,8 @@ void DRW_TextCodec::setVersion(std::string *v, bool dxfFormat){
}
}
void DRW_TextCodec::setCodePage(const std::string *c, bool dxfFormat){
cp = correctCodePage(*c);
void DRW_TextCodec::setCodePage(const std::string &c, bool dxfFormat){
cp = correctCodePage(c);
if (version < DRW::AC1021)
{
if (cp == "UTF-8")

View File

@ -15,10 +15,9 @@ public:
std::string fromUtf8(const std::string &s);
std::string toUtf8(const std::string &s);
int getVersion() const {return version;}
void setVersion(std::string *v, bool dxfFormat);
void setVersion(const std::string &versionStr, bool dxfFormat);
void setVersion(int v, bool dxfFormat);
void setCodePage(const std::string *c, bool dxfFormat);
void setCodePage(const std::string &c, bool dxfFormat){setCodePage(&c, dxfFormat);}
void setCodePage(const std::string &c, bool dxfFormat);
std::string getCodePage() const {return cp;}
static QMap<QString, QStringList> DXFCodePageMap();
@ -30,8 +29,8 @@ private:
private:
Q_DISABLE_COPY(DRW_TextCodec)
int version;
std::string cp;
QTextCodec *conv;
std::string cp{};
QTextCodec *conv{nullptr};
};
#endif // DRW_TEXTCODEC_H

View File

@ -50,8 +50,8 @@ public:
unsigned long long int getInt64() const {return int64;}
bool getBool() const { return (intData==0) ? false : true;}
int getVersion() const {return decoder.getVersion();}
void setVersion(std::string *v, bool dxfFormat){decoder.setVersion(v, dxfFormat);}
void setCodePage(std::string *c){decoder.setCodePage(c, true);}
void setVersion(const std::string &v, bool dxfFormat){decoder.setVersion(v, dxfFormat);}
void setCodePage(const std::string &c){decoder.setCodePage(c, true);}
std::string getCodePage() const { return decoder.getCodePage();}
protected:

View File

@ -32,8 +32,8 @@ public:
virtual bool writeInt64(int code, unsigned long long int data) = 0;
virtual bool writeDouble(int code, double data) = 0;
virtual bool writeBool(int code, bool data) = 0;
void setVersion(std::string *v, bool dxfFormat){encoder.setVersion(v, dxfFormat);}
void setCodePage(std::string *c){encoder.setCodePage(c, true);}
void setVersion(const std::string &v, bool dxfFormat){encoder.setVersion(v, dxfFormat);}
void setCodePage(const std::string &c){encoder.setCodePage(c, true);}
std::string getCodePage() const {return encoder.getCodePage();}
protected:
std::ofstream *filestr;