|  | reflex::BufferedInput Class Reference updated Wed Apr 10 2024 by Robert van Engelen |

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Classes | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
reflex::BufferedInput Class Reference

Buffered input. More...

`#include <input.h>`

Inheritance diagram for reflex::BufferedInput:
[legend]
Collaboration diagram for reflex::BufferedInput:
[legend]

## Classes

class | dos_streambuf
| Buffered stream buffer for reflex::Input to read DOS files, replaces CRLF by LF, derived from std::streambuf. More...
class | streambuf
| Buffered stream buffer for reflex::Input, derived from std::streambuf. More...

## Public Member Functions

| BufferedInput ()
| BufferedInput (const BufferedInput &input)
| Copy constructor. More...
| BufferedInput (const Input &input)
| Construct buffered input from unbuffered input. More...
BufferedInput & | operator= (const Input &input)
| Assignment operator from unbuffered input. More...
BufferedInput & | operator= (const BufferedInput &input)
| Copy assignment operator. More...
| BufferedInput (FILE *file, file_encoding_type enc, const unsigned short *page=NULL)
| Construct buffered input character sequence from an open FILE* file descriptor, using the specified file encoding. More...
| operator bool ()
size_t | size ()
| Get the size of the input character sequence in number of ASCII/UTF-8 bytes (zero if size is not determinable from a `FILE*` or `std::istream` source). More...
bool | good ()
| Check if input is available. More...
bool | eof ()
| Check if input reached EOF. More...
int | peek ()
| Peek a single character (unsigned char 0..255) or EOF (-1) when end-of-input is reached. More...
int | get ()
| Get a single character (unsigned char 0..255) or EOF (-1) when end-of-input is reached. More...
size_t | get (char *s, size_t n)
| Copy character sequence data into buffer. More...
Public Member Functions inherited from reflex::Input
| Input ()
| Construct empty input character sequence. More...
| Input (const Input &input)
| Copy constructor (with intended "move semantics" as internal state is shared, should not rely on using the rhs after copying). More...
| Input (const char *cstring, size_t size)
| Construct input character sequence from a char* string. More...
| Input (const char *cstring)
| Construct input character sequence from a NUL-terminated string. More...
| Input (const std::string &string)
| Construct input character sequence from a std::string. More...
| Input (const std::string *string)
| Construct input character sequence from a pointer to a std::string. More...
| Input (const wchar_t *wstring)
| Construct input character sequence from a NUL-terminated wide character string. More...
| Input (const std::wstring &wstring)
| Construct input character sequence from a std::wstring (may contain UTF-16 surrogate pairs). More...
| Input (const std::wstring *wstring)
| Construct input character sequence from a pointer to a std::wstring (may contain UTF-16 surrogate pairs). More...
| Input (FILE *file)
| Construct input character sequence from an open FILE* file descriptor, supports UTF-8 conversion from UTF-16 and UTF-32. More...
| Input (FILE *file, file_encoding_type enc, const unsigned short *page=NULL)
| Construct input character sequence from an open FILE* file descriptor, using the specified file encoding. More...
| Input (std::istream &istream)
| Construct input character sequence from a std::istream. More...
| Input (std::istream *istream)
| Construct input character sequence from a pointer to a std::istream. More...
Input & | operator= (const Input &input)
| Copy assignment operator. More...
| operator const char * () const
| Cast this Input object to a string, returns NULL when this Input is not a string. More...
| operator const wchar_t * () const
| Cast this Input object to a wide character string, returns NULL when this Input is not a wide string. More...
| operator FILE * () const
| Cast this Input object to a file descriptor FILE*, returns NULL when this Input is not a FILE*. More...
| operator std::istream * () const
| Cast this Input object to a std::istream*, returns NULL when this Input is not a std::istream. More...
| operator bool () const
const char * | cstring () const
| Get the remaining string of this Input object, returns NULL when this Input is not a string. More...
const wchar_t * | wstring () const
| Get the remaining wide character string of this Input object, returns NULL when this Input is not a wide string. More...
FILE * | file () const
| Get the FILE* of this Input object, returns NULL when this Input is not a FILE*. More...
std::istream * | istream () const
| Get the std::istream of this Input object, returns NULL when this Input is not a std::istream. More...
size_t | size ()
| Get the size of the input character sequence in number of ASCII/UTF-8 bytes (zero if size is not determinable from a `FILE*` or `std::istream` source). More...
bool | assigned () const
| Check if this Input object was assigned a character sequence. More...
void | clear ()
| Clear this Input by unassigning it. More...
bool | good () const
| Check if input is available. More...
bool | eof () const
| Check if input reached EOF. More...
int | get ()
| Get a single character (unsigned char 0..255) or EOF (-1) when end-of-input is reached. More...
size_t | get (char *s, size_t n)
| Copy character sequence data into buffer. More...
void | file_encoding (file_encoding_type enc, const unsigned short *page=NULL)
| Set encoding for `FILE*` input. More...
file_encoding_type | file_encoding () const
| Get encoding of the current `FILE*` input. More...
void | init ()
| Initialize the state after (re)setting the input source, auto-detects UTF BOM in FILE* input if the file size is known. More...
void | file_init ()
| Called by init() for a FILE*. More...
void | wstring_size ()
| Called by size() for a wstring. More...
void | file_size ()
| Called by size() for a FILE*. More...
void | istream_size ()
| Called by size() for a std::istream. More...
size_t | file_get (char *s, size_t n)
| Implements get() on a FILE*. More...
void | set_handler (Handler *handler)
| Set FILE* handler. More...

