|
PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
Go to the documentation of this file.
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 uint16_t DEFAULT_WIDTH = 0;
79 static const uint16_t DEFAULT_PRECISION = 6;
80 static const uint8_t DEFAULT_RADIX = 10;
81 static const char DEFAULT_FILL_CHAR =
' ';
114 const uint8_t
radix = DEFAULT_RADIX,
const uint16_t
precision = DEFAULT_PRECISION)
122 static const Format DEFAULT_FORMAT;
134 : m_printCapable(&printCapable),
151 this->m_cooked = cooked;
167 return this->m_cooked;
176 if (this->m_cooked &&
'\n' == c)
177 this->m_printCapable->
put_char(
'\r');
188 void puts (
const char string[])
const {
190 for (
const char *s =
string; *s; ++s)
193 this->m_printCapable->
puts(
string);
205 void put_int (
int x,
const uint8_t radix = 10, uint16_t width = 0,
206 const char fillChar = DEFAULT_FILL_CHAR)
const {
210 this->
put_uint((uint32_t) abs(
x), radix, width, fillChar);
222 void put_uint (
unsigned int x,
const uint8_t radix = 10, uint16_t width = 0,
223 const char fillChar = DEFAULT_FILL_CHAR)
const {
224 char buf[
sizeof(
x) * 8];
230 const unsigned int digit =
x % radix;
231 buf[i] =
static_cast<char>(digit > 9 ? digit +
'A' - 10 : digit +
'0');
236 if (width && width > i) {
243 for (
unsigned int j = 0; j < i; ++j)
256 void put_ll (
long long x,
const uint8_t radix = 10, uint16_t width = 0,
257 const char fillChar = DEFAULT_FILL_CHAR)
const {
261 this->
put_ull((
unsigned long long) llabs(
x), radix, width, fillChar);
273 void put_ull (
unsigned long long x,
const uint8_t radix = 10, uint16_t width = 0,
274 const char fillChar = DEFAULT_FILL_CHAR)
const {
275 char buf[
sizeof(
x) * 8];
281 const uint_fast8_t digit =
static_cast<uint_fast8_t
>(
x % radix);
282 buf[i] =
static_cast<char>(digit > 9 ? digit +
'A' - 10 : digit +
'0');
287 if (width && width > i) {
294 for (
unsigned int j = 0; j < i; ++j)
310 void put_float (
double f, uint16_t width = 0, uint16_t precision = 6,
311 const char fillChar = DEFAULT_FILL_CHAR)
const {
343 if (((
int) f) & 0x80000000)
351 precision = (precision > clamp) ? clamp : precision;
373 for (ctr = 0; ctr <= reps; ctr++) {
383 for (; scale >= 1.0; scale /= 10.0) {
388 for (; scale >= 1.0; scale /= 10.0) {
389 c = (
char) (f / scale);
390 f -= ((
float) c * scale);
397 offset = width - j - precision - 1;
425 s[j++] = (
char) f +
'0';
433 for (; (j >= 0); j--)
434 if (!(s[j] <
'0' || s[j] >
'9')) {
496 template<
typename T,
typename... Targs>
497 void printf (
const char fmt[],
const T first,
const Targs... remaining)
const {
513 format.
fillChar = DEFAULT_FILL_CHAR;
517 format.
width = (uint16_t) (10 * format.
width + (c -
'0'));
535 this->
print((
int) first, format);
539 format.
radix =
static_cast<uint8_t
>(
'b' == c ? 2 : 16);
542 this->
print((
unsigned int) first, format);
547 this->
print(first, format);
553 if (0 ==
sizeof...(remaining))
556 this->
printf(s, remaining...);
580 void print (
const char c,
const Format &format = DEFAULT_FORMAT)
const {
590 void print (
const char string[],
const Format &format = DEFAULT_FORMAT)
const {
617 void print (
const bool b,
const Format &format = DEFAULT_FORMAT)
const {
627 void print (
const unsigned int x,
const Format &format = DEFAULT_FORMAT)
const {
628 this->
put_uint(x, format.radix, format.width, format.fillChar);
637 void print (
const int x,
const Format &format = DEFAULT_FORMAT)
const {
638 this->
put_int(x, format.radix, format.width, format.fillChar);
647 void print (
const unsigned long long x,
const Format &format = DEFAULT_FORMAT)
const {
648 this->
put_uint(x, format.radix, format.width, format.fillChar);
657 void print (
const long long x,
const Format &format = DEFAULT_FORMAT)
const {
658 this->
put_int(x, format.radix, format.width, format.fillChar);
667 void print (
const double f,
const Format &format = DEFAULT_FORMAT)
const {
668 this->
put_float(f, format.width, format.precision, format.fillChar);
695 this->
print(arg, this->m_format);
723 this->
print(arg, this->m_format);
728 this->m_format = arg;
733 PrintCapable *m_printCapable;
740 #ifndef __PROPELLER_COG__
bool get_cooked() const
Determine if the printer is configured for cooked mode or not.
void printf(const char fmt[]) const
void print(const char string[], const Format &format=DEFAULT_FORMAT) const
Print a null-terminated string.
void print(const unsigned int x, const Format &format=DEFAULT_FORMAT) const
Print an unsigned integer with the given format.
void printf(const char fmt[], const T first, const Targs... remaining) const
Similar in functionality to the C-standard function printf.
void put_ll(long long x, const uint8_t radix=10, uint16_t width=0, const char fillChar=DEFAULT_FILL_CHAR) const
Print a signed integer in base 10.
void print(const bool b, const Format &format=DEFAULT_FORMAT) const
Print a boolean as either "true" or "false".
void print(const unsigned long long x, const Format &format=DEFAULT_FORMAT) const
Print an unsigned integer with the given format.
void print(const int x, const Format &format=DEFAULT_FORMAT) const
Print a single character.
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.
void set_cooked(const bool cooked)
Turn on or off cooked mode.
void print(const long long x, const Format &format=DEFAULT_FORMAT) const
Print a single character.
void put_ull(unsigned long long x, const uint8_t radix=10, uint16_t width=0, const char fillChar=DEFAULT_FILL_CHAR) const
Print an unsigned integer in base 10.
Printer(PrintCapable &printCapable, const bool cooked=true)
Construct a Printer instance that will use the given *printCapable instance for sending each characte...
Interface for all classes capable of printing.
void print(const double f, const Format &format=DEFAULT_FORMAT) const
Print a single character.
static const char * to_string(const bool b)
Convert a boolean to the string-literal either "true" or "false"
void print(const char c, const Format &format=DEFAULT_FORMAT) const
Print a single character.
PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
virtual void puts(const char string[])=0
Send a null-terminated character array. Though this method could be created using put_char,...
void puts(const char string[]) const
Send a null-terminated character array.
void println() const
Print a newline (' ')
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_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_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.
void put_char(const char c) const
Print a single character.
virtual void put_char(const char c)=0
Print a single character.
const Printer & operator<<(const T arg) const
The << operator allows for highly optimized use of the Printer.
void println(const char string[]) const
Print a null-terminated string followed by a newline (' ')