diff options
author | couriersud <couriersud@gmx.org> | 2017-02-21 00:59:57 +0100 |
---|---|---|
committer | couriersud <couriersud@gmx.org> | 2017-02-22 02:04:02 +0100 |
commit | a82ca2d244195ba79fcb34c6ccc964d3d906783d (patch) | |
tree | 75bde66f14ff36a23a3dfcb970f28e49dea0f070 | |
parent | 5c4b7cfef851ab8f13d937fdb4d3686936c63d39 (diff) |
Improve readability. Add more c++11 noexcept and swap semantics.
Also fixed clang-5 warnings. (nw)
-rw-r--r-- | src/lib/netlist/nl_base.cpp | 22 | ||||
-rw-r--r-- | src/lib/netlist/nl_base.h | 79 | ||||
-rw-r--r-- | src/lib/netlist/nl_factory.h | 2 | ||||
-rw-r--r-- | src/lib/netlist/nl_lists.h | 49 | ||||
-rw-r--r-- | src/lib/netlist/nl_setup.cpp | 1 | ||||
-rw-r--r-- | src/lib/netlist/nl_time.h | 45 | ||||
-rw-r--r-- | src/lib/netlist/plib/plists.h | 12 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstream.h | 10 | ||||
-rw-r--r-- | src/lib/netlist/plib/ptypes.h | 11 |
9 files changed, 131 insertions, 100 deletions
diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 51eb0eacf7e..e2d6ff3d032 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -513,8 +513,8 @@ void netlist_t::reset() break; case 2: // brute force forward { - for (std::size_t i = 0; i < m_devices.size(); i++) - m_devices[i]->update_dev(); + for (auto &d : m_devices) + d->update_dev(); } break; } @@ -527,7 +527,7 @@ void netlist_t::reset() } -void netlist_t::process_queue(const netlist_time &delta) +void netlist_t::process_queue(const netlist_time &delta) NL_NOEXCEPT { netlist_time stop(m_time + delta); @@ -782,7 +782,7 @@ detail::net_t::net_t(netlist_t &nl, const pstring &aname, core_terminal_t *mr) , m_cur_Q (*this, "m_cur_Q", 0) , m_time(*this, "m_time", netlist_time::zero()) , m_active(*this, "m_active", 0) - , m_in_queue(*this, "m_in_queue", 2) + , m_in_queue(*this, "m_in_queue", QS_DELIVERED) , m_cur_Analog(*this, "m_cur_Analog", 0.0) , m_railterminal(mr) { @@ -795,23 +795,23 @@ detail::net_t::~net_t() void detail::net_t::inc_active(core_terminal_t &term) NL_NOEXCEPT { - m_active++; + ++m_active; m_list_active.push_front(&term); nl_assert(m_active <= static_cast<int>(num_cons())); if (m_active == 1) { railterminal().device().do_inc_active(); - if (m_in_queue == 0) + if (m_in_queue == QS_DELAYED_DUE_TO_INACTIVE) { if (m_time > netlist().time()) { - m_in_queue = 1; /* pending */ + m_in_queue = QS_QUEUED; /* pending */ netlist().queue().push(queue_t::entry_t(m_time, this)); } else { + m_in_queue = QS_DELIVERED; m_cur_Q = m_new_Q; - m_in_queue = 2; } } } @@ -856,7 +856,7 @@ void detail::net_t::update_devs() NL_NOEXCEPT const auto mask = masks[ (m_cur_Q << 1) | m_new_Q ]; m_cur_Q = m_new_Q; - m_in_queue = 2; /* mark as taken ... */ + m_in_queue = QS_DELIVERED; /* mark as taken ... */ for (auto & p : m_list_active) { @@ -870,7 +870,7 @@ void detail::net_t::reset() { m_time = netlist_time::zero(); m_active = 0; - m_in_queue = 2; + m_in_queue = QS_DELIVERED; m_new_Q = 0; m_cur_Q = 0; @@ -892,7 +892,7 @@ void detail::net_t::reset() void detail::net_t::add_terminal(detail::core_terminal_t &terminal) { - for (auto t : m_core_terms) + for (auto &t : m_core_terms) if (t == &terminal) netlist().log().fatal(MF_2_NET_1_DUPLICATE_TERMINAL_2, name(), t->name()); diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index ff457d21d4d..16a6f30212f 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -329,7 +329,7 @@ namespace netlist operator T & () NL_NOEXCEPT { return m_value; } //! Return const value of state variable. constexpr operator const T & () const NL_NOEXCEPT { return m_value; } - T * ptr() { return &m_value; } + T * ptr() NL_NOEXCEPT { return &m_value; } constexpr T * ptr() const NL_NOEXCEPT{ return &m_value; } private: T m_value; @@ -417,8 +417,8 @@ namespace netlist { netlist_ref(netlist_t &nl) : m_netlist(nl) { } - netlist_t & netlist() { return m_netlist; } - const netlist_t & netlist() const { return m_netlist; } + netlist_t & netlist() NL_NOEXCEPT { return m_netlist; } + const netlist_t & netlist() const NL_NOEXCEPT { return m_netlist; } protected: ~netlist_ref() {} // prohibit polymorphic destruction @@ -554,19 +554,19 @@ namespace netlist terminal_t(core_device_t &dev, const pstring &aname); virtual ~terminal_t(); - nl_double operator ()() const; + nl_double operator ()() const NL_NOEXCEPT; - void set(const nl_double G) + void set(const nl_double G) NL_NOEXCEPT { set(G,G, 0.0); } - void set(const nl_double GO, const nl_double GT) + void set(const nl_double GO, const nl_double GT) NL_NOEXCEPT { set(GO, GT, 0.0); } - void set(const nl_double GO, const nl_double GT, const nl_double I) + void set(const nl_double GO, const nl_double GT, const nl_double I) NL_NOEXCEPT { set_ptr(m_Idr1, I); set_ptr(m_go1, GO); @@ -576,7 +576,7 @@ namespace netlist void solve_now(); void schedule_solve_after(const netlist_time &after); - void set_ptrs(nl_double *gt, nl_double *go, nl_double *Idr) + void set_ptrs(nl_double *gt, nl_double *go, nl_double *Idr) NL_NOEXCEPT { m_gt1 = gt; m_go1 = go; @@ -586,7 +586,7 @@ namespace netlist terminal_t *m_otherterm; private: - void set_ptr(nl_double *ptr, const nl_double val) + void set_ptr(nl_double *ptr, const nl_double val) NL_NOEXCEPT { if (ptr != nullptr && *ptr != val) { @@ -644,10 +644,10 @@ namespace netlist return Q(); } - void inactivate(); - void activate(); - void activate_hl(); - void activate_lh(); + void inactivate() NL_NOEXCEPT; + void activate() NL_NOEXCEPT; + void activate_hl() NL_NOEXCEPT; + void activate_lh() NL_NOEXCEPT; }; @@ -693,6 +693,13 @@ namespace netlist { public: + enum queue_status + { + QS_DELAYED_DUE_TO_INACTIVE = 0, + QS_QUEUED, + QS_DELIVERED + }; + net_t(netlist_t &nl, const pstring &aname, core_terminal_t *mr = nullptr); virtual ~net_t(); @@ -707,7 +714,7 @@ namespace netlist } void push_to_queue(const netlist_time delay) NL_NOEXCEPT; - bool is_queued() const NL_NOEXCEPT { return m_in_queue == 1; } + bool is_queued() const NL_NOEXCEPT { return m_in_queue == QS_QUEUED; } void update_devs() NL_NOEXCEPT; @@ -741,7 +748,7 @@ namespace netlist state_var<netlist_time> m_time; state_var_s32 m_active; - state_var_u8 m_in_queue; /* 0: not in queue, 1: in queue, 2: last was taken */ + state_var<queue_status> m_in_queue; /* 0: not in queue, 1: in queue, 2: last was taken */ state_var<nl_double> m_cur_Analog; @@ -785,7 +792,7 @@ namespace netlist { if (newQ != m_new_Q) { - m_in_queue = 0; + m_in_queue = QS_DELAYED_DUE_TO_INACTIVE; m_time = at; } m_cur_Q = m_new_Q = newQ; @@ -910,7 +917,7 @@ namespace netlist { public: param_ptr_t(device_t &device, const pstring name, std::uint8_t* val); - std::uint8_t * operator()() const { return m_param; } + std::uint8_t * operator()() const NL_NOEXCEPT { return m_param; } void setTo(std::uint8_t *param) { set(m_param, param); } private: std::uint8_t* m_param; @@ -920,7 +927,7 @@ namespace netlist { public: param_logic_t(device_t &device, const pstring name, const bool val); - bool operator()() const { return m_param; } + bool operator()() const NL_NOEXCEPT { return m_param; } void setTo(const bool ¶m) { set(m_param, param); } private: bool m_param; @@ -930,7 +937,7 @@ namespace netlist { public: param_int_t(device_t &device, const pstring name, const int val); - int operator()() const { return m_param; } + int operator()() const NL_NOEXCEPT { return m_param; } void setTo(const int ¶m) { set(m_param, param); } private: int m_param; @@ -940,7 +947,7 @@ namespace netlist { public: param_double_t(device_t &device, const pstring name, const double val); - double operator()() const { return m_param; } + double operator()() const NL_NOEXCEPT { return m_param; } void setTo(const double ¶m) { set(m_param, param); } private: double m_param; @@ -952,8 +959,8 @@ namespace netlist param_str_t(device_t &device, const pstring name, const pstring val); virtual ~param_str_t(); - const pstring operator()() const { return Value(); } - void setTo(const pstring ¶m) + const pstring operator()() const NL_NOEXCEPT { return Value(); } + void setTo(const pstring ¶m) NL_NOEXCEPT { if (m_param != param) { @@ -964,7 +971,7 @@ namespace netlist } protected: virtual void changed(); - pstring Value() const { return m_param; } + pstring Value() const NL_NOEXCEPT { return m_param; } private: pstring m_param; }; @@ -1205,13 +1212,13 @@ namespace netlist /* run functions */ - const netlist_time time() const { return m_time; } - devices::NETLIB_NAME(solver) *solver() const { return m_solver; } + const netlist_time time() const NL_NOEXCEPT { return m_time; } + devices::NETLIB_NAME(solver) *solver() const NL_NOEXCEPT { return m_solver; } /* never use this in constructors! */ nl_double gmin() const; - void process_queue(const netlist_time &delta); + void process_queue(const netlist_time &delta) NL_NOEXCEPT; void abort_current_queue_slice() { m_queue.retime(nullptr, m_time); } /* Control functions */ @@ -1220,12 +1227,12 @@ namespace netlist void stop(); void reset(); - const detail::queue_t &queue() const { return m_queue; } - detail::queue_t &queue() { return m_queue; } + const detail::queue_t &queue() const NL_NOEXCEPT { return m_queue; } + detail::queue_t &queue() NL_NOEXCEPT { return m_queue; } /* netlist build functions */ - setup_t &setup() { return *m_setup; } + setup_t &setup() NL_NOEXCEPT { return *m_setup; } void register_dev(plib::owned_ptr<core_device_t> dev); void remove_dev(core_device_t *dev); @@ -1358,7 +1365,7 @@ namespace netlist device.netlist().log().warning("Rom {1} not found", Value()); } - inline void logic_input_t::inactivate() + inline void logic_input_t::inactivate() NL_NOEXCEPT { if (!is_state(STATE_INP_PASSIVE)) { @@ -1367,7 +1374,7 @@ namespace netlist } } - inline void logic_input_t::activate() + inline void logic_input_t::activate() NL_NOEXCEPT { if (is_state(STATE_INP_PASSIVE)) { @@ -1376,7 +1383,7 @@ namespace netlist } } - inline void logic_input_t::activate_hl() + inline void logic_input_t::activate_hl() NL_NOEXCEPT { if (is_state(STATE_INP_PASSIVE)) { @@ -1385,7 +1392,7 @@ namespace netlist } } - inline void logic_input_t::activate_lh() + inline void logic_input_t::activate_lh() NL_NOEXCEPT { if (is_state(STATE_INP_PASSIVE)) { @@ -1401,8 +1408,8 @@ namespace netlist if (is_queued()) netlist().queue().remove(this); m_time = netlist().time() + delay; - m_in_queue = (m_active > 0); /* queued ? */ - if (m_in_queue) + m_in_queue = (m_active > 0) ? QS_QUEUED : QS_DELAYED_DUE_TO_INACTIVE; /* queued ? */ + if (m_in_queue == QS_QUEUED) netlist().queue().push(queue_t::entry_t(m_time, this)); } } @@ -1417,7 +1424,7 @@ namespace netlist return static_cast<analog_net_t &>(core_terminal_t::net()); } - inline nl_double terminal_t::operator ()() const { return net().Q_Analog(); } + inline nl_double terminal_t::operator ()() const NL_NOEXCEPT { return net().Q_Analog(); } inline logic_net_t & logic_t::net() NL_NOEXCEPT { diff --git a/src/lib/netlist/nl_factory.h b/src/lib/netlist/nl_factory.h index 92f126ea4d5..2366a22faae 100644 --- a/src/lib/netlist/nl_factory.h +++ b/src/lib/netlist/nl_factory.h @@ -55,7 +55,7 @@ namespace factory { const pstring ¶m_desc() const { return m_def_param; } const pstring &sourcefile() const { return m_sourcefile; } - protected: + private: pstring m_name; /* device name */ pstring m_classname; /* device class name */ pstring m_def_param; /* default parameter */ diff --git a/src/lib/netlist/nl_lists.h b/src/lib/netlist/nl_lists.h index 788d65f4c1b..a13f14c0da3 100644 --- a/src/lib/netlist/nl_lists.h +++ b/src/lib/netlist/nl_lists.h @@ -54,41 +54,53 @@ namespace netlist struct entry_t final { - constexpr entry_t() : m_exec_time(), m_object(nullptr) { } - constexpr entry_t(const Time &t, const Element &o) : m_exec_time(t), m_object(o) { } - constexpr entry_t(const entry_t &e) : m_exec_time(e.m_exec_time), m_object(e.m_object) { } - constexpr entry_t(entry_t &&e) : m_exec_time(e.m_exec_time), m_object(e.m_object) { } + constexpr entry_t() noexcept : m_exec_time(), m_object(nullptr) { } + constexpr entry_t(const Time &t, const Element &o) noexcept : m_exec_time(t), m_object(o) { } + constexpr entry_t(const entry_t &e) noexcept : m_exec_time(e.m_exec_time), m_object(e.m_object) { } + entry_t(entry_t &&e) noexcept { swap(e); } ~entry_t() = default; - entry_t& operator=(entry_t && other) + entry_t& operator=(entry_t && other) noexcept { - m_exec_time = other.m_exec_time; - m_object = other.m_object; + swap(other); return *this; } + entry_t& operator=(const entry_t &other) noexcept + { + entry_t t(other); + swap(t); + return *this; + } + + void swap(entry_t &other) noexcept + { + std::swap(m_exec_time, other.m_exec_time); + std::swap(m_object, other.m_object); + } + Time m_exec_time; Element m_object; }; - timed_queue(unsigned list_size) + timed_queue(const std::size_t list_size) : m_list(list_size) { clear(); } - constexpr std::size_t capacity() const { return m_list.size(); } - constexpr bool empty() const { return (m_end == &m_list[1]); } + constexpr std::size_t capacity() const noexcept { return m_list.size(); } + constexpr bool empty() const noexcept { return (m_end == &m_list[1]); } void push(entry_t &&e) noexcept { /* Lock */ tqlock lck(m_lock); + entry_t * i = m_end; - while (e.m_exec_time > (i - 1)->m_exec_time) + for (; e.m_exec_time > (i - 1)->m_exec_time; --i) { - *(i) = std::move(*(i-1)); - --i; + *(i) = *(i-1); m_prof_sortmove.inc(); } *i = std::move(e); @@ -96,13 +108,9 @@ namespace netlist m_prof_call.inc(); } -#if 0 - entry_t pop() noexcept { return std::move(*(--m_end)); } - const entry_t &top() const noexcept { return std::move(*(m_end-1)); } -#else entry_t pop() noexcept { return *(--m_end); } const entry_t &top() const noexcept { return *(m_end-1); } -#endif + void remove(const Element &elem) noexcept { /* Lock */ @@ -112,11 +120,8 @@ namespace netlist if (i->m_object == elem) { m_end--; - while (i < m_end) - { + for (;i < m_end; i++) *i = std::move(*(i+1)); - ++i; - } return; } } diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 0572ec1e693..1ff89819bcd 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -967,7 +967,6 @@ bool setup_t::parse_stream(plib::putf8_reader &istrm, const pstring &name) plib::putf8_writer owrt(ostrm); plib::ppreprocessor(&m_defines).process(istrm, owrt); - plib::pimemstream istrm2(ostrm); plib::putf8_reader reader2(istrm2); return parser_t(reader2, *this).parse(name); diff --git a/src/lib/netlist/nl_time.h b/src/lib/netlist/nl_time.h index 1b94c4c4827..6d6cb509ae5 100644 --- a/src/lib/netlist/nl_time.h +++ b/src/lib/netlist/nl_time.h @@ -35,35 +35,42 @@ namespace netlist using internal_type = TYPE; using mult_type = std::uint64_t; - static constexpr internal_type resolution = RES; constexpr ptime() noexcept : m_time(0) {} - constexpr ptime(const ptime &rhs) noexcept = default; - constexpr ptime(ptime &&rhs) noexcept = default; + constexpr ptime(const ptime &rhs) noexcept : m_time(rhs.m_time) { } + constexpr ptime(ptime &&rhs) noexcept : m_time(rhs.m_time) { } constexpr explicit ptime(const double t) = delete; //: m_time((internal_type) ( t * (double) resolution)) { } - constexpr explicit ptime(const internal_type nom, const internal_type den) noexcept - : m_time(nom * (resolution / den)) { } + constexpr explicit ptime(const internal_type &nom, const internal_type &den) noexcept + : m_time(nom * (RES / den)) { } - ptime &operator=(const ptime rhs) noexcept { m_time = rhs.m_time; return *this; } + ptime &operator=(const ptime &rhs) noexcept { ptime t(rhs); std::swap(m_time, t.m_time); return *this; } + ptime &operator=(ptime &&rhs) noexcept { std::swap(this->m_time, rhs.m_time); return *this; } ptime &operator+=(const ptime &rhs) noexcept { m_time += rhs.m_time; return *this; } ptime &operator-=(const ptime &rhs) noexcept { m_time -= rhs.m_time; return *this; } + ptime operator*=(const mult_type &factor) noexcept { m_time *= static_cast<internal_type>(factor); return *this; } - friend constexpr ptime operator-(const ptime &lhs, const ptime &rhs) noexcept + friend ptime operator-(const ptime &lhs, const ptime &rhs) noexcept { - return ptime(lhs.m_time - rhs.m_time); + ptime t(lhs); + t -= rhs; + return t; } - friend constexpr ptime operator+(const ptime &lhs, const ptime &rhs) noexcept + friend ptime operator+(const ptime &lhs, const ptime &rhs) noexcept { - return ptime(lhs.m_time + rhs.m_time); + ptime t(lhs); + t += rhs; + return t; } - friend constexpr ptime operator*(const ptime &lhs, const mult_type factor) noexcept + friend ptime operator*(const ptime &lhs, const mult_type &factor) noexcept { - return ptime(lhs.m_time * static_cast<internal_type>(factor)); + ptime t(lhs); + t *= factor; + return t; } friend constexpr mult_type operator/(const ptime &lhs, const ptime &rhs) noexcept @@ -105,7 +112,7 @@ namespace netlist constexpr double as_double() const noexcept { return static_cast<double>(m_time) - / static_cast<double>(resolution); + / static_cast<double>(RES); } // for save states .... @@ -116,13 +123,15 @@ namespace netlist static constexpr ptime from_msec(const internal_type ms) noexcept { return ptime(ms, UINT64_C(1000)); } static constexpr ptime from_hz(const internal_type hz) noexcept { return ptime(1 , hz); } static constexpr ptime from_raw(const internal_type raw) noexcept { return ptime(raw); } - static constexpr ptime from_double(const double t) noexcept { return ptime(static_cast<internal_type>( t * static_cast<double>(resolution)), resolution); } + static constexpr ptime from_double(const double t) noexcept { return ptime(static_cast<internal_type>( t * static_cast<double>(RES)), RES); } - static constexpr ptime zero() noexcept { return ptime(0, resolution); } - static constexpr ptime quantum() noexcept { return ptime(1, resolution); } - static constexpr ptime never() noexcept { return ptime(plib::numeric_limits<internal_type>::max(), resolution); } + static constexpr ptime zero() noexcept { return ptime(0, RES); } + static constexpr ptime quantum() noexcept { return ptime(1, RES); } + static constexpr ptime never() noexcept { return ptime(plib::numeric_limits<internal_type>::max(), RES); } + static constexpr internal_type resolution() noexcept { return RES; } private: - constexpr explicit ptime(const internal_type time) : m_time(time) {} + constexpr explicit ptime(const internal_type &time) : m_time(time) {} + constexpr explicit ptime(internal_type &&time) : m_time(time) {} internal_type m_time; }; diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index e5edfd189ed..72e17b75424 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -130,13 +130,13 @@ public: constexpr iter_t begin() const noexcept { return iter_t(m_head); } constexpr iter_t end() const noexcept { return iter_t(nullptr); } - void push_front(LC *elem) + void push_front(LC *elem) noexcept { elem->m_next = m_head; m_head = elem; } - void push_back(LC *elem) + void push_back(LC *elem) noexcept { LC **p = &m_head; while (*p != nullptr) @@ -147,7 +147,7 @@ public: elem->m_next = nullptr; } - void remove(const LC *elem) + void remove(const LC *elem) noexcept { auto p = &m_head; for ( ; *p != elem; p = &((*p)->m_next)) @@ -157,9 +157,9 @@ public: (*p) = elem->m_next; } - LC *front() const { return m_head; } - void clear() { m_head = nullptr; } - constexpr bool empty() const { return (m_head == nullptr); } + LC *front() const noexcept { return m_head; } + void clear() noexcept { m_head = nullptr; } + constexpr bool empty() const noexcept { return (m_head == nullptr); } private: LC *m_head; diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index a1165b5e924..00fcfda5bd7 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -27,11 +27,6 @@ public: static constexpr pos_type SEEK_EOF = static_cast<pos_type>(-1); - explicit pstream(const unsigned flags) : m_flags(flags) - { - } - virtual ~pstream(); - bool seekable() const { return ((m_flags & FLAG_SEEKABLE) != 0); } void seek(const pos_type n) @@ -45,6 +40,11 @@ public: } protected: + explicit pstream(const unsigned flags) : m_flags(flags) + { + } + virtual ~pstream(); + virtual void vseek(const pos_type n) = 0; virtual pos_type vtell() = 0; diff --git a/src/lib/netlist/plib/ptypes.h b/src/lib/netlist/plib/ptypes.h index 46428c9ed8a..c40cd283787 100644 --- a/src/lib/netlist/plib/ptypes.h +++ b/src/lib/netlist/plib/ptypes.h @@ -52,6 +52,17 @@ namespace plib nocopyassignmove(const nocopyassignmove &) = delete; nocopyassignmove(nocopyassignmove &&) = delete; nocopyassignmove &operator=(const nocopyassignmove &) = delete; + nocopyassignmove &operator=(nocopyassignmove &&) = delete; + }; + + struct nocopyassign + { + protected: + nocopyassign() = default; + ~nocopyassign() = default; + private: + nocopyassign(const nocopyassign &) = delete; + nocopyassign &operator=(const nocopyassign &) = delete; }; //============================================================ |