diff options
author | 2019-09-29 00:31:30 +0200 | |
---|---|---|
committer | 2019-09-29 00:31:30 +0200 | |
commit | cc8114f39463d338030fa48025d7fa27d5df981b (patch) | |
tree | 4d7c21676c53fb206f72c76d8d272419760889ca | |
parent | 5ad9faa783b27c2744dee5f182fc94a885d47e34 (diff) |
netlist: less cpp - more headers (nw)
- move more code in headers - delete some cpp files.
-rw-r--r-- | scripts/src/netlist.lua | 13 | ||||
-rw-r--r-- | src/lib/netlist/build/makefile | 3 | ||||
-rw-r--r-- | src/lib/netlist/plib/pchrono.cpp | 79 | ||||
-rw-r--r-- | src/lib/netlist/plib/pexception.cpp | 2 | ||||
-rw-r--r-- | src/lib/netlist/plib/pfmtlog.cpp | 2 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstate.cpp | 57 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstate.h | 46 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstream.cpp | 55 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstream.h | 32 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstring.cpp | 44 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstring.h | 3 |
11 files changed, 75 insertions, 261 deletions
diff --git a/scripts/src/netlist.lua b/scripts/src/netlist.lua index 973e9fb2ffc..81fa3b7c073 100644 --- a/scripts/src/netlist.lua +++ b/scripts/src/netlist.lua @@ -48,10 +48,9 @@ project "netlist" MAME_DIR .. "src/lib/netlist/nl_parser.h", MAME_DIR .. "src/lib/netlist/nl_setup.cpp", MAME_DIR .. "src/lib/netlist/nl_setup.h", - MAME_DIR .. "src/lib/netlist/nl_types.h", + MAME_DIR .. "src/lib/netlist/nl_types.h", MAME_DIR .. "src/lib/netlist/plib/pconfig.h", MAME_DIR .. "src/lib/netlist/plib/palloc.h", - MAME_DIR .. "src/lib/netlist/plib/pchrono.cpp", MAME_DIR .. "src/lib/netlist/plib/pchrono.h", MAME_DIR .. "src/lib/netlist/plib/pexception.cpp", MAME_DIR .. "src/lib/netlist/plib/pexception.h", @@ -71,13 +70,11 @@ project "netlist" MAME_DIR .. "src/lib/netlist/plib/pparser.cpp", MAME_DIR .. "src/lib/netlist/plib/pparser.h", MAME_DIR .. "src/lib/netlist/plib/ppmf.h", - MAME_DIR .. "src/lib/netlist/plib/pstate.cpp", MAME_DIR .. "src/lib/netlist/plib/pstate.h", MAME_DIR .. "src/lib/netlist/plib/pstring.cpp", MAME_DIR .. "src/lib/netlist/plib/pstring.h", - MAME_DIR .. "src/lib/netlist/plib/pstream.cpp", MAME_DIR .. "src/lib/netlist/plib/pstream.h", - MAME_DIR .. "src/lib/netlist/plib/ptime.h", + MAME_DIR .. "src/lib/netlist/plib/ptime.h", MAME_DIR .. "src/lib/netlist/plib/ptypes.h", MAME_DIR .. "src/lib/netlist/plib/putil.cpp", MAME_DIR .. "src/lib/netlist/plib/putil.h", @@ -85,9 +82,9 @@ project "netlist" MAME_DIR .. "src/lib/netlist/tools/nl_convert.h", MAME_DIR .. "src/lib/netlist/analog/nld_bjt.cpp", MAME_DIR .. "src/lib/netlist/analog/nld_bjt.h", - MAME_DIR .. "src/lib/netlist/analog/nld_generic_models.h", - MAME_DIR .. "src/lib/netlist/analog/nld_mosfet.cpp", - MAME_DIR .. "src/lib/netlist/analog/nld_mosfet.h", + MAME_DIR .. "src/lib/netlist/analog/nld_generic_models.h", + MAME_DIR .. "src/lib/netlist/analog/nld_mosfet.cpp", + MAME_DIR .. "src/lib/netlist/analog/nld_mosfet.h", MAME_DIR .. "src/lib/netlist/analog/nlid_fourterm.cpp", MAME_DIR .. "src/lib/netlist/analog/nlid_fourterm.h", MAME_DIR .. "src/lib/netlist/analog/nld_fourterm.h", diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index e97affcd398..b0e69754b41 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -79,15 +79,12 @@ OBJS = $(POBJS) $(NLOBJS) POBJS := \ $(POBJ)/pstring.o \ - $(POBJ)/pchrono.o \ $(POBJ)/pdynlib.o \ $(POBJ)/pexception.o \ $(POBJ)/pfunction.o \ $(POBJ)/pfmtlog.o \ $(POBJ)/poptions.o \ $(POBJ)/pparser.o \ - $(POBJ)/pstate.o \ - $(POBJ)/pstream.o \ $(POBJ)/putil.o \ PMAIN := $(POBJ)/pmain.o diff --git a/src/lib/netlist/plib/pchrono.cpp b/src/lib/netlist/plib/pchrono.cpp deleted file mode 100644 index 354a2589851..00000000000 --- a/src/lib/netlist/plib/pchrono.cpp +++ /dev/null @@ -1,79 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud - -#if 0 - -#include "pchrono.h" - -namespace plib { -namespace chrono { -#if defined(__x86_64__) && !defined(_clang__) && !defined(_MSC_VER) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)) - -template <typename T> -auto per_sec() -> typename T :: type -{ - using ret_type = typename T :: type; - static ret_type persec = 0; - if (persec == 0) - { - ret_type x = 0; - system_ticks::type t = system_ticks::start(); - system_ticks::type e; - x = - T :: start(); - do { - e = system_ticks::stop(); - } while (e - t < system_ticks::per_second() / 100 ); - x += T :: stop(); - persec = (ret_type)(double)((double) x * (double) system_ticks::per_second() / double (e - t)); - } - return persec; -} - - -fast_ticks::type fast_ticks::per_second() -{ -#if 1 - return per_sec<fast_ticks>(); -#else - static type persec = 0; - if (persec == 0) - { - type x = 0; - system_ticks::type t = system_ticks::start(); - system_ticks::type e; - x = -start(); - do { - e = system_ticks::stop(); - } while (e - t < system_ticks::per_second() / 100 ); - x += stop(); - persec = (type)(double)((double) x * (double) system_ticks::per_second() / double (e - t)); - } - return persec; -#endif -} - -#if PUSE_ACCURATE_STATS && PHAS_RDTSCP -exact_ticks::type exact_ticks::per_second() -{ - static type persec = 0; - if (persec == 0) - { - type x = 0; - system_ticks::type t = system_ticks::start(); - system_ticks::type e; - x = -start(); - do { - e = system_ticks::stop(); - } while (e - t < system_ticks::per_second() / 100 ); - x += stop(); - persec = (type)(double)((double) x * (double) system_ticks::per_second() / double (e - t)); - } - return persec; -} -#endif - -#endif - -} // namespace chrono -} // namespace plib -#endif diff --git a/src/lib/netlist/plib/pexception.cpp b/src/lib/netlist/plib/pexception.cpp index 8d6907d66f2..1b32549be87 100644 --- a/src/lib/netlist/plib/pexception.cpp +++ b/src/lib/netlist/plib/pexception.cpp @@ -77,7 +77,7 @@ namespace plib { fpexception_e::fpexception_e(const pstring &text) - : pexception(pfmt("Out of memory: {}")(text)) + : pexception(pfmt("Exception error: {}")(text)) { } diff --git a/src/lib/netlist/plib/pfmtlog.cpp b/src/lib/netlist/plib/pfmtlog.cpp index ef12e05fb1d..8da27df8d1c 100644 --- a/src/lib/netlist/plib/pfmtlog.cpp +++ b/src/lib/netlist/plib/pfmtlog.cpp @@ -110,12 +110,10 @@ pfmt::rtype pfmt::setfmt(std::stringstream &strm, char32_t cfmt_spec) strm << std::setprecision(pstonum<int>(fmt.substr(1))); else if (pdot != pstring::npos) { - //strm << std::setprecision(pstonum<int>(fmt.substr(pdot + 1))) << std::setw(pstonum<int>(left(fmt,pdot))); strm << std::setprecision(pstonum<int>(fmt.substr(pdot + 1))); r.width = pstonum<pstring::size_type>(left(fmt,pdot)); } else if (fmt != "") - //strm << std::setw(pstonum<int>(fmt)); r.width = pstonum<pstring::size_type>(fmt); switch (r.pend) diff --git a/src/lib/netlist/plib/pstate.cpp b/src/lib/netlist/plib/pstate.cpp deleted file mode 100644 index 3bd93ed4f8e..00000000000 --- a/src/lib/netlist/plib/pstate.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * pstate.c - * - */ - -#include "pstate.h" -#include "palloc.h" - -namespace plib { - -void state_manager_t::save_state_ptr(const void *owner, const pstring &stname, const datatype_t &dt, const std::size_t count, void *ptr) -{ - auto p = plib::make_unique<entry_t>(stname, dt, owner, count, ptr); - m_save.push_back(std::move(p)); -} - -void state_manager_t::remove_save_items(const void *owner) -{ - auto i = m_save.end(); - while (i != m_save.begin()) - { - i--; - if (i->get()->m_owner == owner) - i = m_save.erase(i); - } - i = m_custom.end(); - while (i > m_custom.begin()) - { - i--; - if (i->get()->m_owner == owner) - i = m_custom.erase(i); - } -} - -void state_manager_t::pre_save() -{ - for (auto & s : m_custom) - s->m_callback->on_pre_save(*this); -} - -void state_manager_t::post_load() -{ - for (auto & s : m_custom) - s->m_callback->on_post_load(*this); -} - -template<> void state_manager_t::save_item(const void *owner, callback_t &state, const pstring &stname) -{ - callback_t *state_p = &state; - auto p = plib::make_unique<entry_t>(stname, owner, state_p); - m_custom.push_back(std::move(p)); - state.register_state(*this, stname); -} - -} // namespace plib diff --git a/src/lib/netlist/plib/pstate.h b/src/lib/netlist/plib/pstate.h index ac75ca6b69e..f595dbcba11 100644 --- a/src/lib/netlist/plib/pstate.h +++ b/src/lib/netlist/plib/pstate.h @@ -113,9 +113,40 @@ public: save_state_ptr(owner, stname, dtype<C>(), N, a.data()); } - void pre_save(); - void post_load(); - void remove_save_items(const void *owner); + void save_state_ptr(const void *owner, const pstring &stname, const datatype_t &dt, const std::size_t count, void *ptr) + { + m_save.push_back(plib::make_unique<entry_t>(stname, dt, owner, count, ptr)); + } + + void pre_save() + { + for (auto & s : m_custom) + s->m_callback->on_pre_save(*this); + } + + void post_load() + { + for (auto & s : m_custom) + s->m_callback->on_post_load(*this); + } + + void remove_save_items(const void *owner) + { + auto i = m_save.end(); + while (i != m_save.begin()) + { + i--; + if (i->get()->m_owner == owner) + i = m_save.erase(i); + } + i = m_custom.end(); + while (i > m_custom.begin()) + { + i--; + if (i->get()->m_owner == owner) + i = m_custom.erase(i); + } + } const std::vector<const entry_t *> save_list() const { @@ -125,8 +156,6 @@ public: return ret; } - void save_state_ptr(const void *owner, const pstring &stname, const datatype_t &dt, const std::size_t count, void *ptr); - protected: private: @@ -135,7 +164,12 @@ private: }; -template<> void state_manager_t::save_item(const void *owner, callback_t &state, const pstring &stname); +template<> inline void state_manager_t::save_item(const void *owner, callback_t &state, const pstring &stname) +{ + m_custom.push_back(plib::make_unique<entry_t>(stname, owner, &state)); + state.register_state(*this, stname); +} + } // namespace plib diff --git a/src/lib/netlist/plib/pstream.cpp b/src/lib/netlist/plib/pstream.cpp deleted file mode 100644 index 1e805825af3..00000000000 --- a/src/lib/netlist/plib/pstream.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * pstream.c - * - */ - -#include "pstream.h" -#include "palloc.h" - -#include <algorithm> -#include <cstdio> -//#include <cstdlib> - -// VS2015 prefers _dup -#ifdef _WIN32 -#include <io.h> -#else -#include <unistd.h> -#endif - -namespace plib { - - -bool putf8_reader::readline(pstring &line) -{ - putf8string::code_t c = 0; - m_linebuf = ""; - if (!this->readcode(c)) - { - line = ""; - return false; - } - while (true) - { - if (c == 10) - break; - else if (c != 13) /* ignore CR */ - m_linebuf += putf8string(1, c); - if (!this->readcode(c)) - break; - } - line = m_linebuf.c_str(); - return true; -} - - -void putf8_fmt_writer::vdowrite(const pstring &ls) const -{ - write(ls); -} - - - -} // namespace plib diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index 68592b70b7d..b6fb7f8d942 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -55,15 +55,37 @@ public: {} bool eof() const { return m_strm->eof(); } - bool readline(pstring &line); - bool readbyte1(std::istream::char_type &b) + bool readline(pstring &line) + { + putf8string::code_t c = 0; + m_linebuf = ""; + if (!this->readcode(c)) + { + line = ""; + return false; + } + while (true) + { + if (c == 10) + break; + else if (c != 13) /* ignore CR */ + m_linebuf += putf8string(1, c); + if (!this->readcode(c)) + break; + } + line = m_linebuf.c_str(); + return true; + } + + bool readbyte(std::istream::char_type &b) { if (m_strm->eof()) return false; m_strm->read(&b, 1); return true; } + bool readcode(putf8string::traits_type::code_t &c) { std::array<std::istream::char_type, 4> b{0}; @@ -154,7 +176,11 @@ public: ~putf8_fmt_writer() override = default; //protected: - void vdowrite(const pstring &ls) const; + void vdowrite(const pstring &s) const + { + write(s); + } + private: }; diff --git a/src/lib/netlist/plib/pstring.cpp b/src/lib/netlist/plib/pstring.cpp index c304f11d1fd..2eedc6b0371 100644 --- a/src/lib/netlist/plib/pstring.cpp +++ b/src/lib/netlist/plib/pstring.cpp @@ -58,50 +58,6 @@ pstring_t<F> pstring_t<F>::substr(size_type start, size_type nlen) const } template<typename F> -typename pstring_t<F>::size_type pstring_t<F>::find_first_not_of(const pstring_t &no) const -{ - size_type pos = 0; - for (auto it = begin(); it != end(); ++it, ++pos) - { - bool f = true; - for (code_t const jt : no) - { - if (*it == jt) - { - f = false; - break; - } - } - if (f) - return pos; - } - return npos; -} - -template<typename F> -typename pstring_t<F>::size_type pstring_t<F>::find_last_not_of(const pstring_t &no) const -{ - /* FIXME: reverse iterator */ - size_type last_found = npos; - size_type pos = 0; - for (auto it = begin(); it != end(); ++it, ++pos) - { - bool f = true; - for (code_t const jt : no) - { - if (*it == jt) - { - f = false; - break; - } - } - if (f) - last_found = pos; - } - return last_found; -} - -template<typename F> typename pstring_t<F>::size_type pstring_t<F>::find(const pstring_t &search, size_type start) const { auto istart = std::next(begin(), static_cast<difference_type>(start)); diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index 1307bc13e3c..23133164202 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -178,9 +178,6 @@ public: size_type find(const pstring_t &search, size_type start = 0) const; size_type find(code_t search, size_type start = 0) const; - size_type find_first_not_of(const pstring_t &no) const; - size_type find_last_not_of(const pstring_t &no) const; - // concatenation operators pstring_t& operator+=(const pstring_t &string) { m_str.append(string.m_str); return *this; } pstring_t& operator+=(const code_t c) { traits_type::encode(c, m_str); return *this; } |