ActiveLib
Loading...
Searching...
No Matches
Public Member Functions | List of all members
active::utility::BufferIn Class Reference

#include <BufferIn.h>

Inheritance diagram for active::utility::BufferIn:
Inheritance graph
[legend]
Collaboration diagram for active::utility::BufferIn:
Collaboration graph
[legend]

Public Member Functions

 BufferIn (const file::File &sourceFile, DataFormat::Option format=DataFormat{})
 
 BufferIn (const Memory &sourceMem, DataFormat::Option format=DataFormat{})
 
 BufferIn (const String &sourceString, DataFormat::Option format=DataFormat{})
 
 BufferIn (BufferIn &&source) noexcept
 
 BufferIn (const BufferIn &)=delete
 No copy constructor.
 
BufferInoperator= (BufferIn &&source) noexcept
 
BufferInoperator= (const BufferIn &)=delete
 
 operator bool () const
 
const BufferInoperator>> (String &str) const
 
const BufferInoperator>> (int16_t &val) const
 
const BufferInoperator>> (int32_t &val) const
 
const BufferInoperator>> (uint32_t &val) const
 
const BufferInoperator>> (int64_t &val) const
 
const BufferInoperator>> (uint64_t &val) const
 
const BufferInoperator>> (double &val) const
 
const char * data () const
 
Memory::size_type dataSize () const
 
Memory::size_type sourceSize () const
 
Memory::size_type getLastRow () const
 
Memory::size_type getLastColumn () const
 
Memory::size_type getPosition () const
 
TextEncoding textEncoding () const
 
void forEach (const String::Function &func, String *pool=nullptr) const
 
bool findIf (const String::Filter &filter, String *pool=nullptr, bool isFoundSkipped=false) const
 
bool find (char32_t toFind, String *pool=nullptr, bool isFoundSkipped=false) const
 
bool find (const String &toFind, String *pool=nullptr, bool isFoundSkipped=false) const
 
bool findFirstOf (const String &toFind, String *pool=nullptr, bool isContiguousMatch=false, bool isRepeatMatch=false, bool isFoundSkipped=false, bool isFoundPooled=false, std::optional< char32_t > escapeChar=std::nullopt) const
 
bool findFirstNotOf (const String &toFind, String *pool=nullptr, std::optional< char32_t > escapeChar=std::nullopt) const
 
const BufferInget (unsigned char &dest) const
 
Memory::size_type getEncodedChar (String &encodedChar, bool isConsumed=true) const
 
std::pair< char32_t, String::size_typegetEncodedChar (bool isConsumed=true) const
 
const BufferInget (String &dest) const
 
const BufferInread (char *dest, Memory::size_type &howMany) const
 
String readWord (const String &division=String::allWhiteSpace) const
 
std::vector< StringreadWords (Memory::sizeOption howMany=std::nullopt, const String &division=String::allWhiteSpace) const
 
template<class T >
const BufferIngetValue (T &val) const
 
const BufferIngetString (String &dest, String::sizeOption howMany=std::nullopt) const
 
const BufferIngetLine (String &line, bool keepStop=true) const
 
const BufferInskip (Memory::size_type howMany) const
 
const BufferInrewind (Memory::size_type howMany) const
 
void setPosition (Memory::size_type pos) const
 
void swap (BufferIn &other)
 
void setFormat (DataFormat format)
 
void setSourceEncoding (TextEncoding encoding)
 
void setSource (const file::File &sourceFile, DataFormat::Option format=DataFormat{})
 
void setSource (const Memory &sourceMem, DataFormat::Option format=DataFormat{})
 
void setSource (const String &sourceString, DataFormat::Option format=DataFormat{})
 
- Public Member Functions inherited from active::file::IOBase
 IOBase () noexcept
 
 IOBase (const IOBase &source) noexcept
 
virtual ~IOBase () noexcept=default
 
bool operator! () const noexcept
 
 operator void * () const noexcept
 
virtual bool good () const noexcept
 
virtual bool eof () const noexcept
 
virtual bool fail () const noexcept
 
virtual bool bad () const noexcept
 
virtual flag_type state () const noexcept
 
virtual void clear (flag_type f=std::ios_base::goodbit)
 
virtual void setState (flag_type f)
 
virtual void unsetState (flag_type f)
 

Additional Inherited Members

- Public Types inherited from active::file::IOBase
using flag_type = std::ios_base::iostate
 The state flag representation type.
 
- Protected Member Functions inherited from active::file::IOBase
void setCompleteState (flag_type state)
 
void clear (flag_type f=std::ios_base::goodbit) const
 
void setState (flag_type f) const
 
virtual void unsetState (flag_type f) const
 

Detailed Description

Class to buffer incoming data from a specified source

Constructor & Destructor Documentation

◆ BufferIn() [1/4]

BufferIn::BufferIn ( const file::File & sourceFile,
DataFormat::Option format = DataFormat{} )

Constructor

Parameters
sourceFileThe source data file. NB: The buffer does not take ownership of this object - must be maintained for the buffer
formatThe source data format (nullopt = attempt to discover format from source)
Here is the call graph for this function:

◆ BufferIn() [2/4]

BufferIn::BufferIn ( const Memory & sourceMem,
DataFormat::Option format = DataFormat{} )

Constructor

Parameters
sourceMemA source block of memory. NB: The buffer does not take ownership of this object - must be maintained for the buffer
formatThe source data format (nullopt = attempt to discover format from source)
Here is the call graph for this function:

◆ BufferIn() [3/4]

BufferIn::BufferIn ( const String & sourceString,
DataFormat::Option format = DataFormat{} )

Constructor

Parameters
sourceStringThe source data string. NB: The buffer does not take ownership of this object - must be maintained for the buffer
formatThe source data format (nullopt = attempt to discover format from source)
Here is the call graph for this function:

◆ BufferIn() [4/4]

BufferIn::BufferIn ( BufferIn && source)
noexcept

Move constructor

Parameters
sourceThe object to move

Member Function Documentation

◆ data()

const char * active::utility::BufferIn::data ( ) const
inline

Get a pointer to the raw buffer data (NB: only intended for low-level APIs that require pointer/length buffering - avoid otherwise)

Returns
A pointer to the buffer data (nullptr if the buffer has no source - dataSize will return the number of bytes in the buffer)
Here is the call graph for this function:

◆ dataSize()

Memory::size_type active::utility::BufferIn::dataSize ( ) const
inline

Get the number of bytes remaining in the buffer

Returns
The number of bytes remaining in the buffer
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find() [1/2]

bool BufferIn::find ( char32_t toFind,
String * pool = nullptr,
bool isFoundSkipped = false ) const

Find a specified character in the buffered content (skipping over all all non-matching data)

Parameters
toFindThe character to find (UTF-32)
poolOptional string to collect the skipped characters (nullptr = discard)
isFoundSkippedTrue if the buffer read position should skip over the found byte
Returns
True if a match is found
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find() [2/2]

bool active::utility::BufferIn::find ( const String & toFind,
String * pool = nullptr,
bool isFoundSkipped = false ) const
inline

Find a specified string in the buffered content (skipping over all all non-matching data)

Parameters
toFindThe string to find (UTF-32)
poolOptional string to collect the skipped characters (nullptr = discard)
isFoundSkippedTrue if the buffer read position should skip over the found string
Returns
True if a match is found

◆ findFirstNotOf()

bool active::utility::BufferIn::findFirstNotOf ( const String & toFind,
String * pool = nullptr,
std::optional< char32_t > escapeChar = std::nullopt ) const
inline

Find the first character not matching a specified set (so it will be the next character read)

Parameters
toFindA string containing the character(s) to skip
poolOptional string to collect the skipped characters (nullptr = discard)
escapeCharAn optional escape char signifying the next character is escaped
Returns
True if a match is found
Here is the caller graph for this function:

◆ findFirstOf()

bool active::utility::BufferIn::findFirstOf ( const String & toFind,
String * pool = nullptr,
bool isContiguousMatch = false,
bool isRepeatMatch = false,
bool isFoundSkipped = false,
bool isFoundPooled = false,
std::optional< char32_t > escapeChar = std::nullopt ) const
inline

Find the first character from a specified string in the buffered content (skipping over all all non-matching data)

Parameters
toFindA string containing the character(s) to find
poolOptional pool string to collect the skipped characters (nullptr = discard)
isContiguousMatchTrue if contiguous matching characters should be found, e.g. any grouping of CR and LF chars
isRepeatMatchUsed when isContiguousMatch = true; true to match found chars multiple times (e.g. all contiguous white-chars)
isFoundSkippedTrue if the buffer read position should skip over the found character
isFoundPooledTrue to add found character(s) to the pool string (ignored if isFoundSkipped = false)
escapeCharAn optional escape char signifying the next character is escaped
Returns
True if a match is found
Here is the caller graph for this function:

