35 #define S_ISNAN(x) (x != x) 39 #define S_ISINF(x) (x != 0.0 && x + x == x) 43 #define isdigit(x) ('0' <= x && x <= '9') 78 static const char DEFAULT_FILL_CHAR =
' ';
113 fillChar(DEFAULT_FILL_CHAR) {
117 static const Format DEFAULT_FORMAT;
129 : m_printCapable(printCapable),
146 this->m_cooked = cooked;
162 return this->m_cooked;
171 if (this->m_cooked &&
'\n' == c)
172 this->m_printCapable->put_char(
'\r');
173 this->m_printCapable->put_char(c);
183 void puts (
const char string[])
const {
185 for (
const char *s =
string; *s; ++s)
188 this->m_printCapable->puts(
string);
201 const char fillChar = DEFAULT_FILL_CHAR)
const {
218 const char fillChar = DEFAULT_FILL_CHAR)
const {
219 char buf[
sizeof(x) * 8];
225 const unsigned int digit = x %
radix;
226 buf[i] = digit > 9 ? digit +
'A' - 10 : digit +
'0';
238 for (
unsigned int j = 0; j < i; ++j)
255 const char fillChar = DEFAULT_FILL_CHAR)
const {
287 if (((
int) f) & 0x80000000)
317 for (ctr = 0; ctr <= reps; ctr++) {
327 for (; scale >= 1.0; scale /= 10.0) {
332 for (; scale >= 1.0; scale /= 10.0) {
333 c = (char) (f / scale);
334 f -= ((float) c * scale);
369 s[j++] = (char) f +
'0';
377 for (; (j >= 0); j--)
378 if (!(s[j] <
'0' || s[j] >
'9')) {
439 template<
typename T,
typename... Targs>
440 void printf (
const char fmt[],
const T first,
const Targs... remaining)
const {
456 format.
fillChar = DEFAULT_FILL_CHAR;
459 while (c && isdigit(c)) {
460 format.
width = (uint16_t) (10 * format.
width + (c -
'0'));
467 while (c && isdigit(c)) {
478 this->
print((
int) first, format);
484 this->
print((
unsigned int) first, format);
489 this->
print(first, format);
495 if (0 ==
sizeof...(remaining))
498 this->
printf(s, remaining...);
522 void print (
const char c,
const Format format = DEFAULT_FORMAT)
const {
532 void print (
const char string[],
const Format format = DEFAULT_FORMAT)
const {
559 void print (
const bool b,
const Format format = DEFAULT_FORMAT)
const {
569 void print (
const unsigned int x,
const Format format = DEFAULT_FORMAT)
const {
570 this->
put_uint(x, format.radix, format.width, format.fillChar);
579 void print (
const int x,
const Format format = DEFAULT_FORMAT)
const {
580 this->
put_int(x, format.radix, format.width, format.fillChar);
589 void print (
const double f,
const Format format = DEFAULT_FORMAT)
const {
590 this->
put_float(f, format.width, format.precision, format.fillChar);
void printf(const char fmt[]) const
void put_float(double f, uint16_t width=0, uint16_t precision=6, const char fillChar=DEFAULT_FILL_CHAR) const
Print a floating point number with a given width and precision.
void put_char(const char c) const
Print a single character.
Printer(PrintCapable *printCapable, const bool cooked=true)
Construct a Printer instance that will use the given *printCapable instance for sending each characte...
Generic definitions and functions for the Parallax Propeller.
bool get_cooked() const
Determine if the printer is configured for cooked mode or not.
void print(const unsigned int x, const Format format=DEFAULT_FORMAT) const
Print an unsigned integer with the given format.
void print(const bool b, const Format format=DEFAULT_FORMAT) const
Print a boolean as either "true" or "false".
const PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
void printf(const char fmt[], const T first, const Targs...remaining) const
Similar in functionality to the C-standard function printf.
void put_uint(unsigned int x, const uint8_t radix=10, uint16_t width=0, const char fillChar=DEFAULT_FILL_CHAR) const
Print an unsigned integer in base 10.
static const char * to_string(const bool b)
Convert a boolean to the string-literal either "true" or "false"
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.
const Printer & operator<<(const T arg) const
The << operator allows for highly optimized use of the Printer.
void print(const int x, const Format format=DEFAULT_FORMAT) const
Print a single character.
void print(const double f, const Format format=DEFAULT_FORMAT) const
Print a single character.
void println() const
Print a newline (' ')
void set_cooked(const bool cooked)
Turn on or off cooked mode.
void put_int(int x, const uint8_t radix=10, uint16_t width=0, const char fillChar=DEFAULT_FILL_CHAR) const
Print a signed integer in base 10.
Interface for all classes capable of printing.
void print(const char c, const Format format=DEFAULT_FORMAT) const
Print a single character.
void println(const char string[]) const
Print a null-terminated string followed by a newline (' ')
void print(const char string[], const Format format=DEFAULT_FORMAT) const
Print a null-terminated string.