summaryrefslogtreecommitdiff
path: root/lib_dxf/intern/dxfreader.h
blob: 845244955c4a3c217d6a4b3dff6d3c9f451f3665 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/******************************************************************************
**  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"

class dxfReader
{
public:
    dxfReader( std::ifstream* stream )
    {
        filestr = stream;
        doubleData = 0.0;
        intData = 0;
        int64 = 0;
#ifdef DRW_DBG
        count = 0;
#endif
    }

    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(); }
#ifdef DRW_DBG
    int count;    // DBG
#endif

protected:
    std::ifstream* filestr;
    std::string strData;
    double doubleData;
    signed int intData;             // 32 bits integer
    unsigned long long int int64;   // 64 bits integer

private:
    DRW_TextCodec decoder;
};

class dxfReaderBinary : public dxfReader
{
public:
    dxfReaderBinary( std::ifstream* stream ) : dxfReader( stream ) {}
    virtual ~dxfReaderBinary() {}
    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();
};

class dxfReaderAscii : public dxfReader
{
public:
    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();
};

#endif    // DXFREADER_H