Skip to content

Commit 74b0cfd

Browse files
committedAug 14, 2021
Partially sync some libdxfrw files with library version
1 parent fc306ed commit 74b0cfd

26 files changed

+1012
-1168
lines changed
 

‎external/libdxfrw/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include_directories(SYSTEM
44
)
55

66
add_library(libdxfrw STATIC
7+
drw_base.cpp
78
drw_classes.cpp
89
drw_entities.cpp
910
drw_header.cpp

‎external/libdxfrw/drw_base.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/******************************************************************************
2+
** libDXFrw - Library to read/write DXF files (ascii & binary) **
3+
** **
4+
** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com **
5+
** **
6+
** This library is free software, licensed under the terms of the GNU **
7+
** General Public License as published by the Free Software Foundation, **
8+
** either version 2 of the License, or (at your option) any later version. **
9+
** You should have received a copy of the GNU General Public License **
10+
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
11+
******************************************************************************/
12+
13+
#include "drw_base.h"
14+
#include "intern/drw_dbg.h"
15+
16+
void DRW::setCustomDebugPrinter(DebugPrinter *printer)
17+
{
18+
DRW_dbg::getInstance()->setCustomDebugPrinter(std::unique_ptr<DebugPrinter>(printer));
19+
}
20+
21+
DRW::DebugPrinter::~DebugPrinter() = default;

‎external/libdxfrw/drw_base.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,37 @@ namespace DRW
100100
BAD_READ_OBJECTS //!< Error in objects read process.
101101
};
102102

103-
enum DBG_LEVEL
104-
{
105-
none,
106-
debug
103+
enum class DebugLevel {
104+
None,
105+
Debug
107106
};
108107

108+
/**
109+
* Interface for debug printers.
110+
*
111+
* The base class is silent and ignores all debugging.
112+
*/
113+
class DebugPrinter {
114+
public:
115+
virtual void printS(const std::string &s){(void)s;}
116+
virtual void printI(long long int i){(void)i;}
117+
virtual void printUI(long long unsigned int i){(void)i;}
118+
virtual void printD(double d){(void)d;}
119+
virtual void printH(long long int i){(void)i;}
120+
virtual void printB(int i){(void)i;}
121+
virtual void printHL(int c, int s, int h){(void)c;(void)s;(void)h;}
122+
virtual void printPT(double x, double y, double z){(void)x;(void)y;(void)z;}
123+
DebugPrinter()=default;
124+
virtual ~DebugPrinter();
125+
};
126+
127+
/**
128+
* Sets a custom debug printer to use when outputting debug messages.
129+
*
130+
* Ownership of `printer` is transferred.
131+
*/
132+
void setCustomDebugPrinter( DebugPrinter* printer );
133+
109134
//! Special codes for colors
110135
enum ColorCodes
111136
{

‎external/libdxfrw/drw_header.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void DRW_Header::parseCode( int code, dxfReader *reader )
7777
curr->addString( code, reader->getUtf8String() );
7878
if ( name == "$ACADVER" )
7979
{
80-
reader->setVersion( curr->content.s, true );
80+
reader->setVersion( *curr->content.s, true );
8181
version = reader->getVersion();
8282
}
8383
break;
@@ -88,7 +88,7 @@ void DRW_Header::parseCode( int code, dxfReader *reader )
8888
curr->addString( code, reader->getUtf8String() );
8989
if ( name == "$DWGCODEPAGE" )
9090
{
91-
reader->setCodePage( curr->content.s );
91+
reader->setCodePage( *curr->content.s );
9292
curr->addString( code, reader->getCodePage() );
9393
}
9494
break;
@@ -181,7 +181,7 @@ void DRW_Header::write( dxfWriter *writer, DRW::Version ver )
181181
break;
182182
}
183183
writer->writeString( 1, varStr );
184-
writer->setVersion( &varStr, true );
184+
writer->setVersion( varStr, true );
185185

186186
getStr( "$ACADVER", &varStr );
187187
getStr( "$ACADMAINTVER", &varStr );
@@ -191,7 +191,7 @@ void DRW_Header::write( dxfWriter *writer, DRW::Version ver )
191191
varStr = "ANSI_1252";
192192
}
193193
writer->writeString( 9, "$DWGCODEPAGE" );
194-
writer->setCodePage( &varStr );
194+
writer->setCodePage( varStr );
195195
writer->writeString( 3, writer->getCodePage() );
196196
writer->writeString( 9, "$INSBASE" );
197197
if ( getCoord( "$INSBASE", &varCoord ) )

‎external/libdxfrw/intern/drw_dbg.cpp

