A general class for utilities.
More...
#include <utilities.hpp>
|
static void | setup (const bool clear_log) |
| Sets up the utilities class If clear_log, the log will be cleared on setup If this function fails, it exists ONLY the current process. More...
|
|
static pid_t | get_tid () |
| Define a gettid function On failure, disables multi_threaded / functionality (to continue logging) then terminates the group. More...
|
|
static void | err (const char *const s) |
| To be called in case of an error Prints log s to the error file, perrors, then kills the process group. More...
|
|
static void | assert (const bool b, const char *const s) |
| assert b, if false call program_err(s) More...
|
|
template<typename... Args> |
static void | log (Args &&...args) |
| Logs the arguments as cout would to the log file if not null Ends the printed line(s) with a newline then flushes the buffer On faliure, silently fails (since it cannot write out) More...
|
|
template<typename... Args> |
static void | verbose_log (Args &&...args) |
| Logs the arguments as cout would to the log file if not null Ends the printed line(s) with a newline then flushes the buffer This function only runs if DEBUG_MODE and VERBOSE are defined. More...
|
|
template<typename... Args> |
static void | message (Args &&...args) |
| Prints the arguments as cout would to the stdout and log files Ends the printed line(s) with a newline then flushes the buffer If either file descriptor is invalied, that file is skipped On faliure, silently fails (since it cannot write out) More...
|
|
template<typename... Args> |
static void | log_error (Args &&...args) |
| Prints the arguments as cout would to the error and log files Ends the printed line(s) with a newline then flushes the buffer If either file descriptor is invalied, that file is skipped On failure, silently fails (since it cannot write out) More...
|
|
static void | enable_multi_thread_or_process_mode () |
| Once this is called, TIDs will be printed with each message. More...
|
|
|
template<typename... Args> |
static void | write_log (const int fd, Args &&...args) |
| A wrapper that writes args to f if f is not null Ends the printed line(s) with a newline then flushes the buffer On failure, silently fails (since it cannot write out) If the process is multithreaded or has forked, prints the TID first. More...
|
|
template<typename... Args> |
static void | write_log_helper (std::stringstream &stream, Args &&...args) |
| Adds the arguments to the stream Ends the printed line(s) with a newline then flushes the buffer If the process is multithreaded or has forked, prints the TID first. More...
|
|
template<typename T > |
static void | write_log_helper (std::stringstream &stream, T &&val) |
| A specialization of write_log_helper that has only one template argument. More...
|
|
template<typename Head , typename... Tail> |
static void | write_log_helper (std::stringstream &stream, Head &&head, Tail &&...tail) |
| A specialization of write_log_helper that has multiple template arguments. More...
|
|
A general class for utilities.
void Utilities::assert |
( |
const bool |
b, |
|
|
const char *const |
s |
|
) |
| |
|
static |
assert b, if false call program_err(s)
void Utilities::enable_multi_thread_or_process_mode |
( |
| ) |
|
|
static |
Once this is called, TIDs will be printed with each message.
void Utilities::err |
( |
const char *const |
s | ) |
|
|
static |
To be called in case of an error Prints log s to the error file, perrors, then kills the process group.
pid_t Utilities::get_tid |
( |
| ) |
|
|
static |
Define a gettid function On failure, disables multi_threaded / functionality (to continue logging) then terminates the group.
template<typename... Args>
static void Utilities::log |
( |
Args &&... |
args | ) |
|
|
inlinestatic |
Logs the arguments as cout would to the log file if not null Ends the printed line(s) with a newline then flushes the buffer On faliure, silently fails (since it cannot write out)
template<typename... Args>
static void Utilities::log_error |
( |
Args &&... |
args | ) |
|
|
inlinestatic |
Prints the arguments as cout would to the error and log files Ends the printed line(s) with a newline then flushes the buffer If either file descriptor is invalied, that file is skipped On failure, silently fails (since it cannot write out)
template<typename... Args>
static void Utilities::message |
( |
Args &&... |
args | ) |
|
|
inlinestatic |
Prints the arguments as cout would to the stdout and log files Ends the printed line(s) with a newline then flushes the buffer If either file descriptor is invalied, that file is skipped On faliure, silently fails (since it cannot write out)
void Utilities::setup |
( |
const bool |
clear_log | ) |
|
|
static |
Sets up the utilities class If clear_log, the log will be cleared on setup If this function fails, it exists ONLY the current process.
template<typename... Args>
static void Utilities::verbose_log |
( |
Args &&... |
args | ) |
|
|
inlinestatic |
Logs the arguments as cout would to the log file if not null Ends the printed line(s) with a newline then flushes the buffer This function only runs if DEBUG_MODE and VERBOSE are defined.
template<typename... Args>
void Utilities::write_log |
( |
const int |
fd, |
|
|
Args &&... |
args |
|
) |
| |
|
staticprivate |
A wrapper that writes args to f if f is not null Ends the printed line(s) with a newline then flushes the buffer On failure, silently fails (since it cannot write out) If the process is multithreaded or has forked, prints the TID first.
template<typename... Args>
static void Utilities::write_log_helper |
( |
std::stringstream & |
stream, |
|
|
Args &&... |
args |
|
) |
| |
|
staticprivate |
Adds the arguments to the stream Ends the printed line(s) with a newline then flushes the buffer If the process is multithreaded or has forked, prints the TID first.
template<typename T >
static void Utilities::write_log_helper |
( |
std::stringstream & |
stream, |
|
|
T && |
val |
|
) |
| |
|
inlinestaticprivate |
A specialization of write_log_helper that has only one template argument.
template<typename Head , typename... Tail>
static void Utilities::write_log_helper |
( |
std::stringstream & |
stream, |
|
|
Head && |
head, |
|
|
Tail &&... |
tail |
|
) |
| |
|
inlinestaticprivate |
A specialization of write_log_helper that has multiple template arguments.
The error file descriptor This must be defined before main()
constexpr const int Utilities::invalid_fd = -2 |
|
static |
A known invalid file descriptor.
bool Utilities::is_multi_thread_or_proccess = false |
|
staticprivate |
Notes whether or not any threading / forking has happened yet.
The log file descriptor This must be defined before main()
The stdout file descriptor This must be defined before main()
The documentation for this class was generated from the following files: