comparison foosdk/sdk/foobar2000/SDK/console.h @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #pragma once
2
3
4 //! Namespace with functions for sending text to console. All functions are fully multi-thread safe, though they must not be called during dll initialization or deinitialization (e.g. static object constructors or destructors) when service system is not available.
5 namespace console
6 {
7 void info(const char * p_message);
8 void error(const char * p_message);
9 void warning(const char * p_message);
10 void info_location(const playable_location & src);
11 void info_location(const metadb_handle_ptr & src);
12 void print_location(const playable_location & src);
13 void print_location(const metadb_handle_ptr & src);
14
15 void print(const char*);
16 void printf(const char*,...);
17 void printfv(const char*,va_list p_arglist);
18
19 //! New console print method, based on pfc::print(). \n
20 //! Example: console::print("foo", "bar", 2000) \ n
21 //! See also: FB2K_console_print(...)
22 template<typename ... args_t> void print(args_t && ... args) {print(pfc::format(std::forward<args_t>(args) ... ).c_str()); }
23
24 class lineWriter {
25 public:
26 const lineWriter & operator<<( const char * msg ) const {print(msg);return *this;}
27 };
28
29 //! Usage: console::formatter() << "blah " << somenumber << " asdf" << somestring;
30 class formatter : public pfc::string_formatter {
31 public:
32 ~formatter() {if (!is_empty()) console::print(get_ptr());}
33 };
34 #define FB2K_console_formatter() ::console::formatter()._formatter()
35 #define FB2K_console_formatter1() ::console::lineWriter()
36
37 //! New console print macro, based on pfc::print(). \n
38 //! Example: FB2K_console_print("foo", "bar", 2000) \n
39 //! Note that this macro is convenient for conditionally enabling logging in specific modules - \n
40 //! instead of putting console formatter lines on #ifdef, #define MY_CONSOLE_LOG(...) FB2K_console_print(__VA_ARGS__) if enabled, or #define to blank if not.
41 #define FB2K_console_print(...) ::console::print(__VA_ARGS__)
42
43 void complain(const char * what, const char * msg);
44 void complain(const char * what, std::exception const & e);
45
46 class timer_scope {
47 public:
48 timer_scope(const char * name) : m_name(name) {m_timer.start();}
49 ~timer_scope() {
50 try {
51 FB2K_console_formatter() << m_name << ": " << pfc::format_time_ex(m_timer.query(), 6);
52 } catch(...) {}
53 }
54 private:
55 pfc::hires_timer m_timer;
56 const char * const m_name;
57 };
58 };
59
60 //! Interface receiving console output. Do not call directly; use console namespace functions instead.
61 class NOVTABLE console_receiver : public service_base {
62 public:
63 virtual void print(const char * p_message,t_size p_message_length) = 0;
64
65 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(console_receiver);
66 };
67
68
69
70