## Static Public Attributes

static const size_t | SIZE = 16384
| Buffer size. More...

## Protected Attributes

char | buf_ [SIZE]
size_t | len_
size_t | pos_
Protected Attributes inherited from reflex::Input
const char * | cstring_
| char string input (when non-null) of length reflex::Input::size_ More...
const wchar_t * | wstring_
| NUL-terminated wide string input (when non-null) More...
FILE * | file_
| FILE* input (when non-null) More...
std::istream * | istream_
| stream input (when non-null) More...
size_t | size_
| size of the remaining input in bytes (size_ == 0 may indicate size is not set) More...
char | utf8_ [8]
| UTF-8 normalization buffer, >=8 bytes. More...
unsigned short | uidx_
| index in utf8_[] More...
unsigned short | ulen_
| length of data (remaining after uidx_) in utf8_[] or 0 if no data More...
file_encoding_type | utfx_
| file_encoding More...
const unsigned short * | page_
| custom code page More...
Handler * | handler_
| to handle FILE* errors and non-blocking FILE* reads More...

## Additional Inherited Members

Public Types inherited from reflex::Input
typedef unsigned short | file_encoding_type
| Common file_encoding constants type. More...

## Detailed Description

Buffered input.

## Constructor & Destructor Documentation

reflex::BufferedInput::BufferedInput | ( |  | ) |

inline

Copy constructor (with intended "move semantics" as internal state is shared, should not rely on using the rhs after copying). Construct empty buffered input.

reflex::BufferedInput::BufferedInput | ( | const BufferedInput & | input | ) |

inline

Copy constructor.

reflex::BufferedInput::BufferedInput | ( | const Input & | input | ) |

inline

Construct buffered input from unbuffered input.

reflex::BufferedInput::BufferedInput | ( | FILE * | file,
|  | file_encoding_type | enc,
|  | const unsigned short * | page = `NULL`
| ) |  |

inline

Construct buffered input character sequence from an open FILE* file descriptor, using the specified file encoding.

Parameters

  file | input file
  enc | file_encoding (when UTF BOM is not present)
  page | code page for file_encoding::custom

## Member Function Documentation

bool reflex::BufferedInput::eof | ( |  | ) |

inline

Check if input reached EOF.

Returns
  true if input is at EOF and no characters are available

int reflex::BufferedInput::get | ( |  | ) |

inline

Get a single character (unsigned char 0..255) or EOF (-1) when end-of-input is reached.

size_t reflex::BufferedInput::get | ( | char * | s,
|  | size_t | n
| ) |  |

inline

Copy character sequence data into buffer.

Parameters

  s | points to the string buffer to fill with input
  n | size of buffer pointed to by s

bool reflex::BufferedInput::good | ( |  | ) |

inline

Check if input is available.

Returns
  true if a non-empty sequence of characters is available to get

reflex::BufferedInput::operator bool | ( |  | ) |

inline

Returns
  true if a non-empty sequence of characters is available to get

BufferedInput& reflex::BufferedInput::operator= | ( | const Input & | input | ) |

inline

Assignment operator from unbuffered input.

BufferedInput& reflex::BufferedInput::operator= | ( | const BufferedInput & | input | ) |

inline

Copy assignment operator.

int reflex::BufferedInput::peek | ( |  | ) |

inline

Peek a single character (unsigned char 0..255) or EOF (-1) when end-of-input is reached.

size_t reflex::BufferedInput::size | ( |  | ) |

inline

Get the size of the input character sequence in number of ASCII/UTF-8 bytes (zero if size is not determinable from a `FILE*` or `std::istream` source).

Returns
  the nonzero number of ASCII/UTF-8 bytes available to read, or zero when source is empty or if size is not determinable e.g. when reading from standard input

## Member Data Documentation

char reflex::BufferedInput::buf_[SIZE]

protected

size_t reflex::BufferedInput::len_

protected

size_t reflex::BufferedInput::pos_

protected

const size_t reflex::BufferedInput::SIZE = 16384

static

Buffer size.

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

- input.h