class::sys::Printer

class sys::Printer
  : public api::WorkObject

The Printer class is used for printing YAML formatted messages to the standard output. The printing mechanisms are virtual and can be re-implemented to print to any output (or multiple outputs).

The Printer class supports the << operator for a growing list of StratifyAPI types.

For example, the following code will print the system information as a YAML object.

//md2code:include
#include <sapi/sys.hpp>
//md2code:main
Printer p;
p.open_object("System Information") << SysInfo::get() << p.close();

Summary

Printer()

~Printer()

void clear_color_code()

void clear_format_code(

u32 code
)

void close_array()

void close_object()

virtual Printer & debug(

const char * fmt,

)

Printer & debug(

const var::ConstString & a
)

void disable_flags(

u32 value
)

void enable_flags(

u32 value
)

virtual Printer & error(

const char * fmt,

)

Printer & error(

const var::ConstString & a
)

virtual Printer & fatal(

const char * fmt,

)

Printer & fatal(

const var::ConstString & a
)

u32 flags() const

virtual Printer & info(

const char * fmt,

)

Printer & info(

const var::ConstString & a
)

virtual Printer & key(

const var::ConstString & key,
const char * fmt,

)

virtual Printer & key(

const var::ConstString & key,
const var::String & a
)

virtual Printer & key(

const var::ConstString & key,
const var::JsonValue & a
)

virtual Printer & message(

const char * fmt,

)

Printer & message(

const var::ConstString & a
)

Printer & open_array(

const var::ConstString & key,
enum verbose_level level
)

Printer & open_object(

const var::ConstString & key,
enum verbose_level level
)

Printer & operator<<(

const api::Result & a
)

Printer & operator<<(

const var::Data & a
)

Printer & operator<<(

const var::Datum & a
)

Printer & operator<<(

const var::DataInfo & a
)

Printer & operator<<(

const var::String & a
)

Printer & operator<<(

const var::Tokenizer & a
)

Printer & operator<<(

const var::JsonObject & a
)

Printer & operator<<(

const var::JsonArray & a
)

Printer & operator<<(

const var::Vector< var::String > & a
)

Printer & operator<<(

const var::Ring< u32 > & a
)

Printer & operator<<(

const var::Ring< s32 > & a
)

Printer & operator<<(

const var::Ring< u16 > & a
)

Printer & operator<<(

const var::Ring< s16 > & a
)

Printer & operator<<(

const var::Ring< u8 > & a
)

Printer & operator<<(

const var::Ring< s8 > & a
)

Printer & operator<<(

const Cli & a
)

Printer & operator<<(

const appfs_file_t & a
)

Printer & operator<<(

const AppfsFileAttributes & a
)

Printer & operator<<(

const TraceEvent & a
)

Printer & operator<<(

const sys::SysInfo & a
)

Printer & operator<<(

const sys::AppfsInfo & a
)

Printer & operator<<(

const sys::TaskInfo & a
)

Printer & operator<<(

const fs::Stat & a
)

Printer & operator<<(

const sgfx::Bitmap & a
)

Printer & operator<<(

const sgfx::Cursor & a
)

Printer & operator<<(

const sgfx::Point & a
)

Printer & operator<<(

const sgfx::Region & a
)

Printer & operator<<(

const sgfx::Area & a
)

Printer & operator<<(

const sgfx::Pen & a
)

Printer & operator<<(

const sgfx::Vector & a
)

Printer & operator<<(

const sgfx::VectorPath & a
)

Printer & operator<<(

const sgfx::VectorPathDescription & a
)

Printer & operator<<(

const chrono::ClockTime & a
)

Printer & operator<<(

const chrono::MicroTime & a
)

Printer & operator<<(

const chrono::Time & a
)

Printer & operator<<(

s32 a
)

Printer & operator<<(

u32 a
)

Printer & operator<<(

s16 a
)

Printer & operator<<(

u16 a
)

Printer & operator<<(

s8 a
)

Printer & operator<<(

u8 a
)

Printer & operator<<(

void * a
)

Printer & operator<<(

const char * a
)

Printer & operator<<(

float a
)

Printer & operator<<(

const hal::DriveInfo & a
)

Printer & operator<<(

const draw::DrawingPoint & a
)

Printer & operator<<(

const draw::DrawingArea & a
)

Printer & operator<<(

const draw::DrawingRegion & a
)

Printer & operator<<(

const PrinterTermination & printer_termination
)

void print(

const char * fmt,

)

const sys::ProgressCallback * progress_callback() const

var::String & progress_key()

const var::String & progress_key() const

void set_color_code(

u32 code
)

void set_flags(

u32 value
)

void set_format_code(

u32 code
)

void set_verbose_level(

enum verbose_level level
)

int set_verbose_level(

const var::ConstString & level
)

bool update_progress(

int progress,
int total
)

enum verbose_level verbose_level() const

virtual Printer & warning(

const char * fmt,

)

Printer & warning(

const var::ConstString & a
)

static PrinterTermination close()

static u32 color_code(

const var::ConstString & color
)

static char get_bitmap_pixel_character(

u32 color,
u8 bits_per_pixel
)

static bool update_progress_callback(

void * context,
int progress,
int total
)

protected void print_indentation()

protected virtual void print_indented(

const var::ConstString & key,
const char * fmt,

)

protected virtual void vprint(

const char * fmt,
va_list list
)

protected virtual void vprint_indented(

const var::ConstString & key,
const char * fmt,
va_list list
)

enum @17

enum @18

enum @19

enum verbose_level

Members

Printer()

~Printer()

void clear_color_code()

void clear_format_code(

u32 code
)


void close_array()

void close_object()

virtual Printer & debug(

const char * fmt,

)

Prints a debug message if the verbose level is set to debug.


Printer & debug(

const var::ConstString & a
)

Prints a debug message if the verbose level is set to debug.


void disable_flags(

u32 value
)


void enable_flags(

u32 value
)


virtual Printer & error(

const char * fmt,

)

Prints an error (filtered according to verbose_level()).


Printer & error(

const var::ConstString & a
)

Prints an error (filtered according to verbose_level()).


virtual Printer & fatal(

const char * fmt,

)

Prints a fatal error message.


Printer & fatal(

const var::ConstString & a
)

Prints a fatal error message.


u32 flags() const

virtual Printer & info(

const char * fmt,

)

Prints information (filtered according to verbose_level()).


Printer & info(

const var::ConstString & a
)

Prints information (filtered according to verbose_level()).


virtual Printer & key(

const var::ConstString & key,
const char * fmt,

)

Prints a key value pair.


virtual Printer & key(

const var::ConstString & key,
const var::String & a
)

Prints a key value pair.


virtual Printer & key(

const var::ConstString & key,
const var::JsonValue & a
)

Prints a key value pair.


virtual Printer & message(

const char * fmt,

)

Prints a message (filtered according to verbose_level()).


Printer & message(

const var::ConstString & a
)

Prints a message (filtered according to verbose_level()).


Printer & open_array(

const var::ConstString & key,
enum verbose_level level
)

Opens a YAML array.

Parameters

  • key The key to be used for the object

  • level The filter level for child keys

YAML object values are not preceded by ‘-’ while arrays are. Objects should have unique keys in order to have properly formatted YAML. The debug(), info(), warning(), error(), and fatal() methods can be used multple times inside of an array and are indexed when parsed.

//md2code:main
Printer p;
//whole object only prints with debug verbose level
p.open_array("keys", Printer::MESSAGE);
p.info("Hello");
p.info("Hello");
p.info("Hello");
p.warning("Hello");
p.message("Hello");
p.message("Hello");
p.warning("Hello");
p.close_array(); //close_array() and close_object() are interchangeable

By default the Printer starts with an open array. The following code can change the top level type to an object.

//md2code:main
Printer p; //printer is now an array
p.close_array();
p.open_object(""); //top level type is an object

Printer & open_object(

const var::ConstString & key,
enum verbose_level level
)

Opens a YAML object.

Parameters

  • key The key to be used for the object

  • level The filter level for child keys

YAML object values are not preceded by ‘-’ while arrays are. Objects should have unique keys in order to have properly formatted YAML. The debug(), info(), warning(), error(), and fatal() methods can be used at most once inside of an object without having a duplicate key. The key() method can be used to assign unique keys to each object.

//md2code:main
Printer p;
//whole object only prints with debug verbose level
p.open_object("keys", Printer::DEBUG);
p.key("key0", "value0");
p.key("key1", "value1");
p.key("key2", "value2");
p.close_object();

Printer & operator<<(

const api::Result & a
)


Printer & operator<<(

const var::Data & a
)

Prints a var::Data object.


Printer & operator<<(

const var::Datum & a
)

Prints a var::Datum object.


Printer & operator<<(

const var::DataInfo & a
)

Prints a var::DataInfo object.


Printer & operator<<(

const var::String & a
)

Prints a var::String object.


Printer & operator<<(

const var::Tokenizer & a
)

Prints a var::Tokenizer object.


Printer & operator<<(

const var::JsonObject & a
)

Prints a var::JsonObject object.


Printer & operator<<(

const var::JsonArray & a
)

Prints a var::JsonArray object.


Printer & operator<<(

const var::Vector< var::String > & a
)

Prints a string list object.


Printer & operator<<(

const var::Ring< u32 > & a
)

Prints a var::Ring object.


Printer & operator<<(

const var::Ring< s32 > & a
)

Prints a var::Ring object.


Printer & operator<<(

const var::Ring< u16 > & a
)

Prints a var::Ring object.


Printer & operator<<(

const var::Ring< s16 > & a
)

Prints a var::Ring object.


Printer & operator<<(

const var::Ring< u8 > & a
)

Prints a var::Ring object.


Printer & operator<<(

const var::Ring< s8 > & a
)

Prints a var::Ring object.


Printer & operator<<(

const Cli & a
)

Prints a sys::Cli object.


Printer & operator<<(

const appfs_file_t & a
)

Prints a sys::appfs_file_t object.


Printer & operator<<(

const AppfsFileAttributes & a
)

Prints a sys::AppfsFileAttributes object.


Printer & operator<<(

const TraceEvent & a
)

Prints a sys::TraceEvent object.


Printer & operator<<(

const sys::SysInfo & a
)

Prints a sys::SysInfo object.


Printer & operator<<(

const sys::AppfsInfo & a
)

Prints a sys::AppfsInfo object.


Printer & operator<<(

const sys::TaskInfo & a
)

Prints a sys::TaskInfo object.


Printer & operator<<(

const fs::Stat & a
)

Prints a file::Info object.


Printer & operator<<(

const sgfx::Bitmap & a
)

Prints a sgfx::Bitmap object.


Printer & operator<<(

const sgfx::Cursor & a
)

Prints a sgfx::Cursor object.


Printer & operator<<(

const sgfx::Point & a
)

Prints a sgfx::Point object.


Printer & operator<<(

const sgfx::Region & a
)

Prints a sgfx::Region object.


Printer & operator<<(

const sgfx::Area & a
)

Prints a sgfx::Area object.


Printer & operator<<(

const sgfx::Pen & a
)

Prints a sgfx::Pen object.


Printer & operator<<(

const sgfx::Vector & a
)

Prints a sgfx::Vector object.


Printer & operator<<(

const sgfx::VectorPath & a
)

Prints a sgfx::VectorPath object.


Printer & operator<<(

const sgfx::VectorPathDescription & a
)

Prints a sgfx::VectorPathDescription object.


Printer & operator<<(

const chrono::ClockTime & a
)

Prints a chrono::ClockTime object.


Printer & operator<<(

const chrono::MicroTime & a
)

Prints a chrono::MicroTime object.


Printer & operator<<(

const chrono::Time & a
)

Prints a chrono::Time object.


Printer & operator<<(

s32 a
)

Prints a basic s32 type (see set_flags() for details).


Printer & operator<<(

u32 a
)

Prints a basic u32 type (see set_flags() for details).


Printer & operator<<(

s16 a
)

Prints a basic s16 type (see set_flags() for details).


Printer & operator<<(

u16 a
)

Prints a basic u16 type (see set_flags() for details).


Printer & operator<<(

s8 a
)

Prints a basic s8 type (see set_flags() for details).


Printer & operator<<(

u8 a
)

Prints a basic u8 type (see set_flags() for details).


Printer & operator<<(

void * a
)

Prints a pointer.


Printer & operator<<(

const char * a
)

Prints a c-style string.


Printer & operator<<(

float a
)

Prints a float type.


Printer & operator<<(

const hal::DriveInfo & a
)


Printer & operator<<(

const draw::DrawingPoint & a
)


Printer & operator<<(

const draw::DrawingArea & a
)


Printer & operator<<(

const draw::DrawingRegion & a
)


Printer & operator<<(

const PrinterTermination & printer_termination
)


void print(

const char * fmt,

)


const sys::ProgressCallback * progress_callback() const

Returns a pointer to the sys::ProgressCallback member.

This method can be used for operations that use sys::ProgressCallback class to update the progress. The progess is printed to the screen with the key set to progress_key().

//md2code:include
#include <sapi/sys.hpp>
#include <sapi/inet.hpp>
#include <sapi/fs.hpp>
//md2code:main
Printer p;

p.progress_key() = var::ConstString("downloading");
Socket socket;
HttpClient http_client(socket);
DataFile data_file(OpenFlags::append_read_write());

//download file to data_file and print the progress using #'s
http_client.get(
  arg::UrlEncodedString("http://some.url/file"),
  arg::DestinationFile(data_file),
  p.progress_callback()
  );

