Bond 0.9
Bond Standard Library API Documentation
Loading...
Searching...
No Matches
Bond::InputStream Struct Reference

An abstract interface for performing both unformatted and formatted input operations. More...

Public Member Functions

void Close ()
 Discards any unread input and closes the stream.
void ScanStr (char *str, uint bufferSize)
 Reads a string of characters from the input stream into a character buffer.
bool ScanB ()
 Reads and returns a formatted Boolean value from the input stream.
char ScanC ()
 Reads and returns a single character from the input stream.
int ScanI ()
 Reads and returns a formatted integer as an int from the input stream.
uint ScanUI ()
 Reads and returns a formatted unsigned integer as a uint from the input stream.
long ScanL ()
 Reads and returns a formatted integer as a long from the input stream.
ulong ScanUL ()
 Reads and returns a formatted unsigned integer as a ulong from the input stream.
float ScanF ()
 Reads and returns a formatted floating-point number as a float from the input stream.
double ScanD ()
 Reads and returns a formatted floating-point number as a double from the input stream.
int Get ()
 Reads and returns a single unformatted byte from the input stream.
uint Read (void *bytes, uint numBytes)
 Attempts to read the specified number of unformatted bytes into the given buffer.
int GetFlags () const
 Returns the stream's current format flags as a bitmask of values from the IO::Flags enum.
InputStream * SetFlags (int flags)
 Enables the format flags in the given bitmask of values from the IO::Flags enum.
InputStream * UnsetFlags (int flags)
 Disables the format flags in the given bitmask of values from the IO::Flags enum.
InputStream * ClearFlags ()
 Disables all of the format flags.
int GetPosition () const
 Returns the stream's current position measured in bytes.
int GetEndPosition () const
 Returns the position of the stream's end measured in bytes.
void SetPosition (int offset)
 Sets the stream's position relative to its beginning measured in bytes.
void SetPositionFromEnd (int offset)
 Sets the stream's position relative to its end measured in bytes.
void AddOffset (int offset)
 Moves the stream by the specified number of bytes relative to its current position.
bool IsEof () const
 Returns whether the end of the stream has been reached.
bool HasError () const
 Returns whether an I/O error has occurred during an input operation.
void ClearError ()
 Clears the error flag.

Detailed Description

An abstract interface for performing both unformatted and formatted input operations.

Except for Close, using a stream after it has been closed raises an error.

Member Function Documentation

◆ AddOffset()

void Bond::InputStream::AddOffset ( int offset)

Moves the stream by the specified number of bytes relative to its current position.

Parameters
offsetThe number of bytes by which the stream is repositioned.

◆ ClearError()

void Bond::InputStream::ClearError ( )

Clears the error flag.

◆ ClearFlags()

InputStream * Bond::InputStream::ClearFlags ( )

Disables all of the format flags.

The format flags modify how the stream interprets input.

Returns
The stream on which this function was called.

◆ Close()

void Bond::InputStream::Close ( )

Discards any unread input and closes the stream.

Closing a stream that is already closed has no effect. Closing a stream does not free it.

◆ Get()

int Bond::InputStream::Get ( )

Reads and returns a single unformatted byte from the input stream.

If the end of the stream has been reached and there is no data to return, the value IO::Eof is returned.

◆ GetEndPosition()

int Bond::InputStream::GetEndPosition ( ) const

Returns the position of the stream's end measured in bytes.

◆ GetFlags()

int Bond::InputStream::GetFlags ( ) const

Returns the stream's current format flags as a bitmask of values from the IO::Flags enum.

The format flags modify how the stream interprets input.

◆ GetPosition()

int Bond::InputStream::GetPosition ( ) const

Returns the stream's current position measured in bytes.

◆ HasError()

bool Bond::InputStream::HasError ( ) const

Returns whether an I/O error has occurred during an input operation.

Input that does not match the requested format is not an error.

◆ IsEof()

bool Bond::InputStream::IsEof ( ) const

Returns whether the end of the stream has been reached.

◆ Read()

uint Bond::InputStream::Read ( void * bytes,
uint numBytes )

Attempts to read the specified number of unformatted bytes into the given buffer.

Fewer bytes are read if the end of the stream is reached.

Parameters
bytesThe buffer into which the read bytes are stored.
numBytesThe requested number of bytes to be read.
Returns
The number of bytes read.

◆ ScanB()

bool Bond::InputStream::ScanB ( )

Reads and returns a formatted Boolean value from the input stream.

