34 extern const char *_scanf_getl (
const char *str,
int *dst,
int base,
unsigned width,
int isSigned);
35 extern const char *_scanf_getf (
const char *str,
float *dst);
53 static const char DEFAULT_DELIMITER =
'\n';
64 : m_scanCapable(scanCapable),
72 const char c = this->m_scanCapable->
get_char();
73 if (NULL != this->m_printer)
81 ErrorCode
gets (
char string[], int32_t length,
const char delimiter = DEFAULT_DELIMITER) {
83 while (0 < --length) {
84 char ch = this->m_scanCapable->
get_char();
86 if (ch == 8 || ch == 127) {
88 if (NULL != this->m_printer)
89 this->m_printer->
puts(
"\010 \010");
97 if (NULL != this->m_printer) {
104 if (
'\r' == ch ||
'\n' == ch)
134 const ErrorCode
get (
char &c) {
137 check_errors(this->
gets(userInput,
sizeof(userInput)));
149 const ErrorCode
get (uint32_t &x) {
152 check_errors(this->
gets(userInput,
sizeof(userInput)));
153 if (0 == _scanf_getl(userInput, (
int *) &x, 10, 11,
false))
162 const ErrorCode
get (int32_t &x) {
165 check_errors(this->
gets(userInput,
sizeof(userInput)));
166 if (0 == _scanf_getl(userInput, &x, 10, 11,
false))
175 const ErrorCode
get (
float &f) {
178 check_errors(this->
gets(userInput,
sizeof(userInput)));
179 if (0 == _scanf_getf(userInput, &f))
205 void input_prompt (
const char prompt[],
const char failureResponse[],
char userInput[],
208 this->m_printer->
puts(prompt);
209 this->
gets(userInput, bufferLength);
211 if (comparator.
valid(userInput))
214 this->m_printer->
puts(failureResponse);
238 void input_prompt (
const char prompt[],
const char failureResponse[], T *userInput,
240 const T original = *userInput;
243 this->m_printer->
puts(prompt);
244 err = this->
get(*userInput);
248 this->m_printer->
puts(failureResponse);
249 *userInput = original;
Interface for all classes capable of printing.
void put_char(const char c) const
Print a single character.
Generic definitions and functions for the Parallax Propeller.
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.
virtual char get_char()=0
Read and return a single character. Whether the method is blocking or not depends entirely on the imp...
Container class that has formatting methods for human-readable output. This class can be constructed ...
void puts(const char string[]) const
Send a null-terminated character array.
virtual bool valid(const T *lhs) const =0
Determines if the given argument is valid.
Scanner(ScanCapable *scanCapable, const Printer *printer=NULL)
Construct a Scanner instance and control whether or not received characters are echoed back via the *...
Interface for all classes capable of scanning.
ErrorCode gets(char string[], int32_t length, const char delimiter=DEFAULT_DELIMITER)
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.
const Scanner & operator>>(T &c)
Extract formatted input.