dxfreader.h 3.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/******************************************************************************
**  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"

18 19
class dxfReader
{
20
public:
21 22
    dxfReader( std::ifstream* stream )
    {
23 24
        filestr = stream;
#ifdef DRW_DBG
25
        count = 0;
26 27
#endif
    }
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

    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 );
    virtual bool    readInt()       = 0;
    virtual bool    readInt32()     = 0;
    virtual bool    readInt64()     = 0;
    virtual bool    readDouble()    = 0;
    virtual bool    readBool()      = 0;

    std::string getString() { return strData; }
    int             getHandleString(); // Convert hex string to int

    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(); }
53
#ifdef DRW_DBG
54
    int                     count; // DBG
55 56
#endif
protected:
57 58 59 60 61
    std::ifstream*          filestr;
    std::string             strData;
    double                  doubleData;
    signed int              intData;    // 32 bits integer
    unsigned long long int  int64;      // 64 bits integer
62
private:
63
    DRW_TextCodec           decoder;
64 65
};

66 67
class dxfReaderBinary : public dxfReader
{
68
public:
69
    dxfReaderBinary( std::ifstream* stream ) : dxfReader( stream ) { }
70
    virtual ~dxfReaderBinary() {}
71 72 73 74 75 76 77 78
    virtual bool    readCode( int* code );
    virtual bool    readString( std::string* text );
    virtual bool    readString();
    virtual bool    readInt();
    virtual bool    readInt32();
    virtual bool    readInt64();
    virtual bool    readDouble();
    virtual bool    readBool();
79 80
};

81 82
class dxfReaderAscii : public dxfReader
{
83
public:
84 85 86 87 88 89 90 91 92 93
    dxfReaderAscii( std::ifstream* stream ) : dxfReader( stream ) { }
    virtual ~dxfReaderAscii() {}
    virtual bool    readCode( int* code );
    virtual bool    readString( std::string* text );
    virtual bool    readString();
    virtual bool    readInt();
    virtual bool    readDouble();
    virtual bool    readInt32();
    virtual bool    readInt64();
    virtual bool    readBool();
94 95
};

96
#endif    // DXFREADER_H