-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproios.h
More file actions
241 lines (183 loc) · 5.56 KB
/
proios.h
File metadata and controls
241 lines (183 loc) · 5.56 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
IL : Intlog Language
Object Oriented Prolog Project
Copyright (C) 1992-2021 - Ing. Capelli Carlo
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 2 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef PROIOS_H_
#define PROIOS_H_
//---------------------------------------------------------------
// Intlog named streams model:
//
// high level constructs for Term(s) read and a polymorphic
// data interface, that can fetch data from source stream files
// or binary format libraries.
//
// These libraries are fully transparent and built 'at once',
// saving data while source input file are scanned.
//---------------------------------------------------------------
#include "iafx.h"
#include "term.h"
class IntlogExec; // forward decl
class IntlogStream; // a named stream
class IntlogIStream; // for input
class IntlogOStream; // for output
class IntlogIOStreams; // IO modelling
class SourceBinaryLib; // binary files libraries
//////////////////////////////////////
// a named stream for input or output
//
class IAFX_API IntlogStream : e_slist {
public:
virtual ~IntlogStream();
// keep identifier
kstring name() const {
return ident;
}
enum mode { input, output, none };
mode get_mode() const {
return md;
}
virtual void close() {}
protected:
IntlogStream(kstring id, mode m) {
ident = id;
md = m;
}
kstring ident;
mode md;
friend class IntlogIOStreams;
};
/////////////////////////////////////////
// for input: derive actual term readers
//
class IntlogIStream : public IntlogStream {
public:
virtual ~IntlogIStream() override;
virtual int ateof() const = 0;
// term reading
enum readResult {
NewClause,
RedoCommand,
EndFile,
Error
};
virtual readResult read() = 0;
// these keep data after a read OK
Term t_data;
kstr_list t_vars;
virtual int get() = 0;
protected:
IntlogIStream(kstring id) : IntlogStream(id, input) {
}
istream *i;
friend class IntlogIOStreams;
};
///////////////////////////
// for output: dummy class
//
class IntlogOStream : public IntlogStream {
virtual ~IntlogOStream() override;
IntlogOStream(kstring id, ostream* s) : IntlogStream(id, output) {
o = s;
}
ostream* o;
friend class IntlogIOStreams;
};
///////////////////////////////////////
// a model for prolog named streams
// mimic te same calls used in prolog
//
class IAFX_API IntlogIOStreams {
public:
IntlogIOStreams() {
currinp = nullptr;
currout = nullptr;
}
virtual ~IntlogIOStreams();
void closeall();
// console identify
static kstring name() {
return user;
}
static void setuser(kstring console, kstring searchpath) {
user = console;
envar = searchpath;
}
// input control
int seeing(kstring id) const {
return id == currinp->ident;
}
int see(kstring name, int flags = 0);
int seen();
IntlogIStream *ips() const{
return currinp;
}
istream& inp() const;
// find by name
IntlogStream *isin(kstring ident, IntlogStream::mode = IntlogStream::none) const;
// output control
int telling(kstring id) const {
return id == currout->ident;
}
int tell(kstring name, int flags = 0);
int told();
IntlogOStream *ops() const {
return currout;
}
ostream& out() const {
return *currout->o;
}
// in-memory files support
void NewBuffer(kstring name);
void DelBuffer(kstring name);
bool IsBuffer(kstring name) const;
const char *GetBuffer(kstring name);
void SetBuffer(kstring name, const char *value);
// binary library control
static void CreateBinLib(kstring);
static void AddBinLibSourceName(kstring);
static void ReadFromBinLib(kstring);
static void ReleaseBinLib();
// open file buf (avoid a problem arise from WINDLL streams...)
static filebuf *openfile(kstring id, int of, char *path = nullptr, char *buf = nullptr, int maxbuf = -1);
static kstring envar;
static void setenvar(kstring var) {
envar = var;
}
static kstring getenvar() {
return envar;
}
protected:
// keep the name of default IO streams (console)
static kstring user;
// open/close the stream as input
virtual istream *openinp(kstring* name, int flags) = 0;
virtual void close(istream*, kstring) = 0;
// open/close the stream as output
virtual ostream *openout(kstring name, int flags) = 0;
virtual void close(ostream*, kstring) = 0;
// current IO ports
IntlogIStream *currinp;
IntlogOStream *currout;
// local opened streams
slist opened;
void closestream(IntlogStream *s);
IntlogIStream *create_input_file(kstring ident, int flags);
virtual void openedbin(kstring) {}
// keep memory buffers
slist membuffer;
// binary lib control
static SourceBinaryLib* sbl;
};
#endif