2 #ifndef __UTILITIES_HPP__
3 #define __UTILITIES_HPP__
45 static void setup(
const bool clear_log );
55 template<
typename ...unused>
Unused(unused
const & ... ) {}
69 [[noreturn]]
static void err(
const char *
const s );
72 static void assert(
const bool b,
const char *
const s );
85 template <
typename...
Args>
static void log(
Args &&... args ) {
95 log( std::forward<Args>( args )... );
123 template <
typename...
Args>
static void debug(
Args &&... args ) {
124 log_error( std::forward<Args>( args )... );
136 template <
typename...
Args>
static void write_log(
const int fd,
Args &&... args );
141 template <
typename...
Args>
153 template <
typename T>
159 template <
typename Head,
typename... Tail>
180 std::stringstream stream;
190 const std::string str = stream.str();
191 const ssize_t len = str.size();
static void enable_multi_thread_or_process_mode()
Once this is called, TIDs will be printed with each message.
Definition: utilities.cpp:116
static void write_log_helper(std::stringstream &stream, T &&val)
A specialization of write_log_helper that has only one template argument.
Definition: utilities.hpp:154
A general class for utilities.
Definition: utilities.hpp:21
static pid_t get_tid()
Define a gettid function On failure, disables multi_threaded / functionality (to continue logging) th...
Definition: utilities.cpp:106
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...
Definition: utilities.hpp:114
static constexpr const int invalid_fd
A known invalid file descriptor.
Definition: utilities.hpp:40
Unused(unused const &...)
The constructor.
Definition: utilities.hpp:55
A struct used to eat unused arguments.
Definition: utilities.hpp:53
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...
Definition: utilities.hpp:176
static void assert(const bool b, const char *const s)
assert b, if false call program_err(s)
Definition: utilities.cpp:89
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 grou...
Definition: utilities.cpp:80
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 ...
Definition: utilities.hpp:92
static int log_fd
The log file descriptor This must be defined before main()
Definition: utilities.hpp:28
static bool is_multi_thread_or_proccess
Notes whether or not any threading / forking has happened yet.
Definition: utilities.hpp:24
static void message(Args &&...args)
Prints the arguments as cout would to the stdout and log files Ends the printed line(s) with a newlin...
Definition: utilities.hpp:105
static const int stdout_fd
The stdout file descriptor This must be defined before main()
Definition: utilities.hpp:32
static void write_log_helper(std::stringstream &stream, Head &&head, Tail &&...tail)
A specialization of write_log_helper that has multiple template arguments.
Definition: utilities.hpp:160
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 t...
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 ...
Definition: utilities.hpp:85
A struct returned by the argument parser.
Definition: parse_args.hpp:35
static const int error_fd
The error file descriptor This must be defined before main()
Definition: utilities.hpp:36
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...
Definition: utilities.cpp:43