ape  0.5.0
Audio Programming Environment
Classes | Namespaces | Macros | Functions
print.h File Reference
#include "baselib.h"
#include <cstddef>
#include <charconv>
#include <complex>

Go to the source code of this file.

Classes

struct  ape::PrintFormatter< Derived >
 Helper type to automatically support formatted printing for user defined types through print() More...
 

Namespaces

 ape
 
 ape::detail
 

Macros

#define printf_once(...)   __CPPAPE_PRINTF_ONCE(CPPAPE_MACRO_CONCAT(__once_flag, __COUNTER__), __VA_ARGS__)
 Execute a printf() expression once, over the lifetime of the program. More...
 
#define print_once(...)   __CPPAPE_PRINT_ONCE(CPPAPE_MACRO_CONCAT(__once_flag, __COUNTER__), __VA_ARGS__)
 Execute a print() expression once, over the lifetime of the program. More...
 

Functions

int printf (const char *fmt,...)
 Print to the console attached to this plugin. This function is inherently unsafe, but may prove useful for particular formatting. cppreference. More...
 
int sprintf (char *buffer, const char *fmt,...)
 Print to a string buffer. This function is inherently unsafe, but may prove useful for particular formatting. cppreference. More...
 
template<typename T >
char * ape::detail::format (const T &val, char *b, char *e)
 
template<typename T >
char * ape::detail::format (const std::complex< T > &val, char *b, char *e)
 
char * ape::detail::format (const long double &val, char *b, char *e)
 
char * ape::detail::format (const double &val, char *b, char *e)
 
char * ape::detail::format (const float &val, char *b, char *e)
 
char * ape::detail::format (const void *val, char *b, char *e)
 
char * ape::detail::format (std::string_view val, char *b, char *e)
 
char * ape::detail::format (const char *val, char *b, char *e)
 
char * ape::detail::format (const std::string &val, char *b, char *e)
 
template<typename T >
print_buffer & ape::detail::operator<< (print_buffer &left, const T &value)
 
void ape::detail::safe_printf (print_buffer &buffer, std::string_view view)
 
template<typename T , typename... Args>
void ape::detail::safe_printf (print_buffer &buffer, std::string_view view, const T &value, Args &&... args)
 
template<typename... Args>
void print (std::string_view fmt, Args &&... args)
 Safely print a string replacing the nth "%" character with the nth variadic argument. Similar format system as printf(), except no format specifiers are required. They are instead derived from the individual types of the ordered argument list args . More...
 
template<typename... Args>
std::string sprint (std::string_view fmt, Args &&... args)
 Safely format the arguments.

See also
print()
More...
 

Macro Definition Documentation

◆ print_once

#define print_once (   ...)    __CPPAPE_PRINT_ONCE(CPPAPE_MACRO_CONCAT(__once_flag, __COUNTER__), __VA_ARGS__)

Execute a print() expression once, over the lifetime of the program.

◆ printf_once

#define printf_once (   ...)    __CPPAPE_PRINTF_ONCE(CPPAPE_MACRO_CONCAT(__once_flag, __COUNTER__), __VA_ARGS__)

Execute a printf() expression once, over the lifetime of the program.

Function Documentation

◆ print()

template<typename... Args>
void print ( std::string_view  fmt,
Args &&...  args 
)
inline

Safely print a string replacing the nth "%" character with the nth variadic argument. Similar format system as printf(), except no format specifiers are required. They are instead derived from the individual types of the ordered argument list args .

Supported types are:

  • built-in primitive scalar and pointer types
  • std::string_view
  • (const) char*
  • std::string
  • std::complex{T}
  • anything supported by std::to_chars
  • any custom implementation of PrintFormatter
Template Parameters
ArgsVariadic list of arguments
Parameters
fmtA string containing N "%" characters. Double "%%" prints a single "%".
argsVariadic list of values to replace positionally matching "%" in fmt .

◆ printf()

int printf ( const char *  fmt,
  ... 
)

Print to the console attached to this plugin. This function is inherently unsafe, but may prove useful for particular formatting. cppreference.

◆ sprint()

template<typename... Args>
std::string sprint ( std::string_view  fmt,
Args &&...  args 
)
inline

Safely format the arguments.

See also
print()

Returns
The formatted result.

◆ sprintf()

int sprintf ( char *  buffer,
const char *  fmt,
  ... 
)

Print to a string buffer. This function is inherently unsafe, but may prove useful for particular formatting. cppreference.