◆ findIf()

bool BufferIn::findIf ( const String::Filter & filter,
String * pool = nullptr,
bool isFoundSkipped = false ) const

Find the specified string within this using a filter

Parameters
filterThe string filter
poolOptional string to collect the skipped characters (nullptr = discard)
isFoundSkippedTrue if the buffer read position should skip over the found byte
Returns
True if a match is found
Here is the call graph for this function:
Here is the caller graph for this function:

◆ forEach()

void BufferIn::forEach ( const String::Function & func,
String * pool = nullptr ) const

Apply a function to the buffered characters

Parameters
funcThe character function
poolOptional string to collect the values returned from the function (nullptr = discard)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get() [1/2]

const BufferIn & BufferIn::get ( String & dest) const

Get a single char in a string (supporting multi-byte chars)

Parameters
destThe incoming char (supporting unicode)
Returns
A reference to this
Here is the call graph for this function:

◆ get() [2/2]

const BufferIn & BufferIn::get ( unsigned char & dest) const

Get a single char

Parameters
destThe incoming char
Returns
A reference to this
Here is the caller graph for this function:

◆ getEncodedChar() [1/2]

std::pair< char32_t, Memory::size_type > BufferIn::getEncodedChar ( bool isConsumed = true) const

Get the next character from the buffer as a UTF32 char

Parameters
isConsumedTrue to consume the character bytes from the buffer
Returns
The character coupled with the number of bytes consumed by the next character (0 bytes = no char read)
Here is the call graph for this function:

◆ getEncodedChar() [2/2]

Memory::size_type BufferIn::getEncodedChar ( String & encodedChar,
bool isConsumed = true ) const

Get the next character from the buffer, encoding as necessary

Parameters
encodedCharThe next encoded character (empty on failure)
isConsumedTrue to consume the character bytes from the buffer
Returns
The number of bytes consumed by the next character (0 bytes = no char read)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLastColumn()

Memory::size_type active::utility::BufferIn::getLastColumn ( ) const
inline

Get the current column position

Returns
The current column position

◆ getLastRow()

Memory::size_type active::utility::BufferIn::getLastRow ( ) const
inline

Get the current row position

Returns
The current row position

◆ getLine()

const BufferIn & BufferIn::getLine ( String & line,
bool keepStop = true ) const

Get a single line (terminating at any known line ending)

Parameters
lineThe incoming line
keepStopTrue to keep the line terminator(s)
Returns
A reference to this

◆ getPosition()

Memory::size_type BufferIn::getPosition ( ) const

Get the current read position in the source data (not the read position in the buffer)

Returns
The read position (e.g. the read position in a source file)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getString()

const BufferIn & BufferIn::getString ( String & dest,
String::sizeOption howMany = std::nullopt ) const

Get a string of a specified number of characters

Parameters
destThe incoming string
howManyThe number of whole characters to get (nullopt to read all)
Returns
A reference to this
Here is the call graph for this function:

◆ getValue()

template<class T >
const BufferIn & active::utility::BufferIn::getValue ( T & val) const
inline

Get a value of a specified type from a buffer

Parameters
valThe value to read
Returns
A reference to this
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator bool()

active::utility::BufferIn::operator bool ( ) const
inline

Bool operator

Returns
True if the source is not is a failed state
Here is the call graph for this function:

◆ operator=()

BufferIn & BufferIn::operator= ( BufferIn && source)
noexcept

Assignment with move operator

Parameters
sourceThe object to move
Returns
A reference to this object

◆ operator>>() [1/7]

const BufferIn & BufferIn::operator>> ( double & val) const

Read operator

Parameters
valA double to read
Returns
A reference to this
Here is the call graph for this function:

◆ operator>>() [2/7]

const BufferIn & active::utility::BufferIn::operator>> ( int16_t & val) const
inline

Read operator

Parameters
valA 16-bit integer to read
Returns
A reference to this
Here is the call graph for this function:

◆ operator>>() [3/7]

const BufferIn & active::utility::BufferIn::operator>> ( int32_t & val) const
inline

Read operator

Parameters
valA 32-bit integer to read
Returns
A reference to this
Here is the call graph for this function:

◆ operator>>() [4/7]

