|
PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
Go to the documentation of this file.
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';
65 : m_scanCapable(&scanCapable),
73 const char c = this->m_scanCapable->
get_char();
74 if (NULL != this->m_printer)
91 ErrorCode gets (
char string[], int32_t length,
const char delimiter = DEFAULT_DELIMITER) {
93 while (0 < --length) {
94 char ch = this->m_scanCapable->
get_char();
96 if (ch == 8 || ch == 127) {
98 if (NULL != this->m_printer)
99 this->m_printer->
puts(
"\010 \010");
107 if (NULL != this->m_printer) {
110 if (
'\n' == delimiter &&
'\r' == ch)
114 if (!ch || delimiter == ch || (
'\n' == delimiter &&
'\r' == ch))
138 while (0 < --length) {
139 const char ch = this->m_scanCapable->
get_char();
141 if (ch == 8 || ch == 127) {
143 if (NULL != this->m_printer)
144 this->m_printer->
puts(
"\010 \010");
152 if (NULL != this->m_printer) {
156 if (!ch || strchr(delimiters, ch))
189 check_errors(this->
get_token(userInput,
sizeof(userInput)));
204 check_errors(this->
get_token(userInput,
sizeof(userInput)));
206 if (0 == _scanf_getl(userInput, &tmp, 10, 11,
false))
209 x =
static_cast<uint8_t
>(tmp);
215 const ErrorCode
get (
char (&buffer)[N]) {
216 return this->
gets(buffer, N);
225 check_errors(this->
get_token(userInput,
sizeof(userInput)));
227 if (0 == _scanf_getl(userInput, &tmp, 10, 11,
false))
230 x =
static_cast<uint16_t
>(tmp);
242 check_errors(this->
get_token(userInput,
sizeof(userInput)));
244 if (0 == _scanf_getl(userInput, &tmp, 10, 11,
false))
247 x =
static_cast<int16_t
>(tmp);
258 check_errors(this->
get_token(userInput,
sizeof(userInput)));
259 if (0 == _scanf_getl(userInput, (
int *) &
x, 10, 11,
false))
271 check_errors(this->
get_token(userInput,
sizeof(userInput)));
272 if (0 == _scanf_getl(userInput, &
x, 10, 11,
false))
284 check_errors(this->
get_token(userInput,
sizeof(userInput)));
285 if (0 == _scanf_getf(userInput, &f))
311 void input_prompt (
const char prompt[],
const char failureResponse[],
char userInput[],
314 this->m_printer->
puts(prompt);
315 this->
gets(userInput, bufferLength);
317 if (comparator.
valid(userInput))
320 this->m_printer->
puts(failureResponse);
344 void input_prompt (
const char prompt[],
const char failureResponse[], T *userInput,
346 const T original = *userInput;
349 this->m_printer->
puts(prompt);
350 err = this->
get(*userInput);
354 this->m_printer->
puts(failureResponse);
355 *userInput = original;
366 #ifndef __PROPELLER_COG__
const ErrorCode get(char &c)
Extract formatted input.
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.
Interface for all classes capable of scanning.
virtual char get_char()=0
Read and return a single character. Whether the method is blocking or not depends entirely on the imp...
const ErrorCode get(int16_t &x)
Interface for all classes capable of printing.
Scanner(ScanCapable &scanCapable, const Printer *printer=NULL)
Construct a Scanner instance and control whether or not received characters are echoed back via the *...
const ErrorCode get(float &f)
virtual bool valid(const T *lhs) const =0
Determines if the given argument is valid.
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.
const ErrorCode get(uint16_t &x)
ErrorCode gets(char string[], int32_t length, const char delimiter=DEFAULT_DELIMITER)
Read words from the bus until the delimiter is received.
const ErrorCode get(uint32_t &x)
const ErrorCode get(int32_t &x)
Scanner & operator>>(T &c)
Extract formatted input.
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.
static const char WHITESPACE_CHARS[]
Set of all standard whitespace.
void puts(const char string[]) const
Send a null-terminated character array.
const ErrorCode get(uint8_t &x)
Container class that has formatting methods for human-readable output. This class can be constructed ...
Generic definitions and functions for the Parallax Propeller.
void put_char(const char c) const
Print a single character.