diff options
author | Vas Crabb <vas@vastheman.com> | 2019-09-26 20:53:06 +1000 |
---|---|---|
committer | Vas Crabb <vas@vastheman.com> | 2019-09-26 20:53:06 +1000 |
commit | 9a12ab37afb3e43d9d3c296b34348b835bafb2ea (patch) | |
tree | 6af7ce1fc5f52b1518100a1be926514cd2f34feb /src/osd/osdcore.h | |
parent | 9d4b7b02acdb79fac05606f57c3fddd08593cba8 (diff) |
Make osd_printf_* use util/strformat semantics.
(nw) This has been a long time coming but it's here at last. It should
be easier now that logerror, popmessage and osd_printf_* behave like
string_format and stream_format. Remember the differences from printf:
* Any object with a stream out operator works with %s
* %d, %i, %o, %x, %X, etc. work out the size by magic
* No sign extending promotion to int for short/char
* No widening/narrowing conversions for characters/strings
* Same rules on all platforms, insulated from C runtime library
* No format warnings from compiler
* Assert in debug builds if number of arguments doesn't match format
(nw) Also removed a pile of redundant c_str and string_format, and some
workarounds for not being able to portably format 64-bit integers or
long long.
Diffstat (limited to 'src/osd/osdcore.h')
-rw-r--r-- | src/osd/osdcore.h | 57 |
1 files changed, 43 insertions, 14 deletions
diff --git a/src/osd/osdcore.h b/src/osd/osdcore.h index 22179f9da45..95233b4eb14 100644 --- a/src/osd/osdcore.h +++ b/src/osd/osdcore.h @@ -13,19 +13,23 @@ broken out into several categories. ***************************************************************************/ +#ifndef MAME_OSD_OSDCORE_H +#define MAME_OSD_OSDCORE_H #pragma once -#ifndef MAME_OSD_OSDCORE_H -#define MAME_OSD_OSDCORE_H #include "osdcomm.h" +#include "strformat.h" + #include <chrono> #include <cstdarg> #include <cstdint> +#include <iosfwd> #include <memory> #include <string> +#include <utility> #include <vector> @@ -1013,30 +1017,55 @@ public: class osd_output { public: - osd_output() : m_chain(nullptr) { } + osd_output() { } virtual ~osd_output() { } - virtual void output_callback(osd_output_channel channel, const char *msg, va_list args) = 0; + virtual void output_callback(osd_output_channel channel, util::format_argument_pack<std::ostream> const &args) = 0; static void push(osd_output *delegate); static void pop(osd_output *delegate); + protected: - void chain_output(osd_output_channel channel, const char *msg, va_list args) const + void chain_output(osd_output_channel channel, util::format_argument_pack<std::ostream> const &args) const { - if (m_chain != nullptr) - m_chain->output_callback(channel, msg, args); + if (m_chain) + m_chain->output_callback(channel, args); } + private: - osd_output *m_chain; + osd_output *m_chain = nullptr; }; -/* calls to be used by the code */ -void CLIB_DECL osd_printf_error(const char *format, ...) ATTR_PRINTF(1,2); -void CLIB_DECL osd_printf_warning(const char *format, ...) ATTR_PRINTF(1,2); -void CLIB_DECL osd_printf_info(const char *format, ...) ATTR_PRINTF(1,2); -void CLIB_DECL osd_printf_verbose(const char *format, ...) ATTR_PRINTF(1,2); -void CLIB_DECL osd_printf_debug(const char *format, ...) ATTR_PRINTF(1,2); + +// diagnostic output +void osd_vprintf_error(util::format_argument_pack<std::ostream> const &args); +void osd_vprintf_warning(util::format_argument_pack<std::ostream> const &args); +void osd_vprintf_info(util::format_argument_pack<std::ostream> const &args); +void osd_vprintf_verbose(util::format_argument_pack<std::ostream> const &args); +void osd_vprintf_debug(util::format_argument_pack<std::ostream> const &args); + +template <typename Format, typename... Params> void osd_printf_error(Format &&fmt, Params &&...args) +{ + return osd_vprintf_error(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...)); +} +template <typename Format, typename... Params> void osd_printf_warning(Format &&fmt, Params &&...args) +{ + return osd_vprintf_warning(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...)); +} +template <typename Format, typename... Params> void osd_printf_info(Format &&fmt, Params &&...args) +{ + return osd_vprintf_info(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...)); +} +template <typename Format, typename... Params> void osd_printf_verbose(Format &&fmt, Params &&...args) +{ + return osd_vprintf_verbose(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...)); +} +template <typename Format, typename... Params> void osd_printf_debug(Format &&fmt, Params &&...args) +{ + return osd_vprintf_debug(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...)); +} + // returns command line arguments as an std::vector<std::string> in UTF-8 std::vector<std::string> osd_get_command_line(int argc, char *argv[]); |