diff options
Diffstat (limited to 'src/emu/emucore.h')
-rw-r--r-- | src/emu/emucore.h | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/emu/emucore.h b/src/emu/emucore.h index 92135e7ae84..ef6713c8d8f 100644 --- a/src/emu/emucore.h +++ b/src/emu/emucore.h @@ -29,6 +29,7 @@ // standard C++ includes #include <cassert> #include <exception> +#include <string> #include <type_traits> #include <typeinfo> @@ -37,6 +38,7 @@ #include "emualloc.h" #include "corestr.h" #include "bitmap.h" +#include "strformat.h" #include "emufwd.h" @@ -247,17 +249,26 @@ class emu_exception : public std::exception { }; class emu_fatalerror : public emu_exception { public: - emu_fatalerror(const char *format, ...) ATTR_PRINTF(2,3); - emu_fatalerror(const char *format, va_list ap); - emu_fatalerror(int _exitcode, const char *format, ...) ATTR_PRINTF(3,4); - emu_fatalerror(int _exitcode, const char *format, va_list ap); - - const char *string() const { return text; } - int exitcode() const { return code; } + emu_fatalerror(util::format_argument_pack<std::ostream> const &args); + emu_fatalerror(int _exitcode, util::format_argument_pack<std::ostream> const &args); + + template <typename Format, typename... Params> + emu_fatalerror(Format const &fmt, Params &&... args) + : emu_fatalerror(static_cast<util::format_argument_pack<std::ostream> const &>(util::make_format_argument_pack(fmt, std::forward<Params>(args)...))) + { + } + template <typename Format, typename... Params> + emu_fatalerror(int _exitcode, Format const &fmt, Params &&... args) + : emu_fatalerror(_exitcode, static_cast<util::format_argument_pack<std::ostream> const &>(util::make_format_argument_pack(fmt, std::forward<Params>(args)...))) + { + } + + virtual char const *what() const noexcept override { return m_text.c_str(); } + int exitcode() const noexcept { return m_code; } private: - char text[1024]; - int code; + std::string m_text; + int m_code; }; class tag_add_exception @@ -269,12 +280,13 @@ private: std::string m_tag; }; + //************************************************************************** // CASTING TEMPLATES //************************************************************************** -void report_bad_cast(const std::type_info &src_type, const std::type_info &dst_type); -void report_bad_device_cast(const device_t *dev, const std::type_info &src_type, const std::type_info &dst_type); +[[noreturn]] void report_bad_cast(const std::type_info &src_type, const std::type_info &dst_type); +[[noreturn]] void report_bad_device_cast(const device_t *dev, const std::type_info &src_type, const std::type_info &dst_type); template <typename Dest, typename Source> inline std::enable_if_t<std::is_base_of<device_t, Source>::value> report_bad_cast(Source *const src) @@ -316,15 +328,15 @@ inline Dest downcast(Source &src) //************************************************************************** -// FUNCTION PROTOTYPES +// INLINE FUNCTIONS //************************************************************************** -[[noreturn]] void fatalerror(const char *format, ...) ATTR_PRINTF(1,2); -[[noreturn]] void fatalerror_exitcode(running_machine &machine, int exitcode, const char *format, ...) ATTR_PRINTF(3,4); +template <typename... T> +[[noreturn]] inline void fatalerror(T &&... args) +{ + throw emu_fatalerror(std::forward<T>(args)...); +} -//************************************************************************** -// INLINE FUNCTIONS -//************************************************************************** // convert a series of 32 bits into a float inline float u2f(u32 v) |