dime  0.9.1
Portable DXF file library
Loading...
Searching...
No Matches
Input.h
1/**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31\**************************************************************************/
32
33#ifndef DIME_INPUT_H
34#define DIME_INPUT_H
35
36#include <dime/Basic.h>
37#include <dime/util/Array.h>
38
39#define DXF_MAXLINELEN 4096
40
41class DIME_DLL_API dimeInput
42{
43public:
44 dimeInput();
45 ~dimeInput();
46
47 bool setFileHandle(FILE *fp);
48 bool setFile(const char * const filename);
49 bool setFilePointer(const int fd);
50 bool eof() const;
51 void setCallback(int (*cb)(float, void *), void *cbdata);
52 float relativePosition();
53
54 void putBackGroupCode(const int32 code);
55 bool readGroupCode(int32 &code);
56 bool readInt8(int8 &val);
57 bool readInt16(int16 &val);
58 bool readInt32(int32 &val);
59 bool readFloat(float &val);
60 bool readDouble(dxfdouble &val);
61 const char *readString();
62 const char *readStringNoSkip();
63
64 class dimeModel *getModel();
65 class dimeMemHandler *getMemHandler();
66
67 int getFilePosition() const;
68
69 bool isBinary() const;
70 int getVersion() const;
71 bool isAborted() const;
72
73private:
74 friend class dimeModel;
75 dimeModel *model; // set by the dimeModel class.
76 int filePosition;
77 bool binary;
78 bool binary16bit;
79 int version;
80
81 int fd;
82#ifdef USE_GZFILE
83 void *gzfp; // gzip file pointer
84 bool gzeof;
85#else // ! USE_GZFILE
86 FILE *fp;
87 bool fpeof;
88#endif // ! USE_GZFILE
89 long filesize;
90 char *readbuf;
91 int readbufIndex;
92 int readbufLen;
93
94 dimeArray <char> backBuf;
95 int backBufIndex;
96
97 char lineBuf[DXF_MAXLINELEN];
98 int32 putBackCode;
99 bool hasPutBack;
100 int (*callback)(float, void*);
101 void *callbackdata;
102 float prevposition;
103 int cbcnt;
104 bool aborted;
105 bool prevwashandle;
106 bool didOpenFile;
107 bool endianSwap;
108
109private:
110 bool init();
111 bool doBufferRead();
112 void putBack(const char c);
113 void putBack(const char * const string);
114 bool get(char &c);
115 bool read(char &c);
116 bool skipWhiteSpace();
117 bool nextLine();
118 bool readInteger(long &l);
119 bool readUnsignedInteger(unsigned long &l);
120 bool readUnsignedIntegerString(char * const str);
121 int readDigits(char * const string);
122 int readHexDigits(char * const string);
123 int readChar(char * const string, char charToRead);
124 bool readReal(dxfdouble &d);
125 bool checkBinary();
126}; // class dimeInput
127
128#endif // ! DIME_INPUT_H
129
The dimeInput class offers transparent file I/O for DXF and DXB.
Definition Input.h:42
The dimeMemHandler class is a special-purpose memory manager.
Definition MemHandler.h:39
The dimeModel class organizes a model.
Definition Model.h:55