var::String & progress_key()

Access to the key to print during progress updates.


const var::String & progress_key() const

Access (read-only) to the key to print during progress updates.


void set_color_code(

u32 code
)


void set_flags(

u32 value
)

Sets the flags that modify how numbers and some messages are printed.


void set_format_code(

u32 code
)


void set_verbose_level(

enum verbose_level level
)

Assign an effective verbose level to this object.


int set_verbose_level(

const var::ConstString & level
)

Assign a verbose level.

Parameters

  • level The level as ‘fatal’, ‘error’, ‘warning’, ‘info’, ‘message’, or ‘debug’

Returns

Zero on success


bool update_progress(

int progress,
int total
)

Used by progres_callback().


enum verbose_level verbose_level() const

Returns the current verbose level.


virtual Printer & warning(

const char * fmt,

)

Prints a warning (filtered according to verbose_level()).


Printer & warning(

const var::ConstString & a
)

Prints a warning (filtered according to verbose_level()).


static PrinterTermination close()

Returns a printer termination object for closing an array or object with the << operator.

//md2code:main
Printer p;
p.open_object("empty object") << p.close();
p.open_array("messages", Printer::MESSAGE) << "hello" << p.close();

static u32 color_code(

const var::ConstString & color
)


static char get_bitmap_pixel_character(

u32 color,
u8 bits_per_pixel
)

Returns a character that will be printed.

Parameters

  • color The color of the pixel

  • bits_per_pixel The number of bits per pixel in the color

Returns

A character (like ‘*‘) to be used for the color

This method is used for printing 1, 2, and 4, bit per pixel colors.


static bool update_progress_callback(

void * context,
int progress,
int total
)

Used by progres_callback().


protected void print_indentation()

Prints the YAML indentation.


protected virtual void print_indented(

const var::ConstString & key,
const char * fmt,

)

Prints an indented key (can be re-implemented).


protected virtual void vprint(

const char * fmt,
va_list list
)

Prints all characters.

This is the only method that needs to be re-implemented to re-direct the Printer from the standard output to another file or output.


protected virtual void vprint_indented(

const var::ConstString & key,
const char * fmt,
va_list list
)

Prints an indented key (can be re-implemented).


enum @17
  • COLOR_CODE_DEFAULT
  • COLOR_CODE_BLACK
  • COLOR_CODE_RED
  • COLOR_CODE_GREEN
  • COLOR_CODE_YELLOW
  • COLOR_CODE_BLUE
  • COLOR_CODE_MAGENTA
  • COLOR_CODE_CYAN
  • COLOR_CODE_LIGHT_GRAY
  • COLOR_CODE_DARK_GRAY
  • COLOR_CODE_LIGHT_RED
  • COLOR_CODE_LIGHT_GREEN
  • COLOR_CODE_LIGHT_YELLOW
  • COLOR_CODE_LIGHT_BLUE

enum @18
  • FORMAT_NORMAL
  • FORMAT_BOLD
  • FORMAT_DIM
  • FORMAT_UNDERLINE
  • FORMAT_BLINK
  • FORMAT_INVERTED
  • FORMAT_HIDDEN

enum @19
  • PRINT_HEX Print hex data
  • PRINT_UNSIGNED Print unsigned integers
  • PRINT_SIGNED Printd signed integers
  • PRINT_CHAR Print Characters
  • PRINT_8 Print as 8 bit values (default)
  • PRINT_16 Print as 16 bit values
  • PRINT_32 Print as 32 bit values
  • PRINT_SIMPLE_PROGRESS Just print # for progress
  • PRINT_BOLD_KEYS Print keys in bold if supported
  • PRINT_BOLD_VALUES Print keys in bold if supported
  • PRINT_BOLD_OBJECTS Print keys in bold if supported
  • PRINT_BOLD_ARRAYS Print keys in bold if supported
  • PRINT_GREEN_VALUES
  • PRINT_RED_VALUES
  • PRINT_YELLOW_VALUES
  • PRINT_RED_ERRORS
  • PRINT_YELLOW_WARNINGS
  • PRINT_CYAN_KEYS
  • PRINT_YELLOW_KEYS
  • PRINT_MAGENTA_KEYS
  • PRINT_BLOB Print Data as a blob

Number printing flags.


enum verbose_level
  • FATAL Prints fatal errors.
  • ERROR Prints fatal and error messages.
  • WARNING Printers warnings and worse.
  • INFO Prints basic info (default setting) plus warning and errors.
  • MESSAGE Prints additional messages.
  • DEBUG Prints everything.

Filtering levels.


X

Thanks for Coming!

Subscribe to news and updates