mirror of
https://github.com/holub/mame
synced 2025-04-24 01:11:11 +03:00
Remove shared_ptr usage and replace with plib:owned_ptr. Clean up nltool
a bit. (nw)
This commit is contained in:
parent
bf2c6fe48f
commit
d1cd307f83
@ -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<net_t>(this, do_nothing_deleter()));
|
||||
nl.m_nets.push_back(std::move(plib::owned_ptr<net_t>(this, false)));
|
||||
else
|
||||
nl.m_nets.push_back(std::shared_ptr<net_t>(this));
|
||||
nl.m_nets.push_back(std::move(plib::owned_ptr<net_t>(this, true)));
|
||||
}
|
||||
|
||||
net_t::~net_t()
|
||||
|
@ -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<plib::owned_ptr<core_device_t>> m_devices;
|
||||
|
||||
/* sole use is to manage lifetime of net objects */
|
||||
std::vector<std::shared_ptr<net_t>> m_nets;
|
||||
std::vector<plib::owned_ptr<net_t>> m_nets;
|
||||
|
||||
/* sole use is to manage lifetime of family objects */
|
||||
std::vector<std::pair<pstring, std::unique_ptr<logic_family_desc_t>>> m_family_cache;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -173,7 +173,7 @@ namespace netlist
|
||||
|
||||
using link_t = std::pair<pstring, pstring>;
|
||||
|
||||
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();
|
||||
|
@ -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<typename DC>
|
||||
owned_ptr(owned_ptr<DC> &&r)
|
||||
{
|
||||
SC *dest_ptr = &dynamic_cast<SC &>(*r.get());
|
||||
bool o = r.is_owned();
|
||||
m_ptr = static_cast<SC *>(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<typename DC, typename... Args>
|
||||
static owned_ptr Create(Args&&... args)
|
||||
@ -110,7 +117,7 @@ public:
|
||||
owned_ptr a;
|
||||
DC *x = new DC(std::forward<Args>(args)...);
|
||||
a.m_ptr = static_cast<SC *>(x);
|
||||
return a;
|
||||
return std::move(a);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
@ -118,7 +125,7 @@ public:
|
||||
{
|
||||
owned_ptr a;
|
||||
a.m_ptr = new SC(std::forward<Args>(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<typename DC>
|
||||
owned_ptr<DC> & operator =(owned_ptr<DC> &r)
|
||||
owned_ptr & operator =(owned_ptr<DC> &&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; }
|
||||
|
@ -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<input_t> *read_input(netlist::netlist_t *netlist, pstring fname)
|
||||
static std::vector<input_t> read_input(const netlist::setup_t &setup, pstring fname)
|
||||
{
|
||||
std::vector<input_t> *ret = plib::palloc<std::vector<input_t>>();
|
||||
std::vector<input_t> ret;
|
||||
if (fname != "")
|
||||
{
|
||||
plib::pifilestream f(fname);
|
||||
@ -194,8 +198,8 @@ std::vector<input_t> *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<input_t> *inps = read_input(&nt, opts.opt_inp());
|
||||
std::vector<input_t> 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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user