forked from ViewTouch/viewtouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_file.hh
172 lines (143 loc) · 4.72 KB
/
data_file.hh
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* Copyright ViewTouch, Inc., 1995, 1996, 1997, 1998
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* data_file.hh - revision 15 (8/25/98)
* Functions for the reading & writing of data files
*/
#ifndef _DATA_FILE_HH
#define _DATA_FILE_HH
#include "utility.hh"
#include <zlib.h>
#define BLOCKSIZE 16384
/**** Types ****/
/*********************************************************************
* InputDataFile:
********************************************************************/
class InputDataFile
{
gzFile fp;
int old_format;
char filename[STRLONG];
public:
int end_of_file;
// Constructor
InputDataFile();
// Destructor
~InputDataFile() { Close(); }
// Member Functions
int Open(const char* filename, int &version);
int Close();
int GetToken(char* buffer, int max_len = 0);
unsigned long long GetValue();
int Read(char &val) { val = (char) GetValue(); return 0; }
int Read(Uchar &val) { val = (Uchar) GetValue(); return 0; }
int Read(short &val) { val = (short) GetValue(); return 0; }
int Read(Ushort &val) { val = (Ushort) GetValue(); return 0; }
int Read(int &val) { val = (int) GetValue(); return 0; }
int Read(Uint &val) { val = (Uint) GetValue(); return 0; }
int Read(long long &val) { val = GetValue(); return 0; }
int Read(Flt &val);
int Read(Str &val);
int Read(TimeInfo &val);
// conditional reads (won't read if pointer is NULL)
int Read(int *val);
int Read(Flt *val);
int Read(Str *val);
int PeekTokens();
const char* ShowTokens(char* buffer = NULL, int lines = 1);
const char* FileName() { return filename; }
};
/*********************************************************************
* OutputDataFile
********************************************************************/
class OutputDataFile
{
void *fp;
int compress;
char filename[STRLONG];
public:
// Constructor
OutputDataFile();
// Destructor
~OutputDataFile() { Close(); }
// Member Functions
int Open(const char* filename, int version, int use_compression = 0);
int Close();
int PutValue(unsigned long long val, int bk);
int Write(short val, int bk = 0) { return PutValue((long long) val, bk); }
int Write(int val, int bk = 0) { return PutValue((long long) val, bk); }
int Write(long long val, int bk = 0) { return PutValue(val, bk); }
int Write(Str &val, int bk = 0) { return Write(val.Value(), bk); }
int Write(Flt val, int bk = 0);
int Write(TimeInfo &val, int bk = 0);
// conditional writes (won't write if pointer is NULL)
int Write(int *val, int bk = 0);
int Write(const char* val, int bk = 0);
int Write(Flt *val, int bk = 0);
int Write(Str *val, int bk = 0);
const char* FileName() { return filename; }
};
/*********************************************************************
* KeyValueInputFile:
********************************************************************/
class KeyValueInputFile
{
private:
int filedes;
int bytesread;
int keyidx;
int validx;
int buffidx;
int comment;
int getvalue;
char delimiter;
char buffer[BLOCKSIZE];
char inputfile[STRLONG];
public:
KeyValueInputFile();
KeyValueInputFile(int fd);
KeyValueInputFile(const char* filename);
int Open();
int Open(const char* filename);
int IsOpen();
int Set(int fd);
int Set(const char* filename);
char SetDelim(char delim);
int Close();
int Reset();
int Read(char* key, char* value, int maxlen);
};
/*********************************************************************
* KeyValueOutputFile:
********************************************************************/
class KeyValueOutputFile
{
private:
int filedes;
char delimiter;
char outputfile[STRLONG];
public:
KeyValueOutputFile();
KeyValueOutputFile(int fd);
KeyValueOutputFile(const char* filename);
int Open();
int Open(const char* filename);
int IsOpen();
char SetDelim(char delim);
int Close();
int Reset();
int Write(const char* key, const char* value);
};
#endif