Wheefun I/O Library  0.0.5
Useful I/O Primitives.
bin.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 
22 #ifndef WFIO_BIN_H
23 #define WFIO_BIN_H
24 
25 #include <wfio/device.h>
26 #include <wfio/ieee754.h>
27 
40 
54 typedef struct wfio_binstream_t {
55  wfio_endian_t endian;
56  wfio_endian_t floatEndian;
57  int ecode;
58  const size_t refcount;
60 
61 /* Creation and destruction */
62 
63 #if 0
64 
79 WFIO_DLL wfio_binstream_t* wfio_binstream_createEx(
80  struct wfio_peer_t peer, wfio_endian_t endian, int* error);
81 
97 WFIO_ALWAYS_INLINE wfio_binstream_t* wfio_binstream_create(
98  struct wfio_peer_t peer, int* error) {
99  return wfio_binstream_fromPeerEx(peer, WFIO_ENDIAN_HOST, error);
100 }
101 #endif
102 
120  struct wfio_device_t* device, wfio_endian_t endian, int* error);
121 
138  struct wfio_device_t* device, int* error) {
140  error);
141 }
142 
159  wfio_binstream_t* bin, int ioshare);
160 
178 
189 
206  wfio_binstream_t* bin);
207 
219 
233  wfio_off_t offset, wfio_whence_t whence);
234 
243 
255 
256 
257 
279  wfio_dcntl_t cmd, va_list va);
280 
305  wfio_dcntl_t cmd, ...) {
306  register int ret;
307  va_list va;
308  va_start(va, cmd);
309  ret = wfio_binstream_dcntl(bin, cmd, va);
310  va_end(va);
311  return ret;
312 }
313 
334  int cmd, va_list va);
335 
358  int cmd, ...) {
359  register int ret;
360  va_list va;
361  va_start(va, cmd);
362  ret = wfio_binstream_ioctl(bin, cmd, va);
363  va_end(va);
364  return ret;
365 }
366 
379 
403  size_t sz);
404 
405 /* Basic operations */
406 
417 WFIO_DLL size_t wfio_binstream_read(wfio_binstream_t* bin, void* buf,
418  size_t sz, size_t elem);
419 
430  void* buf, size_t len) {
431  return wfio_binstream_read(bin, buf, 1, len);
432 }
433 
442  unsigned char ret;
443  if (wfio_binstream_read(bin, &ret, 1, 1) != -1)
444  return ret;
445  else
446  return -1;
447 }
448 
463  const void* buf, size_t sz, size_t elem);
464 
478  const void* buf, size_t len) {
479  return wfio_binstream_write(bin, buf, 1, len);
480 }
481 
493  char c) {
494  return wfio_binstream_write(bin, &c, 1, 1) == 1;
495 }
496 
497 /* Integer Operations */
498 
512  wfio_sint16_t* buf, size_t len);
513 
527  const wfio_sint16_t* buf, size_t len);
528 
540  wfio_sint16_t si16) {
541  return wfio_binstream_writeSI16V(bin, &si16, 1) ? 1 : WFIO_NPOS;
542 }
543 
557  wfio_uint16_t* buf, size_t len) {
558  return wfio_binstream_readSI16V(bin, (wfio_sint16_t*) buf, len);
559 }
560 
574  const wfio_uint16_t* buf, size_t len) {
575  return wfio_binstream_writeSI16V(bin, (const wfio_sint16_t*) buf,
576  len);
577 }
578 
590  wfio_uint16_t ui16) {
591  return wfio_binstream_writeSI16(bin, (wfio_sint16_t) ui16);
592 }
593 
607  wfio_sint32_t* buf, size_t len);
608 
622  const wfio_sint32_t* buf, size_t len);
623 
635  wfio_sint32_t si32) {
636  return wfio_binstream_writeSI32V(bin, &si32, 1) ? 1 : WFIO_NPOS;
637 }
638 
652  wfio_uint32_t* buf, size_t len) {
653  return wfio_binstream_readSI32V(bin, (wfio_sint32_t*) buf, len);
654 }
655 
669  const wfio_uint32_t* buf, size_t len) {
670  return wfio_binstream_writeSI32V(bin, (const wfio_sint32_t*) buf,
671  len);
672 }
673 
685  wfio_uint32_t ui32) {
686  return wfio_binstream_writeSI32(bin, (wfio_sint32_t) ui32);
687 }
688 
702  wfio_sint64_t* buf, size_t len);
703 
717  const wfio_sint64_t* buf, size_t len);
718 
730  wfio_sint64_t si64) {
731  return wfio_binstream_writeSI64V(bin, &si64, 1) ? 1 : WFIO_NPOS;
732 }
733 
747  wfio_uint64_t* buf, size_t len) {
748  return wfio_binstream_readSI64V(bin, (wfio_sint64_t*) buf, len);
749 }
750 
764  const wfio_uint64_t* buf, size_t len) {
765  return wfio_binstream_writeSI64V(bin, (const wfio_sint64_t*) buf,
766  len);
767 }
768 
780  wfio_uint64_t ui64) {
781  return wfio_binstream_writeSI64(bin, (wfio_sint64_t) ui64);
782 }
783 
784 /* IEEE 754 Operations */
785 
799  wfio_flt32_t* buf, size_t len);
800 
814  const wfio_flt32_t* buf, size_t len);
815 
827  wfio_flt32_t f32) {
828  return wfio_binstream_writeB32V(bin, &f32, 1) != 0;
829 }
830 
844  wfio_flt64_t* buf, size_t len);
845 
859  const wfio_flt64_t* buf, size_t len);
860 
872  wfio_flt64_t f64) {
873  return wfio_binstream_writeB64V(bin, &f64, 1) != 0;
874 }
875 
877 
878 #ifdef __cplusplus
879 namespace wfio {
883  class BinStream {
884  ::wfio_binstream_t* m_bin;
885 
886  public:
887 
892 
893  /* Constructors and Destructors */
894 
900  inline BinStream() : m_bin(NULL) {}
901 
913  inline BinStream(::wfio_binstream_t* bin,
914  bool acquire = true) : m_bin(bin) {
915  if (acquire)
917  }
918 
925  inline BinStream(const BinStream& bin) :
926  m_bin(bin.m_bin) {
928  }
929 
936  inline BinStream(Device& dev, int* error = NULL) :
937  m_bin(::wfio_binstream_fromDevice(dev, error)) {}
938 
939 
946  inline ~BinStream() {
947  ::wfio_binstream_close(m_bin);
948  }
949 
950  /* Properties */
951 
952  endian_t endian() const throw() {
953  return m_bin->endian;
954  }
955 
956  void endian(endian_t endian) {
957  if (m_bin)
958  m_bin->endian = endian;
959  }
960 
961  endian_t floatEndian() const throw() {
962  return m_bin->floatEndian;
963  }
964 
965  void floatEndian(endian_t endian) {
966  if (m_bin)
967  m_bin->floatEndian = endian;
968  }
969 
970  /* I/O - bytewise */
971 
982  inline size_t read(void* buf, size_t sz, size_t elem) {
983  return ::wfio_binstream_read(m_bin, buf, sz, elem);
984  }
985 
994  inline size_t read(void* buf, size_t len) {
995  return ::wfio_binstream_readbV(m_bin, buf, len);
996  }
997 
1001  inline int read() {
1002  return ::wfio_binstream_readb(m_bin) != -1;
1003  }
1004 
1015  inline size_t write(const void* buf, size_t sz,
1016  size_t elem) {
1017  return ::wfio_binstream_write(m_bin, buf, sz,
1018  elem);
1019  }
1020 
1030  inline size_t write(const void* buf, size_t len) {
1031  return ::wfio_binstream_writebV(m_bin, buf, len);
1032  }
1033 
1042  inline bool write(char c) {
1043  return ::wfio_binstream_writeb(m_bin, c) != 0;
1044  }
1045 
1046  /* Integer Operations */
1047 
1057  inline size_t readSI16V(sint16_t* buf, size_t len) {
1058  return ::wfio_binstream_readSI16V(m_bin, buf, len);
1059  }
1060 
1070  inline size_t writeSI16V(const sint16_t* buf, size_t len) {
1071  return ::wfio_binstream_writeSI16V(m_bin, buf, len);
1072  }
1073 
1081  inline bool writeSI16(wfio_sint16_t si16) {
1082  return ::wfio_binstream_writeSI16(m_bin, si16) != 0;
1083  }
1084 
1094  inline size_t readUI16V(uint16_t* buf, size_t len) {
1095  return ::wfio_binstream_readUI16V(m_bin, buf, len);
1096  }
1097 
1107  inline size_t writeUI16V(const uint16_t* buf, size_t len) {
1108  return ::wfio_binstream_writeUI16V(m_bin, buf, len);
1109  }
1110 
1118  inline bool writeUI16(uint16_t ui16) {
1119  return ::wfio_binstream_writeUI16(m_bin, ui16);
1120  }
1121 
1133  inline size_t readSI32V(sint32_t* buf, size_t len) {
1134  return ::wfio_binstream_readSI32V(m_bin, buf, len);
1135  }
1136 
1146  inline size_t writeSI32V(const sint32_t* buf, size_t len) {
1147  return ::wfio_binstream_writeSI32V(m_bin, buf, len);
1148  }
1149 
1157  inline bool writeSI32(sint32_t si32) {
1158  return ::wfio_binstream_writeSI32(m_bin, si32) != 0;
1159  }
1160 
1170  inline size_t readUI32V(uint32_t* buf, size_t len) {
1171  return ::wfio_binstream_readUI32V(m_bin, buf, len);
1172  }
1173 
1183  inline size_t writeUI32V(const uint32_t* buf, size_t len) {
1184  return ::wfio_binstream_writeUI32V(m_bin, buf, len);
1185  }
1186 
1194  inline bool writeUI32(uint32_t ui32) {
1195  return ::wfio_binstream_writeUI32(m_bin, ui32) != 0;
1196  }
1197 
1207  inline size_t readSI64V(sint64_t* buf, size_t len) {
1208  return ::wfio_binstream_readSI64V(m_bin, buf, len);
1209  }
1210 
1222  inline size_t writeSI64V(const sint64_t* buf, size_t len) {
1224  buf, len);
1225  }
1226 
1234  inline bool writeSI64(sint64_t si64) {
1235  return ::wfio_binstream_writeSI64(m_bin, si64) != 0;
1236  }
1237 
1247  inline size_t readUI64V(uint64_t* buf, size_t len) {
1248  return ::wfio_binstream_readUI64V(m_bin, buf, len);
1249  }
1250 
1260  inline size_t writeUI64V(const uint64_t* buf, size_t len) {
1262  buf, len);
1263  }
1264 
1272  inline bool writeUI64(uint64_t ui64) {
1274  ui64) != 0;
1275  }
1276 
1277  /* IEEE 754 */
1278 
1290  inline size_t readB32V(wfio_flt32_t* buf, size_t len) {
1291  return ::wfio_binstream_readB32V(m_bin, buf, len);
1292  }
1293 
1305  inline size_t writeB32V(const wfio_flt32_t* buf,
1306  size_t len) {
1307  return ::wfio_binstream_writeB32V(m_bin, buf, len);
1308  }
1309 
1319  inline bool writeB32(wfio_flt32_t f32) {
1320  return ::wfio_binstream_writeB32(m_bin, f32) != 0;
1321  }
1322 
1334  inline size_t readB64V(wfio_flt64_t* buf, size_t len) {
1335  return ::wfio_binstream_readB64V(m_bin, buf, len);
1336  }
1337 
1349  inline size_t writeB64V(const wfio_flt64_t* buf,
1350  size_t len) {
1351  return ::wfio_binstream_writeB64V(m_bin, buf, len);
1352  }
1353 
1363  inline bool writeB64(wfio_flt64_t f64) {
1364  return ::wfio_binstream_writeB64(m_bin, f64) != 0;
1365  }
1366 
1367  /* Buffering */
1368 
1374  bool flush() {
1375  return ::wfio_binstream_flush(m_bin) != 0;
1376  }
1377 
1385  size_t bufSz() const {
1387  }
1388 
1402  size_t bufSz(size_t sz) {
1404  }
1405 
1406  /* Ioctl */
1407 
1416  inline int vdcntl(wfio_dcntl_t cmd, va_list va) {
1417  return ::wfio_binstream_vdcntl(m_bin, cmd, va);
1418  }
1419 
1429  inline int dcntl(wfio_dcntl_t cmd, ...) {
1430  register int ret;
1431  va_list va;
1432  va_start(va, cmd);
1433  ret = ::wfio_binstream_vdcntl(m_bin, cmd, va);
1434  va_end(va);
1435  return ret;
1436  }
1437 
1447  inline int vioctl(int cmd, va_list va) {
1448  return ::wfio_binstream_vioctl(m_bin, cmd, va);
1449  }
1450 
1460  inline int ioctl(wfio_binstream_t* bin,
1461  int cmd, ...) {
1462  register int ret;
1463  va_list va;
1464  va_start(va, cmd);
1465  ret = ::wfio_binstream_vioctl(m_bin, cmd, va);
1466  va_end(va);
1467  return ret;
1468  }
1469 
1470  /* Other */
1471 
1476  int ecode() const throw() {
1477  return m_bin ? m_bin->ecode : 1;
1478  }
1479 
1486  void ecode(int ecode) throw() {
1487  if (m_bin)
1488  m_bin->ecode = ecode;
1489  }
1490 
1500  inline bool valid() const throw() {
1501  return m_bin != NULL;
1502  }
1503 
1509  inline operator bool() const throw() {
1510  return m_bin != NULL;
1511  }
1512 
1517  inline operator ::wfio_binstream_t*() throw() {
1518  return m_bin;
1519  }
1520  };
1521 }
1522 #endif
1523 
1524 #endif
bool writeUI32(uint32_t ui32)
Write a single 32-bit unsigned integer.
Definition: bin.h:1194
The root namespace for WFIO.
Definition: bin.h:879
WFIO_DLL size_t wfio_binstream_writeB64V(wfio_binstream_t *bin, const wfio_flt64_t *buf, size_t len)
Write a vector of 64-bit IEEE 754 binary floats.
size_t writeUI16V(const uint16_t *buf, size_t len)
Write a vector of 16-bit unsigned integers.
Definition: bin.h:1107
WFIO_ALWAYS_INLINE size_t wfio_binstream_readbV(wfio_binstream_t *bin, void *buf, size_t len)
Read bytes from the supplied binstream.
Definition: bin.h:429
::wfio_uint32_t uint32_t
Definition: integer.h:128
WFIO_DLL size_t wfio_binstream_writeSI16V(wfio_binstream_t *bin, const wfio_sint16_t *buf, size_t len)
Write a vector of 16-bit signed integers.
::wfio_binstream_t CType
The C type from which a BinStream is derived.
Definition: bin.h:891
Wrap a wfio_binstream_t.
Definition: bin.h:883
WFIO_DLL size_t wfio_binstream_readSI64V(wfio_binstream_t *bin, wfio_sint64_t *buf, size_t len)
Read a vector of 64-bit signed integers.
WFIO_DLL size_t wfio_binstream_writeSI32V(wfio_binstream_t *bin, const wfio_sint32_t *buf, size_t len)
Write a vector of 32-bit signed integers.
size_t writeB32V(const wfio_flt32_t *buf, size_t len)
Write a vector of 32-bit IEEE 754 binary floats.
Definition: bin.h:1305
#define WFIO_DLL
Mark the symbol as an element of the library.
Definition: host.h:397
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
bool writeSI16(wfio_sint16_t si16)
Write a single 16-bit signed integer.
Definition: bin.h:1081
WFIO_DLL_FASTCALL wfio_binstream_t * wfio_binstream_ioshare(wfio_binstream_t *bin, int ioshare)
Share this bin with the supplied ioshare mode.
#define WFIO_DLL_FASTCALL
Shorthand for WFIO_DLL WFIO_FASTCALL.
Definition: host.h:425
size_t writeSI32V(const sint32_t *buf, size_t len)
Write a vector of 32-bit signed integers.
Definition: bin.h:1146
size_t read(void *buf, size_t len)
Read bytes from this BinStream.
Definition: bin.h:994
WFIO_DLL int wfio_binstream_acquire(wfio_binstream_t *bin)
Share the supplied binstream.
WFIO_DLL int wfio_binstream_seek(wfio_binstream_t *bin, wfio_off_t offset, wfio_whence_t whence)
Seek to a position in the stream.
A generic stream encapsulation.
Definition: peer.h:44
bool writeB32(wfio_flt32_t f32)
Write a single 32-bit IEEE 754 binary float.
Definition: bin.h:1319
size_t bufSz(size_t sz)
Set the buffer size for this BinStream.
Definition: bin.h:1402
WFIO_ALWAYS_INLINE int wfio_binstream_dcntl(wfio_binstream_t *bin, wfio_dcntl_t cmd,...)
Perform device-independent I/O control on this binstream.
Definition: bin.h:304
WFIO_ALWAYS_INLINE int wfio_binstream_writeSI32(wfio_binstream_t *bin, wfio_sint32_t si32)
Write a single 32-bit signed integer.
Definition: bin.h:634
WFIO_DLL int wfio_binstream_vdcntl(wfio_binstream_t *bin, wfio_dcntl_t cmd, va_list va)
Perform device-independent I/O control on this binstream using a va_list.
WFIO_DLL size_t wfio_binstream_write(struct wfio_binstream_t *bin, const void *buf, size_t sz, size_t elem)
Write elements to the supplied binstream.
bool writeSI32(sint32_t si32)
Write a single 32-bit signed integer.
Definition: bin.h:1157
bool writeUI64(uint64_t ui64)
Write a single 64-bit unsigned integer.
Definition: bin.h:1272
WFIO_DLL_FASTCALL int wfio_binstream_canSeek(wfio_binstream_t *bin)
Determine whether or not this binstream is capable of seeking.
int vdcntl(wfio_dcntl_t cmd, va_list va)
Perform device-independent I/O control on this binstream using a va_list.
Definition: bin.h:1416
#define WFIO_ALWAYS_INLINE
Mark this symbol to be forced inline.
Definition: host.h:447
size_t readB64V(wfio_flt64_t *buf, size_t len)
Read a vector of 64-bit IEEE 754 binary floats.
Definition: bin.h:1334
wfio_whence_t
The type corresponding to the point of reference in a seek operation.
Definition: iotype.h:60
::wfio_uint16_t uint16_t
Definition: integer.h:122
WFIO_ALWAYS_INLINE size_t wfio_binstream_writeUI32V(wfio_binstream_t *bin, const wfio_uint32_t *buf, size_t len)
Write a vector of 32-bit unsigned integers.
Definition: bin.h:668
size_t writeUI64V(const uint64_t *buf, size_t len)
Write a vector of 64-bit unsigned integers.
Definition: bin.h:1260
WFIO_DLL size_t wfio_binstream_readSI16V(wfio_binstream_t *bin, wfio_sint16_t *buf, size_t len)
Read a vector of 16-bit signed integers.
WFIO_ALWAYS_INLINE size_t wfio_binstream_readUI32V(wfio_binstream_t *bin, wfio_uint32_t *buf, size_t len)
Read a vector of 32-bit unsigned integers.
Definition: bin.h:651
bool write(char c)
Write a byte to the this BinStream.
Definition: bin.h:1042
::wfio_uint64_t uint64_t
Definition: integer.h:134
::wfio_sint32_t sint32_t
Definition: integer.h:125
WFIO_DLL size_t wfio_binstream_readSI32V(wfio_binstream_t *bin, wfio_sint32_t *buf, size_t len)
Read a vector of 32-bit signed integers.
WFIO_ALWAYS_INLINE int wfio_binstream_writeSI16(wfio_binstream_t *bin, wfio_sint16_t si16)
Write a single 16-bit signed integer.
Definition: bin.h:539
size_t readSI64V(sint64_t *buf, size_t len)
Read a vector of 64-bit signed integers.
Definition: bin.h:1207
WFIO_DLL size_t wfio_binstream_read(wfio_binstream_t *bin, void *buf, size_t sz, size_t elem)
Read elements from the supplied binstream.
WFIO_ALWAYS_INLINE int wfio_binstream_ioctl(wfio_binstream_t *bin, int cmd,...)
Perform device-dependent I/O control on this binstream.
Definition: bin.h:357
IEEE754 floating point manipulation.
wfio_dcntl_t
A command to be supplied to a device or similar stream.
Definition: iotype.h:175
WFIO_DLL size_t wfio_binstream_readB64V(wfio_binstream_t *bin, wfio_flt64_t *buf, size_t len)
Read a vector of 64-bit IEEE 754 binary floats.
WFIO_DLL size_t wfio_binstream_readB32V(wfio_binstream_t *bin, wfio_flt32_t *buf, size_t len)
Read a vector of 32-bit IEEE 754 binary floats.
size_t writeUI32V(const uint32_t *buf, size_t len)
Write a vector of 32-bit unsigned integers.
Definition: bin.h:1183
size_t writeB64V(const wfio_flt64_t *buf, size_t len)
Write a vector of 64-bit IEEE 754 binary floats.
Definition: bin.h:1349
A C++ wrapper for a wfio_device_t.
Definition: device.h:783
WFIO_DLL_FASTCALL size_t wfio_binstream_setbufsz(wfio_binstream_t *bin, size_t sz)
Set the buffer size.
WFIO_ALWAYS_INLINE int wfio_binstream_readb(wfio_binstream_t *bin)
Read a byte from the supplied binstream.
Definition: bin.h:441
int ecode() const
Obtain the error code associated with this BinStream.
Definition: bin.h:1476
size_t readB32V(wfio_flt32_t *buf, size_t len)
Read a vector of 32-bit IEEE 754 binary floats.
Definition: bin.h:1290
WFIO_ALWAYS_INLINE int wfio_binstream_writeB64(wfio_binstream_t *bin, wfio_flt64_t f64)
Write a single 64-bit IEEE 754 binary float.
Definition: bin.h:871
WFIO_DLL_FASTCALL size_t wfio_binstream_getbufsz(wfio_binstream_t *bin)
Obtain the buffer size.
size_t readUI32V(uint32_t *buf, size_t len)
Read a vector of 32-bit unsigned integers.
Definition: bin.h:1170
WFIO_ALWAYS_INLINE size_t wfio_binstream_writebV(wfio_binstream_t *bin, const void *buf, size_t len)
Write a byte vector to the supplied binstream.
Definition: bin.h:477
A stream intended for binary output.
Definition: bin.h:54
size_t readSI16V(sint16_t *buf, size_t len)
Read a vector of 16-bit signed integers.
Definition: bin.h:1057
WFIO_ALWAYS_INLINE int wfio_binstream_writeUI16(wfio_binstream_t *bin, wfio_uint16_t ui16)
Write a single 16-bit unsigned integer.
Definition: bin.h:589
::wfio_sint16_t sint16_t
Definition: integer.h:119
size_t write(const void *buf, size_t len)
Write a byte vector to this BinStream.
Definition: bin.h:1030
A constant indicating no position.
Definition: iotype.h:226
size_t readUI16V(uint16_t *buf, size_t len)
Read a vector of 16-bit unsigned integers.
Definition: bin.h:1094
size_t read(void *buf, size_t sz, size_t elem)
Read elements from this BinStream.
Definition: bin.h:982
WFIO_ALWAYS_INLINE size_t wfio_binstream_readUI64V(wfio_binstream_t *bin, wfio_uint64_t *buf, size_t len)
Read a vector of 64-bit unsigned integers.
Definition: bin.h:746
BinStream(Device &dev, int *error=NULL)
Construct a BinStream by supplying a Device.
Definition: bin.h:936
WFIO_ALWAYS_INLINE int wfio_binstream_writeSI64(wfio_binstream_t *bin, wfio_sint64_t si64)
Write a single 64-bit signed integer.
Definition: bin.h:729
#define WFIO_C_END
Definition: host.h:485
A simple, byte-oriented channel.
Definition: device.h:164
WFIO_ALWAYS_INLINE size_t wfio_binstream_writeUI16V(wfio_binstream_t *bin, const wfio_uint16_t *buf, size_t len)
Write a vector of 16-bit unsigned integers.
Definition: bin.h:573
bool valid() const
Determine if this BinStream is valid.
Definition: bin.h:1500
bool writeUI16(uint16_t ui16)
Write a single 16-bit unsigned integer.
Definition: bin.h:1118
~BinStream()
Release this BinStream.
Definition: bin.h:946
WFIO_DLL size_t wfio_binstream_writeSI64V(wfio_binstream_t *bin, const wfio_sint64_t *buf, size_t len)
Write a vector of 64-bit signed integers.
WFIO_DLL wfio_binstream_t * wfio_binstream_fromDeviceEx(struct wfio_device_t *device, wfio_endian_t endian, int *error)
Create a new binstream with the specified device and endian.
int vioctl(int cmd, va_list va)
Perform device-dependent I/O control on this binstream.
Definition: bin.h:1447
BinStream(const BinStream &bin)
Copy-construct a BinStream.
Definition: bin.h:925
WFIO_ALWAYS_INLINE int wfio_binstream_writeUI32(wfio_binstream_t *bin, wfio_uint32_t ui32)
Write a single 32-bit unsigned integer.
Definition: bin.h:684
size_t bufSz() const
Obtain the buffer size for this BinStream.
Definition: bin.h:1385
WFIO_ALWAYS_INLINE int wfio_binstream_writeUI64(wfio_binstream_t *bin, wfio_uint64_t ui64)
Write a single 64-bit unsigned integer.
Definition: bin.h:779
WFIO_DLL_FASTCALL int wfio_binstream_flush(wfio_binstream_t *bin)
Flush this binstream.
bool flush()
Attempt to flush this BinStream.
Definition: bin.h:1374
wfio_endian_t
A categorization of the byte-order of multibyte integers.
Definition: misctype.h:61
WFIO_DLL void wfio_binstream_close(wfio_binstream_t *bin)
Close the supplied binstream.
WFIO_DLL_FASTCALL wfio_off_t wfio_binstream_tell(wfio_binstream_t *bin)
Determine the current stream position of this binstream.
The endianness of this system.
Definition: misctype.h:173
BinStream(::wfio_binstream_t *bin, bool acquire=true)
Wrap a wfio_binstream_t.
Definition: bin.h:913
int ioctl(wfio_binstream_t *bin, int cmd,...)
Perform device-dependent I/O control on this binstream.
Definition: bin.h:1460
size_t write(const void *buf, size_t sz, size_t elem)
Write elements to this BinStream.
Definition: bin.h:1015
::wfio_sint64_t sint64_t
Definition: integer.h:131
WFIO_C_BEGIN struct wfio_binstream_t wfio_binstream_t
A stream intended for binary output.
WFIO_DLL int wfio_binstream_vioctl(wfio_binstream_t *bin, int cmd, va_list va)
Perform device-dependent I/O control on this binstream.
Byte-oriented devices.
WFIO_ALWAYS_INLINE int wfio_binstream_writeb(wfio_binstream_t *bin, char c)
Write a byte to the supplied binstream.
Definition: bin.h:492
int dcntl(wfio_dcntl_t cmd,...)
Perform device-independent I/O control on this binstream.
Definition: bin.h:1429
WFIO_DLL size_t wfio_binstream_writeB32V(wfio_binstream_t *bin, const wfio_flt32_t *buf, size_t len)
Write a vector of 32-bit IEEE 754 binary floats.
size_t writeSI64V(const sint64_t *buf, size_t len)
Write a vector of 64-bit signed integers.
Definition: bin.h:1222
bool writeSI64(sint64_t si64)
Write a single 64-bit signed integer.
Definition: bin.h:1234
size_t readUI64V(uint64_t *buf, size_t len)
Read a vector of 64-bit unsigned integers.
Definition: bin.h:1247
bool writeB64(wfio_flt64_t f64)
Write a single 64-bit IEEE 754 binary float.
Definition: bin.h:1363
WFIO_ALWAYS_INLINE size_t wfio_binstream_readUI16V(wfio_binstream_t *bin, wfio_uint16_t *buf, size_t len)
Read a vector of 16-bit unsigned integers.
Definition: bin.h:556
void ecode(int ecode)
Set the error code associated with this BinStream.
Definition: bin.h:1486
BinStream()
Construct the default BinStream.
Definition: bin.h:900
A structure indicating no definition.
Definition: misctype.h:47
size_t readSI32V(sint32_t *buf, size_t len)
Read a vector of 32-bit signed integers.
Definition: bin.h:1133
WFIO_ALWAYS_INLINE int wfio_binstream_writeB32(wfio_binstream_t *bin, wfio_flt32_t f32)
Write a single 32-bit IEEE 754 binary float.
Definition: bin.h:826
WFIO_ALWAYS_INLINE wfio_binstream_t * wfio_binstream_fromDevice(struct wfio_device_t *device, int *error)
Create a new binstream with the specified device.
Definition: bin.h:137
size_t writeSI16V(const sint16_t *buf, size_t len)
Write a vector of 16-bit signed integers.
Definition: bin.h:1070
WFIO_DLL struct wfio_device_t * wfio_binstream_toDevice(wfio_binstream_t *bin)
Wrap this binstream around a device.
int read()
Read a byte from the supplied binstream.
Definition: bin.h:1001
WFIO_ALWAYS_INLINE size_t wfio_binstream_writeUI64V(wfio_binstream_t *bin, const wfio_uint64_t *buf, size_t len)
Write a vector of 64-bit unsigned integers.
Definition: bin.h:763