Lines changed: 62 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -21,131 +21,102 @@
2121
DRW_dbg *DRW_dbg::instance = nullptr;
2222

2323
/*********private classes*************/
24-
class print_none
25-
{
26-
public:
27-
virtual void printS( std::string s ) {( void )s;}
28-
virtual void printI( long long int i ) {( void )i;}
29-
virtual void printUI( long long unsigned int i ) {( void )i;}
30-
virtual void printD( double d ) {( void )d;}
31-
virtual void printH( long long int i ) {( void )i;}
32-
virtual void printB( int i ) {( void )i;}
33-
virtual void printHL( int c, int s, int h ) {( void )c; ( void )s; ( void )h;}
34-
virtual void printPT( double x, double y, double z ) {( void )x; ( void )y; ( void )z;}
35-
print_none() {}
36-
virtual ~print_none() = default;
37-
};
38-
39-
class print_debug : public print_none
40-
{
41-
public:
42-
virtual void printS( std::string s );
43-
virtual void printI( long long int i );
44-
virtual void printUI( long long unsigned int i );
45-
virtual void printD( double d );
46-
virtual void printH( long long int i );
47-
virtual void printB( int i );
48-
virtual void printHL( int c, int s, int h );
49-
virtual void printPT( double x, double y, double z );
50-
print_debug();
51-
virtual ~print_debug() { QgsDebugMsgLevel( mBuf, 5 ); }
52-
private:
24+
class print_debug : public DRW::DebugPrinter {
25+
public:
26+
void printS(const std::string& s) override;
27+
void printI(long long int i) override;
28+
void printUI(long long unsigned int i) override;
29+
void printD(double d) override;
30+
void printH(long long int i) override;
31+
void printB(int i) override;
32+
void printHL(int c, int s, int h) override;
33+
void printPT(double x, double y, double z) override;
34+
~print_debug() override { QgsDebugMsgLevel( mBuf, 5 ); }
35+
private:
36+
std::ios_base::fmtflags flags{std::cerr.flags()};
5337
QString mBuf;
5438
QTextStream mTS;
5539
void flush();
5640
};
5741

5842
/********* debug class *************/
59-
DRW_dbg *DRW_dbg::getInstance()
60-
{
61-
if ( !instance )
62-
{
63-
instance = new DRW_dbg;
64-
}
65-
return instance;
43+
DRW_dbg *DRW_dbg::getInstance(){
44+
if (!instance){
45+
instance = new DRW_dbg;
46+
}
47+
return instance;
6648
}
6749

68-
DRW_dbg::DRW_dbg()
69-
{
70-
level = none;
71-
prClass = new print_none;
50+
DRW_dbg::DRW_dbg(){
51+
debugPrinter.reset(new print_debug);
52+
currentPrinter = &silentDebug;
7253
}
7354

74-
void DRW_dbg::setLevel( LEVEL lvl )
55+
void DRW_dbg::setCustomDebugPrinter(std::unique_ptr<DRW::DebugPrinter> printer)
7556
{
76-
level = lvl;
77-
delete prClass;
78-
switch ( level )
79-
{
80-
case debug:
81-
prClass = new print_debug;
82-
break;
83-
default:
84-
prClass = new print_none;
85-
}
57+
debugPrinter = std::move( printer );
58+
if (level == Level::Debug){
59+
currentPrinter = debugPrinter.get();
60+
}
8661
}
8762

88-
DRW_dbg::LEVEL DRW_dbg::getLevel()
89-
{
90-
return level;
63+
void DRW_dbg::setLevel(Level lvl){
64+
level = lvl;
65+
switch (level){
66+
case Level::Debug:
67+
currentPrinter = debugPrinter.get();
68+
break;
69+
case Level::None:
70+
currentPrinter = &silentDebug;
71+
break;
72+
}
9173
}
9274

93-
void DRW_dbg::print( std::string s )
94-
{
95-
prClass->printS( s );
75+
DRW_dbg::Level DRW_dbg::getLevel(){
76+
return level;
9677
}
9778

98-
void DRW_dbg::print( int i )
99-
{
100-
prClass->printI( i );
79+
void DRW_dbg::print(const std::string &s){
80+
currentPrinter->printS(s);
10181
}
10282

103-
void DRW_dbg::print( unsigned int i )
104-
{
105-
prClass->printUI( i );
83+
void DRW_dbg::print(int i){
84+
currentPrinter->printI(i);
10685
}
10786

108-
void DRW_dbg::print( long long int i )
109-
{
110-
prClass->printI( i );
87+
void DRW_dbg::print(unsigned int i){
88+
currentPrinter->printUI(i);
11189
}
11290

113-
void DRW_dbg::print( long unsigned int i )
114-
{
115-
prClass->printUI( i );
91+
void DRW_dbg::print(long long int i){
92+
currentPrinter->printI(i);
11693
}
11794

118-
void DRW_dbg::print( long long unsigned int i )
119-
{
120-
prClass->printUI( i );
95+
void DRW_dbg::print(long unsigned int i){
96+
currentPrinter->printUI(i);
12197
}
12298

123-
void DRW_dbg::print( double d )
124-
{
125-
prClass->printD( d );
99+
void DRW_dbg::print(long long unsigned int i){
100+
currentPrinter->printUI(i);
126101
}
127102

128-
void DRW_dbg::printH( long long int i )
129-
{
130-
prClass->printH( i );
103+
void DRW_dbg::print(double d){
104+
currentPrinter->printD(d);
131105
}
132106

133-
void DRW_dbg::printB( int i )
134-
{
135-
prClass->printB( i );
136-
}
137-
void DRW_dbg::printHL( int c, int s, int h )
138-
{
139-
prClass->printHL( c, s, h );
107+
void DRW_dbg::printH(long long int i){
108+
currentPrinter->printH(i);
140109
}
141110

142-
void DRW_dbg::printPT( double x, double y, double z )
143-
{
144-
prClass->printPT( x, y, z );
111+
void DRW_dbg::printB(int i){
112+
currentPrinter->printB(i);
113+
}
114+
void DRW_dbg::printHL(int c, int s, int h){
115+
currentPrinter->printHL(c, s, h);
145116
}
146117

147-
print_debug::print_debug() : mTS( &mBuf )
148-
{
118+
void DRW_dbg::printPT(double x, double y, double z){
119+
currentPrinter->printPT(x, y, z);
149120
}
150121

151122
void print_debug::flush()
@@ -158,7 +129,7 @@ void print_debug::flush()
158129
mBuf = lines.last();
159130
}
160131

161-
void print_debug::printS( std::string s )
132+
void print_debug::printS( const std::string& s )
162133
{
163134
mTS << QString::fromStdString( s );
164135
flush();

‎external/libdxfrw/intern/drw_dbg.h

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#include <string>
1717
#include <iostream>
18+
#include <memory>
19+
#include "../drw_base.h"
20+
//#include <iomanip>
1821

1922
#define DRW_DBGSL(a) DRW_dbg::getInstance()->setLevel(a)
2023
#define DRW_DBGGL DRW_dbg::getInstance()->getLevel()
@@ -24,37 +27,39 @@
2427
#define DRW_DBGHL(a, b, c) DRW_dbg::getInstance()->printHL(a, b ,c)
2528
#define DRW_DBGPT(a, b, c) DRW_dbg::getInstance()->printPT(a, b, c)
2629

27-
28-
class print_none;
29-
30-
class DRW_dbg
31-
{
32-
public:
33-
enum LEVEL
34-
{
35-
none,
36-
debug
30+
class DRW_dbg {
31+
public:
32+
enum class Level {
33+
None,
34+
Debug
3735
};
38-
void setLevel( LEVEL lvl );
39-
LEVEL getLevel();
36+
void setLevel(Level lvl);
37+
/**
38+
* Sets a custom debug printer to use when non-silent output
39+
* is required.
40+
*/
41+
void setCustomDebugPrinter(std::unique_ptr<DRW::DebugPrinter> printer);
42+
Level getLevel();
4043
static DRW_dbg *getInstance();
41-
void print( std::string s );
42-
void print( int i );
43-
void print( unsigned int i );
44-
void print( long long int i );
45-
void print( long unsigned int i );
46-
void print( long long unsigned int i );
47-
void print( double d );
48-
void printH( long long int i );
49-
void printB( int i );
50-
void printHL( int c, int s, int h );
51-
void printPT( double x, double y, double z );
44+
void print(const std::string& s);
45+
void print(int i);
46+
void print(unsigned int i);
47+
void print(long long int i);
48+
void print(long unsigned int i);
49+
void print(long long unsigned int i);
50+
void print(double d);
51+
void printH(long long int i);
52+
void printB(int i);
53+
void printHL(int c, int s, int h);
54+
void printPT(double x, double y, double z);
5255

53-
private:
56+
private:
5457
DRW_dbg();
5558
static DRW_dbg *instance;
56-
LEVEL level;
57-
print_none *prClass = nullptr;
59+
Level level{Level::None};
60+
DRW::DebugPrinter silentDebug;
61+
std::unique_ptr< DRW::DebugPrinter > debugPrinter;
62+
DRW::DebugPrinter* currentPrinter{nullptr};
5863
};
5964

6065

0 commit comments

Comments
 (0)
Please sign in to comment.