If the IO::BoolAlpha flag is set, an attempt is made to read the string "true" or "false", otherwise an integer is read, in base 16 if it begins with 0x, in base 8 if it begins with 0, or in base 10 otherwise. If the string "true" or a non-zero value is read, true is returned. If no valid input can be read, false is returned and the stream is left at the first character that did not match.

◆ ScanC()

char Bond::InputStream::ScanC ( )

Reads and returns a single character from the input stream.

Whitespace is skipped first if the IO::SkipWhite flag is set. If the end of the stream has been reached, 0 is returned.

◆ ScanD()

double Bond::InputStream::ScanD ( )

Reads and returns a formatted floating-point number as a double from the input stream.

Leading whitespace is skipped. If no floating-point number can be read, 0 is returned and the stream is left at the first character that did not match.

◆ ScanF()

float Bond::InputStream::ScanF ( )

Reads and returns a formatted floating-point number as a float from the input stream.

Leading whitespace is skipped. If no floating-point number can be read, 0 is returned and the stream is left at the first character that did not match.

◆ ScanI()

int Bond::InputStream::ScanI ( )

Reads and returns a formatted integer as an int from the input stream.

If the IO::Dec, IO::Hex or IO::Oct flag is set, the integer is read in base 10, 16 or 8 respectively, checked in that order. If none of those flags are set, the integer is read in base 16 if it begins with 0x, in base 8 if it begins with 0, or in base 10 otherwise. Leading whitespace is skipped. If no integer can be read, 0 is returned and the stream is left at the first character that did not match.

◆ ScanL()

long Bond::InputStream::ScanL ( )

Reads and returns a formatted integer as a long from the input stream.

If the IO::Dec, IO::Hex or IO::Oct flag is set, the integer is read in base 10, 16 or 8 respectively, checked in that order. If none of those flags are set, the integer is read in base 16 if it begins with 0x, in base 8 if it begins with 0, or in base 10 otherwise. Leading whitespace is skipped. If no integer can be read, 0 is returned and the stream is left at the first character that did not match.

◆ ScanStr()

void Bond::InputStream::ScanStr ( char * str,
uint bufferSize )

Reads a string of characters from the input stream into a character buffer.

Leading whitespace is skipped. The scan stops at the first whitespace character or when the buffer is full. The string is null terminated. At most bufferSize-1 characters are read to leave space for the null terminator. If the end of the stream is reached before any character is read, the buffer is left unchanged.

Parameters
strPointer to a character buffer where characters are stored.
bufferSizeLength of the buffer pointed to by str. It must be at least 1.

◆ ScanUI()

uint Bond::InputStream::ScanUI ( )

Reads and returns a formatted unsigned integer as a uint from the input stream.

If the IO::Dec, IO::Hex or IO::Oct flag is set, the integer is read in base 10, 16 or 8 respectively, checked in that order. If none of those flags are set, the integer is read in base

  1. Leading whitespace is skipped. If no integer can be read, 0 is returned and the stream is left at the first character that did not match.

◆ ScanUL()

ulong Bond::InputStream::ScanUL ( )

Reads and returns a formatted unsigned integer as a ulong from the input stream.

If the IO::Dec, IO::Hex or IO::Oct flag is set, the integer is read in base 10, 16 or 8 respectively, checked in that order. If none of those flags are set, the integer is read in base 16 if it begins with 0x, in base 8 if it begins with 0, or in base 10 otherwise. Leading whitespace is skipped. If no integer can be read, 0 is returned and the stream is left at the first character that did not match.

◆ SetFlags()

InputStream * Bond::InputStream::SetFlags ( int flags)

Enables the format flags in the given bitmask of values from the IO::Flags enum.

All other flags are left untouched. The format flags modify how the stream interprets input.

Parameters
flagsThe bitmask of flags from the IO::Flags enum to enable.
Returns
The stream on which this function was called.

◆ SetPosition()

void Bond::InputStream::SetPosition ( int offset)

Sets the stream's position relative to its beginning measured in bytes.

Parameters
offsetThe number of bytes from the beginning to which the stream is repositioned.

◆ SetPositionFromEnd()

void Bond::InputStream::SetPositionFromEnd ( int offset)

Sets the stream's position relative to its end measured in bytes.

Parameters
offsetThe number of bytes from the end to which the stream is repositioned.

◆ UnsetFlags()

InputStream * Bond::InputStream::UnsetFlags ( int flags)

Disables the format flags in the given bitmask of values from the IO::Flags enum.

All other flags are left untouched. The format flags modify how the stream interprets input.

Parameters
flagsThe bitmask of flags from the IO::Flags enum to disable.
Returns
The stream on which this function was called.

The documentation for this struct was generated from the following file:
  • build/libdoc/io.bond