diff options
Diffstat (limited to 'src/lib/netlist/plib/putil.h')
-rw-r--r-- | src/lib/netlist/plib/putil.h | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index 22abf637f87..b5fe06efb61 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -19,12 +19,31 @@ #define PSTRINGIFY_HELP(y) # y #define PSTRINGIFY(x) PSTRINGIFY_HELP(x) -#define PNARGS_(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, N, ...) N -#define PNARGS(...) PNARGS_(__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) +// Discussion and background of this MSVC bug: https://github.com/mamedev/mame/issues/6106 +/// +/// \brief Macro to work around a bug in MSVC treatment of __VA_ARGS__ +/// +#define PMSVC_VARARG_BUG(MACRO, ARGS) MACRO ARGS -#define PCONCAT_(a, b) a ## b +/// \brief Determine number of arguments in __VA_ARGS__ +/// +/// This macro works up to 16 arguments in __VA_ARGS__ +/// +/// \returns Number of arguments +/// +#define PNARGS(...) PNARGS_1(__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) + +#define PNARGS_2(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, N, ...) N +#define PNARGS_1(...) PMSVC_VARARG_BUG(PNARGS_2, (__VA_ARGS__)) + +/// \brief Concatenate two arguments after expansion +/// +/// \returns Concatenated expanded arguments +/// #define PCONCAT(a, b) PCONCAT_(a, b) +#define PCONCAT_(a, b) a ## b + #define PSTRINGIFY_1(x) #x #define PSTRINGIFY_2(x, x2) #x, #x2 #define PSTRINGIFY_3(x, ...) #x, PSTRINGIFY_2(__VA_ARGS__) @@ -42,7 +61,13 @@ #define PSTRINGIFY_15(x, ...) #x, PSTRINGIFY_14(__VA_ARGS__) #define PSTRINGIFY_16(x, ...) #x, PSTRINGIFY_15(__VA_ARGS__) -#define PSTRINGIFY_VA(...) PCONCAT(PSTRINGIFY_, PNARGS(__VA_ARGS__))(__VA_ARGS__) +/// \brief Individually stringify up to 16 arguments +/// +/// PSTRINGIFY_VA(a, b, c) will be expanded to "a", "b", "c" +/// +/// \returns List of stringified individual arguments +/// +#define PSTRINGIFY_VA(...) PMSVC_VARARG_BUG(PCONCAT, (PSTRINGIFY_, PNARGS(__VA_ARGS__)))(__VA_ARGS__) // FIXME:: __FUNCTION__ may be not be supported by all compilers. @@ -131,10 +156,8 @@ namespace plib typename TS::stream_ptr stream(const pstring &name) override { - if (name == m_name) - return plib::make_unique<std::stringstream>(m_str); - else - return typename TS::stream_ptr(nullptr); + return (name == m_name) ? + plib::make_unique<std::stringstream>(m_str) : typename TS::stream_ptr(nullptr); } private: pstring m_name; @@ -254,7 +277,7 @@ namespace plib std::vector<pstring> psplit(const pstring &str, const std::vector<pstring> &onstrl); std::vector<std::string> psplit_r(const std::string &stri, const std::string &token, - const std::size_t maxsplit); + std::size_t maxsplit); //============================================================ // penum - strongly typed enumeration @@ -276,7 +299,8 @@ namespace plib template <typename T> explicit ename(T val) { m_v = static_cast<E>(val); } \ bool set_from_string (const pstring &s) { \ int f = from_string_int(strings(), s); \ - if (f>=0) { m_v = static_cast<E>(f); return true; } else { return false; } \ + if (f>=0) { m_v = static_cast<E>(f); return true; } \ + return false;\ } \ operator E() const noexcept {return m_v;} \ bool operator==(const ename &rhs) const noexcept {return m_v == rhs.m_v;} \ |