MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Attributes
MFM::ByteSource Class Referenceabstract

#include <ByteSource.h>

Inheritance diagram for MFM::ByteSource:
MFM::CharBufferByteSource MFM::FileByteSource MFM::LineCountingByteSource MFM::ZStringByteSource

Public Member Functions

 ByteSource ()
 
s32 Read ()
 
void Unread ()
 
s32 Peek ()
 
virtual int ReadByte ()=0
 
virtual ~ByteSource ()
 
u32 GetBytesRead ()
 
bool Scan (u64 &result)
 
bool Scan (s32 &result, Format::Type code=Format::DEC, u32 fieldWidth=U32_MAX)
 
bool Scan (u32 &result, Format::Type code=Format::DEC, u32 fieldWidth=U32_MAX)
 
bool Scan (ByteSerializable &byteSerializable, s32 argument=0)
 
bool ScanLexDigits (u32 &digits)
 
bool Scan (ByteSink &result, const u32 fieldWidth)
 
s32 ScanSet (ByteSink &result, const char *setSpec)
 
s32 SkipSet (const char *setSpec)
 
s32 ScanSetFormat (ByteSink &result, const char *&setSpec)
 
bool ScanIdentifier (ByteSink &result)
 
bool ScanHex (ByteSink &result)
 
bool ScanBinary (ByteSink &result)
 
bool ScanCamelIdentifier (ByteSink &result)
 
s32 SkipWhitespace ()
 
s32 Scanf (const char *format,...)
 
s32 Vscanf (const char *format, va_list &ap)
 

Static Public Attributes

static const char * WHITESPACE_CHARS = " \n\t\v"
 
static const char * WHITESPACE_SET = "[ \n\t\v]"
 
static const char * NON_WHITESPACE_SET = "[^ \n\t\v]"
 

Detailed Description

An abstract source where bytes may be read from.

Constructor & Destructor Documentation

MFM::ByteSource::ByteSource ( )
inline

Constructs a new ByteSource in an unread state.

virtual MFM::ByteSource::~ByteSource ( )
inlinevirtual

Deconstructs this ByteSource. Default implementation does nothing.

Member Function Documentation

u32 MFM::ByteSource::GetBytesRead ( )
inline

Gets the number of bytes that have currently been read from this ByteSource. If a byte has been Unread() , it is treated by this method as never having been read.

Parameters
Thenumber of bytes that have currently been read from this ByteSource .
s32 MFM::ByteSource::Peek ( )
inline

Gets the next 32-bit character from the front of this ByteSource without consuming it.

Returns
The next 32-bit character to be Read() from this ByteSource.
s32 MFM::ByteSource::Read ( )
inline

Gets the next logical single 32-bit character from this ByteSource. If there was an Unread() operation on this ByteSource before this Read() operation, the last character returned by Read() will be returned.

Returns
the next logical single 32-bit character from this ByteSource.
virtual int MFM::ByteSource::ReadByte ( )
pure virtual

Gets the next 32-bit character from this ByteSource , regardless of whether or not Unread() has been called.

Returns
the next 32-bit character from this ByteSource .

Implemented in MFM::LineCountingByteSource, MFM::FileByteSource, and MFM::CharBufferByteSource.

bool MFM::ByteSource::Scan ( u64 &  result)

Performs a binary read of the next 64 bits to come out of this ByteSource . These bytes are stored in the specified u64 , where the first bytes read are stored in its MSB end.

Parameters
resultThe location to store the next 64 bits to come out of this ByteSource.
Returns
true if the next 64 bits are read successfully from this ByteSource, else false.
bool MFM::ByteSource::Scan ( s32 &  result,
Format::Type  code = Format::DEC,
u32  fieldWidth = U32_MAX 
)

Performs several types of reads of a 32-bit number, depending on the provided format.

Parameters
resultThe location to store the read binary formatted 32-bit number.
codeThe format to treat the next bytes read from this ByteSource as, including various numeric bases (such as binary, octal, decimal, hexadecimal) and network-order binary representations.
fieldWidthThe maximum number of characters which will be read during this call.
Returns
true if a number of code formatting can be read from the next read bytes.
bool MFM::ByteSource::Scan ( u32 &  result,
Format::Type  code = Format::DEC,
u32  fieldWidth = U32_MAX 
)

