diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index e20c240a374..2450ad9e83e 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -583,9 +583,9 @@ net_t::net_t(netlist_t &nl, const pstring &aname, core_terminal_t *mr) { m_railterminal = mr; if (mr != nullptr) - nl.m_nets.push_back(std::shared_ptr(this, do_nothing_deleter())); + nl.m_nets.push_back(std::move(plib::owned_ptr(this, false))); else - nl.m_nets.push_back(std::shared_ptr(this)); + nl.m_nets.push_back(std::move(plib::owned_ptr(this, true))); } net_t::~net_t() diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 1451e18038d..79b651f2058 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -1044,7 +1044,7 @@ namespace netlist public plib::state_manager_t::callback_t { public: - queue_t(netlist_t &nl); + explicit queue_t(netlist_t &nl); protected: @@ -1070,7 +1070,7 @@ namespace netlist P_PREVENT_COPYING(netlist_t) public: - netlist_t(const pstring &aname); + explicit netlist_t(const pstring &aname); virtual ~netlist_t(); pstring name() const { return m_name; } @@ -1155,7 +1155,7 @@ namespace netlist std::vector> m_devices; /* sole use is to manage lifetime of net objects */ - std::vector> m_nets; + std::vector> m_nets; /* sole use is to manage lifetime of family objects */ std::vector>> m_family_cache; diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 0582f8a9070..99fb8962546 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -399,7 +399,7 @@ core_terminal_t *setup_t::find_terminal(const pstring &terminal_in, device_objec return term; } -param_t *setup_t::find_param(const pstring ¶m_in, bool required) +param_t *setup_t::find_param(const pstring ¶m_in, bool required) const { const pstring param_in_fqn = build_fqn(param_in); diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 2fee7210aa9..5d3cda4bd39 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -173,7 +173,7 @@ namespace netlist using link_t = std::pair; - setup_t(netlist_t &netlist); + explicit setup_t(netlist_t &netlist); ~setup_t(); netlist_t &netlist() { return m_netlist; } @@ -210,7 +210,7 @@ namespace netlist bool device_exists(const pstring name) const; - param_t *find_param(const pstring ¶m_in, bool required = true); + param_t *find_param(const pstring ¶m_in, bool required = true) const; void start_devices(); void resolve_inputs(); diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index 1529cd38194..72617aa603b 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -79,8 +79,15 @@ public: : m_ptr(p), m_is_owned(owned) { } owned_ptr(const owned_ptr &r) = delete; - owned_ptr & operator =(const owned_ptr &r) = delete; - + owned_ptr & operator =(owned_ptr &r) = delete; + owned_ptr & operator =(owned_ptr &&r) + { + m_is_owned = r.m_is_owned; + m_ptr = r.m_ptr; + r.m_is_owned = false; + r.m_ptr = nullptr; + return *this; + } owned_ptr(owned_ptr &&r) { m_is_owned = r.m_is_owned; @@ -92,17 +99,17 @@ public: template owned_ptr(owned_ptr &&r) { - SC *dest_ptr = &dynamic_cast(*r.get()); - bool o = r.is_owned(); + m_ptr = static_cast(r.get()); + m_is_owned = r.is_owned(); r.release(); - m_is_owned = o; - m_ptr = dest_ptr; } ~owned_ptr() { - if (m_is_owned) + if (m_is_owned && m_ptr != nullptr) delete m_ptr; + m_is_owned = false; + m_ptr = nullptr; } template static owned_ptr Create(Args&&... args) @@ -110,7 +117,7 @@ public: owned_ptr a; DC *x = new DC(std::forward(args)...); a.m_ptr = static_cast(x); - return a; + return std::move(a); } template @@ -118,7 +125,7 @@ public: { owned_ptr a; a.m_ptr = new SC(std::forward(args)...); - return a; + return std::move(a); } void release() { @@ -128,8 +135,9 @@ public: bool is_owned() const { return m_is_owned; } +#if 1 template - owned_ptr & operator =(owned_ptr &r) + owned_ptr & operator =(owned_ptr &&r) { m_is_owned = r.m_is_owned; m_ptr = r.m_ptr; @@ -137,6 +145,7 @@ public: r.m_ptr = nullptr; return *this; } +#endif SC * operator ->() const { return m_ptr; } SC & operator *() const { return *m_ptr; } SC * get() const { return m_ptr; } diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index 8d753e212c6..0f7b7ffb565 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -118,6 +118,8 @@ public: } } + netlist::setup_t &setup() { return *m_setup; } + tool_options_t *m_opts; protected: @@ -143,11 +145,13 @@ void usage(tool_options_t &opts) struct input_t { +#if 0 input_t() : m_param(nullptr), m_value(0.0) { } - input_t(netlist::netlist_t *netlist, const pstring &line) +#endif + input_t(const netlist::setup_t &setup, const pstring &line) { char buf[400]; double t; @@ -155,7 +159,7 @@ struct input_t if ( e!= 3) throw netlist::fatalerror_e(plib::pfmt("error {1} scanning line {2}\n")(e)(line)); m_time = netlist::netlist_time::from_double(t); - m_param = netlist->setup().find_param(buf, true); + m_param = setup.find_param(buf, true); } void setparam() @@ -183,9 +187,9 @@ struct input_t }; -std::vector *read_input(netlist::netlist_t *netlist, pstring fname) +static std::vector read_input(const netlist::setup_t &setup, pstring fname) { - std::vector *ret = plib::palloc>(); + std::vector ret; if (fname != "") { plib::pifilestream f(fname); @@ -194,8 +198,8 @@ std::vector *read_input(netlist::netlist_t *netlist, pstring fname) { if (l != "") { - input_t inp(netlist, l); - ret->push_back(inp); + input_t inp(setup, l); + ret.push_back(inp); } } } @@ -220,7 +224,7 @@ static void run(tool_options_t &opts) nt.read_netlist(opts.opt_file(), opts.opt_name()); - std::vector *inps = read_input(&nt, opts.opt_inp()); + std::vector inps = read_input(nt.setup(), opts.opt_inp()); double ttr = opts.opt_ttr(); t.stop(); @@ -234,16 +238,15 @@ static void run(tool_options_t &opts) unsigned pos = 0; netlist::netlist_time nlt = netlist::netlist_time::zero(); - while (pos < inps->size() && (*inps)[pos].m_time < netlist::netlist_time::from_double(ttr)) + while (pos < inps.size() && inps[pos].m_time < netlist::netlist_time::from_double(ttr)) { - nt.process_queue((*inps)[pos].m_time - nlt); - (*inps)[pos].setparam(); - nlt = (*inps)[pos].m_time; + nt.process_queue(inps[pos].m_time - nlt); + inps[pos].setparam(); + nlt = inps[pos].m_time; pos++; } nt.process_queue(netlist::netlist_time::from_double(ttr) - nlt); nt.stop(); - plib::pfree(inps); t.stop();