-
Notifications
You must be signed in to change notification settings - Fork 1
/
ftype.h
104 lines (91 loc) · 2.82 KB
/
ftype.h
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
// -*- mode:c++ -*-
#ifndef ICI_FTYPE_H
#define ICI_FTYPE_H
#include "fwd.h"
namespace ici
{
/*
* The following portion of this file exports to ici.h. --ici.h-start--
*/
/*
* A set of functions for file access. ICI file objects are implemented
* on top of this simple file abstraction in order to allow several
* different types of file-like entities. Each different type of file
* uses one of these structures with specific functions. Each function is
* assumed to be compatible with the stdio function of the same name. In the
* case were the file is a stdio stream, these *are* the stdio functions.
*
* See also: 'stdio_ftype', 'popen_ftype', 'parse_ftype' et al.
*
* This --class-- forms part of the --ici-api--.
*/
class ftype
{
public:
/*
* The flags that may appear in flags. NOTE: If any flag greater than 0x80
* is specified, file creation with new_file() will fail. See that
* function for details.
*
* nomutex ICI will surround file I/O on this file with
* leave()/enter(). Using this flag can increase
* efficiency by allowing other threads to run during a
* blocking I/O operation; however it must NOT be used if
* the file's I/O functions can access ICI data.
*
* --ici-api-- continued.
*/
static constexpr int nomutex = 0x01;
protected:
ftype(int flags = 0)
: flags(flags)
{
}
public:
virtual ~ftype()
{
}
virtual int getch(void *);
virtual int ungetch(int, void *);
virtual int flush(void *);
virtual int close(void *);
virtual long seek(void *, long, int);
virtual int eof(void *);
virtual int read(void *, long, void *);
virtual int write(const void *, long, void *);
virtual int fileno(void *);
virtual int setvbuf(void *, char *, int, size_t);
const int flags;
};
/*
* flags A combination of * flags, defined above.
*/
class stdio_ftype : public ftype
{
public:
stdio_ftype();
virtual int getch(void *) override;
virtual int ungetch(int, void *) override;
virtual int flush(void *) override;
virtual int close(void *) override;
virtual long seek(void *, long, int) override;
virtual int eof(void *) override;
virtual int read(void *, long, void *) override;
virtual int write(const void *, long, void *) override;
virtual int fileno(void *) override;
virtual int setvbuf(void *, char *, int, size_t) override;
};
/*
* The ftype for pipes is just a stdio ftype that uses pclose()
* for its close implementation and checks the returned exit status.
*/
class popen_ftype : public stdio_ftype
{
public:
virtual int close(void *) override;
};
/*
* End of ici.h export. --ici.h-end--
*/
} // namespace ici
#endif