PropWare
C++ objects and CMake build system for Parallax Propeller
|
Interface for all classes capable of scanning. More...
#include <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) |
template<typename T > | |
const Scanner & | operator>> (T &c) |
Extract formatted input. More... | |
const ErrorCode | get (char &c) |
Extract formatted input. More... | |
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' |
PropWare::Scanner::Scanner | ( | ScanCapable * | scanCapable, |
const Printer * | printer = NULL |
||
) |
const ErrorCode PropWare::Scanner::get | ( | char & | c | ) |
const ErrorCode PropWare::Scanner::get | ( | uint32_t & | x | ) |
const ErrorCode PropWare::Scanner::get | ( | int32_t & | x | ) |
const ErrorCode PropWare::Scanner::get | ( | float & | f | ) |
char PropWare::Scanner::get_char | ( | ) |
Definition at line 71 of file scanner.h.
ErrorCode PropWare::Scanner::gets | ( | char | string[], |
int32_t | length, | ||
const char | delimiter = DEFAULT_DELIMITER |
||
) |
Definition at line 81 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 205 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 238 of file scanner.h.
const Scanner& PropWare::Scanner::operator>> | ( | T & | c | ) |