PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
Interface for all classes capable of scanning. More...
#include <PropWare/hmi/input/scanner.h>
Public Types | |
enum | ErrorCode { NO_ERROR = 0, BEG_ERROR, BAD_INPUT = BEG_ERROR, END_ERROR = BAD_INPUT } |
Public Member Functions | |
Scanner (ScanCapable &scanCapable, const Printer *printer=NULL) | |
Construct a Scanner instance and control whether or not received characters are echoed back via the *printer argument. More... | |
char | get_char () |
ErrorCode | gets (char string[], int32_t length, const char delimiter=DEFAULT_DELIMITER) |
Read words from the bus until the delimiter is received. More... | |
ErrorCode | get_token (char string[], int32_t length, const char *delimiters=WHITESPACE_CHARS) |
Read characters from the bus until the any one of the given delimiters is received. More... | |
template<typename T > | |
Scanner & | operator>> (T &c) |
Extract formatted input. More... | |
const ErrorCode | get (char &c) |
Extract formatted input. More... | |
const ErrorCode | get (uint8_t &x) |
template<size_t N> | |
const ErrorCode | get (char(&buffer)[N]) |
const ErrorCode | get (uint16_t &x) |
const ErrorCode | get (int16_t &x) |
const ErrorCode | get (uint32_t &x) |
const ErrorCode | get (int32_t &x) |
const ErrorCode | get (float &f) |
void | input_prompt (const char prompt[], const char failureResponse[], char userInput[], const size_t bufferLength, const Comparator< char > &comparator) |
Prompt the user for input and store the value only if it is sanitized. More... | |
template<typename T > | |
void | input_prompt (const char prompt[], const char failureResponse[], T *userInput, const Comparator< T > &comparator) |
Prompt the user for input and store the value only if it is sanitized. More... | |
Static Public Attributes | |
static const char | DEFAULT_DELIMITER = '\n' |
static const char | WHITESPACE_CHARS [] = "\r\n\t " |
Set of all standard whitespace. | |
Interface for all classes capable of scanning.
PropWare::Scanner::Scanner | ( | ScanCapable & | scanCapable, |
const Printer * | printer = NULL |
||
) |
const ErrorCode PropWare::Scanner::get | ( | int16_t & | x | ) |
const ErrorCode PropWare::Scanner::get | ( | int32_t & | x | ) |
const ErrorCode PropWare::Scanner::get | ( | uint16_t & | x | ) |
const ErrorCode PropWare::Scanner::get | ( | uint32_t & | x | ) |
const ErrorCode PropWare::Scanner::get | ( | uint8_t & | x | ) |
char PropWare::Scanner::get_char | ( | ) |
Definition at line 72 of file scanner.h.
ErrorCode PropWare::Scanner::get_token | ( | char | string[], |
int32_t | length, | ||
const char * | delimiters = WHITESPACE_CHARS |
||
) |
Read characters from the bus until the any one of the given delimiters is received.
If found, the delimiter will be replaced with a null-terminator. If the buffer is filled before a delimiter is found, no null-terminator will be inserted
[in] | string[] | Output buffer which should store the data |
[in] | delimiters | Set of characters (null-terminated), any of which will be considered as the stop point for the reader |
Definition at line 136 of file scanner.h.
ErrorCode PropWare::Scanner::gets | ( | char | string[], |
int32_t | length, | ||
const char | delimiter = DEFAULT_DELIMITER |
||
) |
Read words from the bus until the delimiter is received.
If found, the delimiter will be replaced with a null-terminator. If the buffer is filled before a delimiter is found, no null-terminator will be inserted
[in] | string[] | Output buffer which should store the data |
[in] | length | Maximum number of characters to read |
[in] | delimiter | Character which should be considered as the stop point for the reader |
Definition at line 91 of file scanner.h.
void PropWare::Scanner::input_prompt | ( | const char | prompt[], |
const char | failureResponse[], | ||
char | userInput[], | ||
const size_t | bufferLength, | ||
const Comparator< char > & | comparator | ||
) |
Prompt the user for input and store the value only if it is sanitized.
For safe input of strings only, use this method. For example, to request a yes/no answer, use the YES_NO_COMP shared instance:
[in] | prompt[] | User prompt which will be displayed before each attempt to read the serial bus |
[in] | failureResponse[] | Message to be displayed after each incorrect input |
[out] | userInput[] | Buffer that can be used for storing the user's input |
[in] | bufferLength | Size (in bytes) of the userInput[] buffer |
[in] | comparator | Determines whether or not the received input was valid |
Definition at line 311 of file scanner.h.
void PropWare::Scanner::input_prompt | ( | const char | prompt[], |
const char | failureResponse[], | ||
T * | userInput, | ||
const Comparator< T > & | comparator | ||
) |
Prompt the user for input and store the value only if it is sanitized.
For safe input of any value other than strings, use this method. For example, to request any non-negative number, use the NON_NEGATIVE_COMP shared instance:
[in] | prompt[] | User prompt which will be displayed before each attempt to read the serial bus |
[in] | failureResponse[] | Message to be displayed after each incorrect input |
[out] | *userInput | Resulting value will be stored at this address |
[in] | comparator | Determines whether or not the received input was valid |
Definition at line 344 of file scanner.h.
Scanner& PropWare::Scanner::operator>> | ( | T & | c | ) |