Public Member Functions | List of all members
ustl::istream Class Reference

Helper class to read packed binary streams. More...

#include <ustl.h>

Inheritance diagram for ustl::istream:
ustl::cmemlink ustl::ios_base ustl::istringstream ustl::ifstream

Public Member Functions

 istream (const void *p, streamsize n)
 istream (const cmemlink &source)
 istream (const ostream &source) noexcept
 Attaches to the block pointed to by source of size source.pos()
iterator end (void) const
void link (const void *p, streamsize n)
void link (const cmemlink &l)
void link (const void *f, const void *l)
void relink (const void *p, streamsize n)
void relink (const cmemlink &l)
virtual void unlink (void) noexcept override
virtual streamsize underflow (streamsize=1)
uoff_t pos (void) const
const_iterator ipos (void) const
streamsize remaining (void) const
void seek (uoff_t newPos)
 Sets the current read position to newPos.
void iseek (const_iterator newPos)
 Sets the current read position to newPos.
void skip (streamsize nBytes)
 Skips nBytes without reading them.
bool aligned (streamsize grain=c_DefaultAlignment) const
 Returns true if the read position is aligned on grain.
bool verify_remaining (const char *op, const char *type, streamsize n)
 Checks that n bytes are available in the stream, or else throws.
streamsize align_size (streamsize grain=c_DefaultAlignment) const
 Returns the number of bytes to skip to be aligned on grain.
void align (streamsize grain=c_DefaultAlignment)
 aligns the read position on grain
void swap (istream &is)
 Swaps contents with is.
void read (void *buffer, streamsize size)
 Reads n bytes into buffer.
void read (memlink &buf)
void read_strz (string &str)
 Reads a null-terminated string into str.
streamsize readsome (void *s, streamsize n)
 Reads at most n bytes into s.
void read (istream &)
void write (ostream &os) const
 Writes all unread bytes into os.
void text_write (ostringstream &os) const
 Writes the object to stream os.
streamsize stream_size (void) const
template<typename T >
void iread (T &v)
 Reads type T from the stream via a direct pointer cast.
void ungetc (void)
off_t tellg (void) const
void seekg (off_t p, seekdir d=beg)
 Sets the current write position to p based on d.
- Public Member Functions inherited from ustl::ios_base
iostate rdstate (void) const
bool bad (void) const
bool good (void) const
bool fail (void) const
bool eof (void) const
bool operator! (void) const
 operator void * (void) const
void clear (iostate v=goodbit)
void setstate (iostate v)
iostate exceptions (void) const
iostate exceptions (iostate v)

Additional Inherited Members

- Public Types inherited from ustl::ios_base
enum  fmtflags {
  boolalpha = (1 << 0),
  dec = (1 << 1),
  fixed = (1 << 2),
  hex = (1 << 3),
  internal = (1 << 4),
  left = (1 << 5),
  oct = (1 << 6),
  right = (1 << 7),
  scientific = (1 << 8),
  showbase = (1 << 9),
  showpoint = (1 << 10),
  showpos = (1 << 11),
  skipws = (1 << 12),
  unitbuf = (1 << 13),
  uppercase = (1 << 14),
  adjustfield = (1 << 15),
  basefield = (1 << 16),
  floatfield = (1 << 17)
 Used to set parameters for stringstreams. More...
enum  openmode_bits {
  in = (1 << 0),
  out = (1 << 1),
  app = (1 << 2),
  ate = (1 << 3),
  binary = (1 << 4),
  trunc = (1 << 5)
 For file-based streams, specifies fd mode.
enum  seekdir {
 Seek directions, equivalent to SEEK_SET, SEEK_CUR, and SEEK_END.
enum  iostate_bits {
  goodbit = 0,
  badbit = (1 << 0),
  eofbit = (1 << 1),
  failbit = (1 << 2)
 I/O state bitmasks.
typedef uint32_t openmode
 Holds openmode_bits.
typedef uint32_t iostate
 Holds iostate_bits for a file stream.
typedef file_exception failure
 Thrown by fstream on errors.
- Static Public Attributes inherited from ustl::ios_base
static const char c_DefaultDelimiters [16] = DEFAULT_DELIMITERS
 Default word delimiters for stringstreams.
- Protected Member Functions inherited from ustl::ios_base
bool set_and_throw (iostate v)
void overrun (const char *op, const char *type, uint32_t n, uint32_t p, uint32_t rem)
 Checks that n bytes are available in the stream, or else throws.

Detailed Description

Helper class to read packed binary streams.

This class contains a set of functions to read integral types from an unstructured memory block. Unpacking binary file data can be done this way, for instance. aligning the data is your responsibility, and can be accomplished by proper ordering of reads and by calling the align() function. Unaligned access is usually slower by orders of magnitude and, on some architectures, such as PowerPC, can cause your program to crash. Therefore, all read functions have asserts to check alignment. Overreading the end of the stream will also cause a crash (an assert in debug builds). Oh, and don't be intimidated by the size of the inlines here. In the assembly code the compiler will usually chop everything down to five instructions each.

Alignment rules for your objects:

Example code:

memblock b;
b.read_file ("test.file");
ostream is (b);
is >> boolVar >> ios::talign<int>();
is >> intVar >> floatVar; (binaryData, binaryDataSize);

The documentation for this class was generated from the following files:

Generated on Mon Sep 28 2015 17:58:50 for uSTL by Doxygen 1.8.10