diff options
author | 2020-05-23 10:48:33 +0200 | |
---|---|---|
committer | 2020-05-24 10:48:06 +0200 | |
commit | de615ac138316726da6158bfaa8567dde96ddcc0 (patch) | |
tree | b9b53339ddfe40054b42942701f8aa7dd9a927e6 | |
parent | fff7f6ef55f93ba53ceea798d1c65a9910c41f27 (diff) |
netlist: move penum into own header file. (nw)
-rw-r--r-- | scripts/src/netlist.lua | 1 | ||||
-rw-r--r-- | src/lib/netlist/nl_base.cpp | 4 | ||||
-rwxr-xr-x | src/lib/netlist/nl_setup.cpp | 6 | ||||
-rw-r--r-- | src/lib/netlist/plib/penum.h | 57 | ||||
-rw-r--r-- | src/lib/netlist/plib/pfmtlog.h | 3 | ||||
-rw-r--r-- | src/lib/netlist/plib/ptokenizer.h | 3 | ||||
-rw-r--r-- | src/lib/netlist/plib/putil.cpp | 3 | ||||
-rw-r--r-- | src/lib/netlist/plib/putil.h | 34 | ||||
-rw-r--r-- | src/lib/netlist/solver/nld_matrix_solver.h | 7 |
9 files changed, 75 insertions, 43 deletions
diff --git a/scripts/src/netlist.lua b/scripts/src/netlist.lua index 2b1cf9a2778..e3e79c55817 100644 --- a/scripts/src/netlist.lua +++ b/scripts/src/netlist.lua @@ -52,6 +52,7 @@ project "netlist" MAME_DIR .. "src/lib/netlist/plib/pconfig.h", MAME_DIR .. "src/lib/netlist/plib/palloc.h", MAME_DIR .. "src/lib/netlist/plib/pchrono.h", + MAME_DIR .. "src/lib/netlist/plib/penum.h", MAME_DIR .. "src/lib/netlist/plib/pexception.cpp", MAME_DIR .. "src/lib/netlist/plib/pexception.h", MAME_DIR .. "src/lib/netlist/plib/pfunction.cpp", diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index aa649aee2d8..177e2b62020 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -245,8 +245,10 @@ namespace netlist ENTRY_EX(sizeof(param_logic_t)) ENTRY_EX(sizeof(state_var<int>)) ENTRY_EX(sizeof(pstring)) - + ENTRY_EX(sizeof(core_device_t::stats_t)) + ENTRY_EX(sizeof(plib::plog_level)) #undef ENTRY + #undef ENTRY_EX } pstring netlist_state_t::version() diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 466b7c1faed..ea5adee6b0c 100755 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -2,6 +2,8 @@ // copyright-holders:Couriersud #include "plib/palloc.h" +#include "plib/putil.h" +#include "plib/penum.h" #include "analog/nld_twoterm.h" #include "devices/nlid_proxy.h" #include "devices/nlid_system.h" @@ -10,7 +12,7 @@ #include "nl_factory.h" #include "nl_parser.h" #include "nl_setup.h" -#include "plib/putil.h" + #include "solver/nld_solver.h" namespace netlist @@ -1275,7 +1277,7 @@ nl_fptype models_t::model_t::value(const pstring &entity) const // FIXME: all this belongs elsewhere -P_ENUM(family_type, +PENUM(family_type, CUSTOM, TTL, MOS, diff --git a/src/lib/netlist/plib/penum.h b/src/lib/netlist/plib/penum.h new file mode 100644 index 00000000000..1e0042f7dd2 --- /dev/null +++ b/src/lib/netlist/plib/penum.h @@ -0,0 +1,57 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud + +#ifndef PENUM_H_ +#define PENUM_H_ + +/// +/// \file penum.h +/// + +#include "pstring.h" +#include "pstrutil.h" +#include "putil.h" + +namespace plib +{ + + //============================================================ + // penum - strongly typed enumeration + //============================================================ + struct penum_base + { + protected: + // Implementation in putil.cpp. + // Putting the code here leads to a performance decrease. + static int from_string_int(const pstring &str, const pstring &x); + static pstring nthstr(int n, const pstring &str); + }; + +} // namespace plib + +#define PENUM(ename, ...) \ + struct ename : public plib::penum_base { \ + enum E { __VA_ARGS__ }; \ + constexpr ename (const E &v) : m_v(v) { } \ + constexpr ename (E && v) : m_v(v) { } \ + template <typename T> explicit constexpr ename(const T &val) { m_v = static_cast<E>(val); } \ + template <typename T> explicit constexpr 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; } \ + return false;\ + } \ + constexpr operator E() const noexcept {return m_v;} \ + constexpr bool operator==(const ename &rhs) const noexcept {return m_v == rhs.m_v;} \ + constexpr bool operator==(const E &rhs) const noexcept {return m_v == rhs;} \ + pstring name() const { \ + return nthstr(static_cast<int>(m_v), strings()); \ + } \ + private: E m_v; \ + static pstring strings() {\ + static const char * lstrings = # __VA_ARGS__; \ + return pstring(lstrings); \ + } \ + }; + +#endif // PENUM_H_ diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index e35e7db70bb..aae6ee9c085 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -11,6 +11,7 @@ #include "pstring.h" #include "ptypes.h" #include "putil.h" +#include "penum.h" #include <limits> #include <locale> @@ -26,7 +27,7 @@ namespace plib { - P_ENUM(plog_level, + PENUM(plog_level, DEBUG, VERBOSE, INFO, diff --git a/src/lib/netlist/plib/ptokenizer.h b/src/lib/netlist/plib/ptokenizer.h index b37dad3ec86..d5c4e13632c 100644 --- a/src/lib/netlist/plib/ptokenizer.h +++ b/src/lib/netlist/plib/ptokenizer.h @@ -13,6 +13,7 @@ #include "pstring.h" #include "putil.h" // psource_t +#include "penum.h" #include <unordered_map> #include <vector> @@ -39,7 +40,7 @@ namespace plib { virtual ~ptokenizer() = default; - P_ENUM(token_type, + PENUM(token_type, IDENTIFIER, NUMBER, TOKEN, diff --git a/src/lib/netlist/plib/putil.cpp b/src/lib/netlist/plib/putil.cpp index 89174dc4da2..180f2079ebc 100644 --- a/src/lib/netlist/plib/putil.cpp +++ b/src/lib/netlist/plib/putil.cpp @@ -5,6 +5,7 @@ #include "plists.h" #include "pstrutil.h" #include "ptypes.h" +#include "penum.h" #include <algorithm> #include <cstdlib> // needed for getenv ... @@ -168,7 +169,7 @@ namespace plib return -1; } - std::string penum_base::nthstr(int n, const pstring &str) + pstring penum_base::nthstr(int n, const pstring &str) { return psplit(str, ",", false)[static_cast<std::size_t>(n)]; } diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index f453637fe5b..d10b11b60f4 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -319,40 +319,6 @@ namespace plib return result; } - //============================================================ - // penum - strongly typed enumeration - //============================================================ - - struct penum_base - { - protected: - static int from_string_int(const pstring &str, const pstring &x); - static std::string nthstr(int n, const pstring &str); - }; - } // namespace plib -#define P_ENUM(ename, ...) \ - struct ename : public plib::penum_base { \ - enum E { __VA_ARGS__ }; \ - ename (E v) : m_v(v) { } \ - 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; } \ - return false;\ - } \ - operator E() const noexcept {return m_v;} \ - bool operator==(const ename &rhs) const noexcept {return m_v == rhs.m_v;} \ - bool operator==(const E &rhs) const noexcept {return m_v == rhs;} \ - std::string name() const { \ - return nthstr(static_cast<int>(m_v), strings()); \ - } \ - private: E m_v; \ - static pstring strings() {\ - static const pstring lstrings = # __VA_ARGS__; \ - return lstrings; \ - } \ - }; - #endif // PUTIL_H_ diff --git a/src/lib/netlist/solver/nld_matrix_solver.h b/src/lib/netlist/solver/nld_matrix_solver.h index d3f0aaa83e8..2e164171478 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.h +++ b/src/lib/netlist/solver/nld_matrix_solver.h @@ -15,6 +15,7 @@ #include "netlist/plib/pmatrix2d.h" #include "netlist/plib/putil.h" #include "netlist/plib/vector_ops.h" +#include "netlist/plib/penum.h" #include <numeric> @@ -29,7 +30,7 @@ namespace solver CXX_STATIC }; - P_ENUM(matrix_sort_type_e, + PENUM(matrix_sort_type_e, NOSORT, ASCENDING, DESCENDING, @@ -37,7 +38,7 @@ namespace solver PREFER_BAND_MATRIX ) - P_ENUM(matrix_type_e, + PENUM(matrix_type_e, SOR_MAT, MAT_CR, MAT, @@ -47,7 +48,7 @@ namespace solver GMRES ) - P_ENUM(matrix_fp_type_e, + PENUM(matrix_fp_type_e, FLOAT , DOUBLE , LONGDOUBLE |