Wheefun I/O Library  0.0.5
Useful I/O Primitives.
iotype.h
Go to the documentation of this file.
1 /* WFIO - the Wheefun IO Library
2  Copyright (C) 2018 Phillip Kilgore
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <https://www.gnu.org/licenses/>.
16 
17  Additionally, you should have recieved a copy of the GNU Classpath
18  exception, which amends the license to generally permit linking against
19  the software provided herein.
20 */
21 
32 #ifndef WFIO_IOTYPE_H
33 #define WFIO_IOTYPE_H
34 
35 #include <stddef.h>
36 
38 
39 
40 #if defined(WFIO_COMPILER_DJGPP) | defined(WFIO_OS_BEOS) | defined(WFIO_OS_HAIKU)
41 #include <sys/types.h>
42 typedef off_t wfio_off_t;
43 /* Todo: under what circumstances can we assume this? */
44 #elif defined(WFIO_COMPILER_GCC)
45 #include <bits/types.h>
46 typedef __off_t wfio_off_t;
47 #else
48 typedef long int wfio_off_t;
49 #endif
50 
60 typedef enum wfio_whence_t {
68 
72 typedef enum wfio_openflag_t {
87 
88  /* Synthetic flags */
91 
99 
103 typedef int wfio_openmode_t;
104 
108 typedef int wfio_fd_t;
109 enum {
114 };
115 
116 /* Bounded types */
117 
118 struct wfio_device_t;
119 
120 struct wfio_iobuf_t;
121 
122 struct wfio_binstream_t;
123 
127 typedef enum wfio_peer_type_t {
135 
136 struct wfio_peer_t;
137 
138 enum {
144 
149 
154 
155  /* Masks */
156 
162 };
163 
167 typedef int wfio_ioshare_t;
168 
175 typedef enum {
184 
194 
201 
206 
220 } wfio_dcntl_t;
221 
222 enum {
226  WFIO_NPOS = (size_t) -1,
227 };
228 
230 
231 #ifdef __cplusplus
232 namespace wfio {
235 
238 
239  class Device;
240 
241  class IOBuf;
242 
243  class Peer;
244 
245  enum {
248  };
249 
253  struct IOShare {
255 
256  enum {
263 
264  /* Flags */
265 
268  };
269 
273  enum Ownership {
289  };
290 
294  int value;
295 
299  IOShare() throw() : value(0) {}
300 
304  IOShare(int value) throw() : value(value) {}
305 
306  /* Flags */
307 
311  Ownership ownership() const throw() {
312  return static_cast<Ownership>(value & M_OWNERSHIP);
313  }
314 
318  void ownership(Ownership ownership) throw() {
319  value &= ~M_OWNERSHIP;
320  value |= ownership;
321  }
322 
323  /* Conversion */
324 
328  inline operator int() const throw() {
329  return value;
330  }
331  };
332 
334  struct DCntl {
335 
339  enum Value {
349  DCNTL_TRUNCATE
350  };
351 
356 
358 
362  inline DCntl() throw() : value(DCNTL_GETFD) {}
363 
367  inline DCntl(Value value) throw() : value(value) {}
368 
372  inline DCntl(CType value) throw() :
373  value(static_cast<Value>(value)) {}
374 
382  inline bool operator == (DCntl rhs) const throw() {
383  return value == rhs.value;
384  }
385 
393  inline bool operator != (DCntl rhs) const throw() {
394  return value != rhs.value;
395  }
396 
402  inline operator CType() const throw() {
403  return static_cast<CType>(value);
404  }
405  };
406 }
407 
408 #endif
409 
410 #endif
The root namespace for WFIO.
Definition: bin.h:879
Definition: iotype.h:86
A command to be supplied to a device or similar stream.
Definition: iotype.h:334
An IOShare mask selecting the ownership mode for this mode.
Definition: iotype.h:161
Definition: iotype.h:90
WFIO_C_BEGIN typedef long int wfio_off_t
An integer corresponding to a device offset.
Definition: iotype.h:48
#define WFIO_C_BEGIN
Definition: host.h:477
int value
The literal value for this IOShare.
Definition: iotype.h:294
An ownership type corresponding to O_ACQUIRE.
Definition: iotype.h:283
Definition: iotype.h:129
Definition: iotype.h:78
Value
An acceptable value for a DCntl.
Definition: iotype.h:339
A generic stream encapsulation.
Definition: peer.h:44
Ownership
An ownership type for an IOShare.
Definition: iotype.h:273
Definition: iotype.h:247
Obtain the file&#39;s current file descriptor.
Definition: iotype.h:193
Definition: iotype.h:341
Definition: iotype.h:345
A constant representing a bad file descriptor.
Definition: iotype.h:113
DCntl(Value value)
Construct a DCntl from an explicit value.
Definition: iotype.h:367
Definition: iotype.h:84
Value value
The literal value of this DCntl.
Definition: iotype.h:355
Definition: iotype.h:131
wfio_openflag_t
A single flag for a wfio_openmode_t;.
Definition: iotype.h:72
wfio_whence_t
The type corresponding to the point of reference in a seek operation.
Definition: iotype.h:60
wfio_peer_type_t
The type associated with a peer.
Definition: iotype.h:127
An IOShare mode indicating that the stream is shared weakly.
Definition: iotype.h:258
An IO sharing mode.
Definition: iotype.h:253
Definition: iotype.h:62
Definition: iotype.h:66
int wfio_fd_t
The type corresponding a file descriptor.
Definition: iotype.h:108
wfio_dcntl_t
A command to be supplied to a device or similar stream.
Definition: iotype.h:175
Definition: iotype.h:133
DCntl()
Construct en empty DCntl.
Definition: iotype.h:362
An IOShare mode indicating that the stream is duplicated.
Definition: iotype.h:262
void ownership(Ownership ownership)
Set the ownership type of this IOShare.
Definition: iotype.h:318
A C++ wrapper for a wfio_device_t.
Definition: device.h:783
Obtain the file&#39;s current file descriptor.
Definition: iotype.h:343
Definition: iotype.h:76
A C++ wrapper for a wfio_iobuf_t.
Definition: iobuf.h:551
Definition: iotype.h:64
A stream intended for binary output.
Definition: bin.h:54
A constant indicating no position.
Definition: iotype.h:226
Definition: peer.h:396
DCntl(CType value)
Construct a DCntl from a CType.
Definition: iotype.h:372
Obtain the flags associated with this device.
Definition: iotype.h:205
#define WFIO_C_END
Definition: host.h:485
A simple, byte-oriented channel.
Definition: device.h:164
int wfio_ioshare_t
An I/O sharing mode.
Definition: iotype.h:167
The stream is both readable and writable.
Definition: iotype.h:97
Definition: iotype.h:82
Perform no operation.
Definition: iotype.h:183
An ownership type corresponding to O_DUP.
Definition: iotype.h:288
IOShare(int value)
Construct an IOShare from an explicit value.
Definition: iotype.h:304
An IOShare mode indicating that the stream is acquired.
Definition: iotype.h:148
An IOShare mode indicating that the stream is shared weakly.
Definition: iotype.h:143
Set the length of a device&#39;s backing store.
Definition: iotype.h:219
An IOShare mode indicating that the stream is duplicated.
Definition: iotype.h:153
::wfio_fd_t fd_t
The type corresponding a file descriptor.
Definition: iotype.h:237
An IOShare mask selecting the ownership mode for this mode.
Definition: iotype.h:267
An IOShare mode indicating that the stream is acquired.
Definition: iotype.h:260
IOShare()
Construct the default IOShare.
Definition: iotype.h:299
Attempt to change the flags associated with this device.
Definition: iotype.h:200
::wfio_off_t off_t
An integer corresponding to a device offset.
Definition: iotype.h:234
Definition: iotype.h:80
A generic I/O buffer.
Definition: iobuf.h:122
Ownership ownership() const
Obtain the ownership type from this IOShare.
Definition: iotype.h:311
Definition: iotype.h:74
Obtain the flags associated with this device.
Definition: iotype.h:347
An ownership type corresponding to O_WEAK.
Definition: iotype.h:278
int wfio_openmode_t
The type corresponding to an openmode.
Definition: iotype.h:103