2013-10-24 16:44:38 +00:00
|
|
|
/******************************************************************************
|
|
|
|
** libDXFrw - Library to read/write DXF files (ascii & binary) **
|
|
|
|
** **
|
|
|
|
** Copyright (C) 2011 Rallaz, rallazz@gmail.com **
|
|
|
|
** **
|
|
|
|
** This library is free software, licensed under the terms of the GNU **
|
|
|
|
** General Public License as published by the Free Software Foundation, **
|
|
|
|
** either version 2 of the License, or (at your option) any later version. **
|
|
|
|
** You should have received a copy of the GNU General Public License **
|
|
|
|
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef DXFREADER_H
|
|
|
|
#define DXFREADER_H
|
|
|
|
|
|
|
|
#include "drw_textcodec.h"
|
|
|
|
|
2013-10-28 08:06:38 +00:00
|
|
|
class dxfReader
|
|
|
|
{
|
2013-10-24 16:44:38 +00:00
|
|
|
public:
|
2013-10-28 08:06:38 +00:00
|
|
|
dxfReader( std::ifstream* stream )
|
|
|
|
{
|
2013-10-24 16:44:38 +00:00
|
|
|
filestr = stream;
|
2015-02-24 09:07:40 +00:00
|
|
|
doubleData = 0.0;
|
|
|
|
intData = 0;
|
|
|
|
int64 = 0;
|
2013-10-24 16:44:38 +00:00
|
|
|
#ifdef DRW_DBG
|
2013-10-28 08:06:38 +00:00
|
|
|
count = 0;
|
2013-10-24 16:44:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
2013-10-28 08:06:38 +00:00
|
|
|
|
|
|
|
virtual ~dxfReader() {}
|
|
|
|
virtual bool readCode( int* code ) = 0; // return true if sucesful (not EOF)
|
|
|
|
virtual bool readString( std::string* text ) = 0;
|
|
|
|
virtual bool readString() = 0;
|
|
|
|
bool readRec( int* code, bool skip );
|
2015-02-24 09:07:40 +00:00
|
|
|
virtual bool readInt() = 0;
|
2013-10-28 08:06:38 +00:00
|
|
|
virtual bool readInt32() = 0;
|
|
|
|
virtual bool readInt64() = 0;
|
|
|
|
virtual bool readDouble() = 0;
|
2015-02-24 09:07:40 +00:00
|
|
|
virtual bool readBool() = 0;
|
2013-10-28 08:06:38 +00:00
|
|
|
|
|
|
|
std::string getString() { return strData; }
|
2015-02-24 09:07:40 +00:00
|
|
|
int getHandleString(); // Convert hex string to int
|
2013-10-28 08:06:38 +00:00
|
|
|
|
|
|
|
std::string toUtf8String( std::string t ) { return decoder.toUtf8( t ); }
|
|
|
|
std::string getUtf8String() { return decoder.toUtf8( strData ); }
|
|
|
|
double getDouble() { return doubleData; }
|
|
|
|
int getInt32() { return intData; }
|
|
|
|
unsigned long long int getInt64() { return int64; }
|
|
|
|
bool getBool() { return (intData==0) ? false : true; }
|
|
|
|
int getVersion() { return decoder.getVersion(); }
|
|
|
|
void setVersion( std::string* v ) { decoder.setVersion( v ); }
|
|
|
|
void setCodePage( std::string* c ) { decoder.setCodePage( c ); }
|
|
|
|
std::string getCodePage() { return decoder.getCodePage(); }
|
2013-10-24 16:44:38 +00:00
|
|
|
#ifdef DRW_DBG
|
2015-02-24 09:07:40 +00:00
|
|
|
int count; // DBG
|
2013-10-24 16:44:38 +00:00
|
|
|
#endif
|
2015-02-24 09:07:40 +00:00
|
|
|
|
2013-10-24 16:44:38 +00:00
|
|
|
protected:
|
2015-02-24 09:07:40 +00:00
|
|
|
std::ifstream* filestr;
|
|
|
|
std::string strData;
|
|
|
|
double doubleData;
|
|
|
|
signed int intData; // 32 bits integer
|
|
|
|
unsigned long long int int64; // 64 bits integer
|
|
|
|
|
2013-10-24 16:44:38 +00:00
|
|
|
private:
|
2015-02-24 09:07:40 +00:00
|
|
|
DRW_TextCodec decoder;
|
2013-10-24 16:44:38 +00:00
|
|
|
};
|
|
|
|
|
2013-10-28 08:06:38 +00:00
|
|
|
class dxfReaderBinary : public dxfReader
|
|
|
|
{
|
2013-10-24 16:44:38 +00:00
|
|
|
public:
|
2015-02-24 09:07:40 +00:00
|
|
|
dxfReaderBinary( std::ifstream* stream ) : dxfReader( stream ) {}
|
2013-10-24 16:44:38 +00:00
|
|
|
virtual ~dxfReaderBinary() {}
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual bool readCode( int* code ) override;
|
|
|
|
virtual bool readString( std::string* text ) override;
|
|
|
|
virtual bool readString() override;
|
|
|
|
virtual bool readInt() override;
|
|
|
|
virtual bool readInt32() override;
|
|
|
|
virtual bool readInt64() override;
|
|
|
|
virtual bool readDouble() override;
|
|
|
|
virtual bool readBool() override;
|
2013-10-24 16:44:38 +00:00
|
|
|
};
|
|
|
|
|
2013-10-28 08:06:38 +00:00
|
|
|
class dxfReaderAscii : public dxfReader
|
|
|
|
{
|
2013-10-24 16:44:38 +00:00
|
|
|
public:
|
2015-02-24 09:07:40 +00:00
|
|
|
dxfReaderAscii( std::ifstream* stream ) : dxfReader( stream ) {}
|
2013-10-28 08:06:38 +00:00
|
|
|
virtual ~dxfReaderAscii() {}
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual bool readCode( int* code ) override;
|
|
|
|
virtual bool readString( std::string* text ) override;
|
|
|
|
virtual bool readString() override;
|
|
|
|
virtual bool readInt() override;
|
|
|
|
virtual bool readDouble() override;
|
|
|
|
virtual bool readInt32() override;
|
|
|
|
virtual bool readInt64() override;
|
|
|
|
virtual bool readBool() override;
|
2013-10-24 16:44:38 +00:00
|
|
|
};
|
|
|
|
|
2013-10-28 08:06:38 +00:00
|
|
|
#endif // DXFREADER_H
|