const BufferIn & active::utility::BufferIn::operator>> ( int64_t & val) const
inline

Read operator

Parameters
valA 64-bit integer to read
Returns
A reference to this
Here is the call graph for this function:

◆ operator>>() [5/7]

const BufferIn & active::utility::BufferIn::operator>> ( String & str) const
inline

Read operator (the next word)

Parameters
strA string to read
Returns
A reference to this
Here is the call graph for this function:

◆ operator>>() [6/7]

const BufferIn & active::utility::BufferIn::operator>> ( uint32_t & val) const
inline

Read operator

Parameters
valAn unsigned 32-bit integer to read
Returns
A reference to this
Here is the call graph for this function:

◆ operator>>() [7/7]

const BufferIn & active::utility::BufferIn::operator>> ( uint64_t & val) const
inline

Read operator

Parameters
valAn unsigned 64-bit integer to read
Returns
A reference to this
Here is the call graph for this function:

◆ read()

const BufferIn & BufferIn::read ( char * dest,
Memory::size_type & howMany ) const

Read a stream of bytes

Parameters
destThe data destination
howManyThe number of bytes to read (contains the number of bytes actually read on return)
Returns
A reference to this
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readWord()

String BufferIn::readWord ( const String & division = String::allWhiteSpace) const

Read a word (starting from the first non-dividing character and up to next dividing character)

Parameters
divisionThe dividing character(s)
Returns
The word read (empty if not found)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readWords()

std::vector< String > BufferIn::readWords ( Memory::sizeOption howMany = std::nullopt,
const String & division = String::allWhiteSpace ) const

Read multiple words from the buffer

Parameters
howManyOptional limit on the number of words to read (nullopt = to end of buffer)
divisionThe dividing character(s)
Returns
The found words
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rewind()

const BufferIn & BufferIn::rewind ( Memory::size_type howMany) const

Rewind a specified number of bytes backward in the input source

Parameters
howManyThe number of bytes to rewind back
Returns
A reference to this
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFormat()

void active::utility::BufferIn::setFormat ( DataFormat format)
inline

Set The source text encoding

Parameters
formatThe source data format

◆ setPosition()

void BufferIn::setPosition ( Memory::size_type pos) const

Set the current read position in the source data (not the read position in the buffer)

Parameters
posThe read position (e.g. the read position in a source file)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSource() [1/3]

void BufferIn::setSource ( const file::File & sourceFile,
DataFormat::Option format = DataFormat{} )

Set the data source

Parameters
sourceFileThe source data file. NB: The buffer does not take ownership of this object - must be maintained for the buffer
formatThe source data format (nullopt = discover format from source)
Here is the caller graph for this function:

◆ setSource() [2/3]

void BufferIn::setSource ( const Memory & sourceMem,
DataFormat::Option format = DataFormat{} )

Set the data source

Parameters
sourceMemA source block of memory. NB: The buffer does not take ownership of this object - must be maintained for the buffer
formatThe source data format (nullopt = discover format from source)
Here is the call graph for this function:

◆ setSource() [3/3]

void BufferIn::setSource ( const String & sourceString,
DataFormat::Option format = DataFormat{} )

Set the data source

Parameters
sourceStringThe source data string. NB: The buffer does not take ownership of this object - must be maintained for the buffer
formatThe source data format (nullopt = discover format from source)
Here is the call graph for this function:

◆ setSourceEncoding()

void active::utility::BufferIn::setSourceEncoding ( TextEncoding encoding)
inline

Set the source encoding type

Parameters
encodingThe source encoding type

◆ skip()

const BufferIn & BufferIn::skip ( Memory::size_type howMany) const

Skip a specified number of bytes forward in the input source

Parameters
howManyThe number of bytes to skip forward
Returns
A reference to this
Here is the call graph for this function:

◆ sourceSize()

Memory::size_type BufferIn::sourceSize ( ) const

Get the total number of bytes in the source, e.g. the source file/string/memory

Returns
The total number of bytes in the source
Here is the call graph for this function:
Here is the caller graph for this function:

◆ swap()

void BufferIn::swap ( BufferIn & other)

Swap this buffer with another

Parameters
otherThe buffer to swap with this

◆ textEncoding()

TextEncoding active::utility::BufferIn::textEncoding ( ) const
inline

Get The source text encoding (NB: for text input functionality only)

Returns
The text encoding type

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