Performs several types of reads of a 32-bit number, depending on the provided format.

Parameters
resultThe location to store the read binary formatted 32-bit number .
codeThe format to treat the next bytes read from this ByteSource as, be it binary or ascii in nature.
fieldWidthThe maximum number of characters which will be read during this call.
Returns
true if a number of code formatting can be read from the next read bytes.
bool MFM::ByteSource::Scan ( ByteSerializable byteSerializable,
s32  argument = 0 
)

Reads a ByteSerializable from the front of this ByteSource.

Parameters
byteSerializableThe ByteSerializable which is to be expected during this Scan. The ByteSerializable itself defines whether or not these bytes may represent it.
argumentAn argument which may be passed to byteSerializable to help determine whether or not is is being read correctly. Again, this is determined by the particular ByteSerializable used in this call.
Returns
true if byteSerializable may be represented by the following read bytes, else false .
bool MFM::ByteSource::ScanBinary ( ByteSink result)
inline

Scans this ByteSource for a binary string, i.e. a string consisting only of the binary characters '1' and '0' .

Parameters
resultThe ByteSink which collects the all characters that match the rules for being a binary string.
Returns
true if the next characters of this ByteSource (excluding whitespace) can be treated as a binary string.
bool MFM::ByteSource::ScanCamelIdentifier ( ByteSink result)
inline

Scans this ByteSource for a camelcase identifier, i.e. an alphanumeric string which starts with a capital letter.

Parameters
resultThe ByteSink which collects the all characters that match the rules for being an camelcase identifier.
Returns
true if the next characters of this ByteSource (excluding whitespace) can be treated as a camelcase identifier.
bool MFM::ByteSource::ScanHex ( ByteSink result)
inline

Scans this ByteSource for a hexadecimal string, i.e. a string consisting of both upper and lowercase hexadecimal digits.

Parameters
resultThe ByteSink which collects the all characters that match the rules for being a hexadecimal string.
Returns
true if the next characters of this ByteSource (excluding whitespace) can be treated as a hexadecimal string.
bool MFM::ByteSource::ScanIdentifier ( ByteSink result)
inline

Scans this ByteSource for an Identifier, i.e. an alphanumeric string which does not start with a number.

Parameters
resultThe ByteSink which collects the all characters that match the rules for being an identifier.
Returns
true if the next characters of this ByteSource (excluding whitespace) can be treated as an identifier.
s32 MFM::ByteSource::SkipSet ( const char *  setSpec)
inline

Scans a set of characters, defined by a specified descriptor, consuming them as they are scanned.

Parameters
setSpecThe descriptor of the characters to be consumed.
Returns
The number of characters consumed.
s32 MFM::ByteSource::SkipWhitespace ( )
inline

Consumes and destroys all whitespace characters at the front of this ByteSource.

Returns
The number of whitespace characters consumed.
void MFM::ByteSource::Unread ( )
inline

Puts the last read character back into this ByteSource. This is useful for situations where the character on top of this ByteSource is needed to be regurgitated; for instance, when using the Peek() method.

s32 MFM::ByteSource::Vscanf ( const char *  format,
va_list &  ap 
)

NYI: u8 padChar;

Field Documentation

const char * MFM::ByteSource::NON_WHITESPACE_SET = "[^ \n\t\v]"
static

A char* representing a Scanf() formatted set of all chars which are not included in WHITESPACE_CHARS . This is to be used when scanning for anything that is not whitespace.

const char * MFM::ByteSource::WHITESPACE_CHARS = " \n\t\v"
static

A char* consisting only of all unique characters treated as Whitespace by this ByteSource. This set includes:

' ' Space '
' Newline '' Tab '' Vertical Tab

const char * MFM::ByteSource::WHITESPACE_SET = "[ \n\t\v]"
static

A char* representing a Scanf() formatted set of all chars in WHITESPACE_CHARS . This is to be used when scanning for whitespace.


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