mirror of
https://github.com/holub/mame
synced 2025-04-23 17:00:53 +03:00
Refactored factory. Use namespace "factory" instead of prefix factory_
all over the place. (nw)
This commit is contained in:
parent
9a7b32f29d
commit
db7cdcb957
@ -63,7 +63,7 @@ NETLIST_END()
|
||||
#define ENTRY1(nic, name, defparam) factory.register_device<nic>( # name, xstr(nic), defparam );
|
||||
#define ENTRY(nic, name, defparam) ENTRY1(NETLIB_NAME(nic), name, defparam)
|
||||
|
||||
#define NETLIB_DEVICE_DECL(chip) extern factory_creator_ptr_t decl_ ## chip;
|
||||
#define NETLIB_DEVICE_DECL(chip) extern factory::constructor_ptr_t decl_ ## chip;
|
||||
|
||||
#define ENTRYX1(nic, name, defparam, decl) factory.register_device( decl (# name, xstr(nic), defparam) );
|
||||
#define ENTRYX(nic, name, defparam) { NETLIB_DEVICE_DECL(nic) ENTRYX1(NETLIB_NAME(nic), name, defparam, decl_ ## nic) }
|
||||
@ -72,7 +72,7 @@ namespace netlist
|
||||
{
|
||||
namespace devices
|
||||
{
|
||||
static void initialize_factory(factory_list_t &factory)
|
||||
static void initialize_factory(factory::list_t &factory)
|
||||
{
|
||||
ENTRY(R, RES, "R")
|
||||
ENTRY(POT, POT, "R")
|
||||
@ -204,7 +204,7 @@ static void initialize_factory(factory_list_t &factory)
|
||||
|
||||
namespace netlist
|
||||
{
|
||||
void initialize_factory(factory_list_t &factory)
|
||||
void initialize_factory(factory::list_t &factory)
|
||||
{
|
||||
devices::initialize_factory(factory);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ NETLIST_EXTERNAL(bjt_models)
|
||||
NETLIST_EXTERNAL(family_models)
|
||||
|
||||
namespace netlist {
|
||||
void initialize_factory(netlist::factory_list_t &factory);
|
||||
void initialize_factory(factory::list_t &factory);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -62,7 +62,7 @@ namespace netlist
|
||||
register_subalias("2", m_C);
|
||||
register_subalias("3", m_LTQ);
|
||||
register_subalias("4", m_BIQ);
|
||||
register_subalias("5",m_RBIQ);
|
||||
register_subalias("5", m_RBIQ);
|
||||
register_subalias("6", m_D);
|
||||
register_subalias("7", m_A);
|
||||
|
||||
|
@ -71,7 +71,7 @@ namespace netlist
|
||||
{
|
||||
NETLIB_CONSTRUCTOR_DERIVED(7493_dip, 7493)
|
||||
{
|
||||
register_subalias("1", B.m_I);
|
||||
register_subalias("1", "CLKB");
|
||||
register_subalias("2", m_R1);
|
||||
register_subalias("3", m_R2);
|
||||
|
||||
@ -80,13 +80,13 @@ namespace netlist
|
||||
// register_subalias("6", ); --> NC
|
||||
// register_subalias("7", ); --> NC
|
||||
|
||||
register_subalias("8", C.m_Q);
|
||||
register_subalias("9", B.m_Q);
|
||||
register_subalias("8", "QC");
|
||||
register_subalias("9", "QB");
|
||||
// register_subalias("10", ); -. GND
|
||||
register_subalias("11", D.m_Q);
|
||||
register_subalias("12", A.m_Q);
|
||||
register_subalias("11", "QD");
|
||||
register_subalias("12", "QA");
|
||||
// register_subalias("13", ); -. NC
|
||||
register_subalias("14", A.m_I);
|
||||
register_subalias("14", "CLKA");
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -366,13 +366,13 @@ namespace netlist
|
||||
plib::pstring_vector_t m_desc;
|
||||
};
|
||||
|
||||
class netlist_base_factory_truthtable_t : public base_factory_t
|
||||
class netlist_base_factory_truthtable_t : public factory::element_t
|
||||
{
|
||||
P_PREVENT_COPYING(netlist_base_factory_truthtable_t)
|
||||
public:
|
||||
netlist_base_factory_truthtable_t(const pstring &name, const pstring &classname,
|
||||
const pstring &def_param)
|
||||
: base_factory_t(name, classname, def_param), m_family(family_TTL())
|
||||
: factory::element_t(name, classname, def_param), m_family(family_TTL())
|
||||
{}
|
||||
|
||||
virtual ~netlist_base_factory_truthtable_t()
|
||||
|
@ -413,47 +413,6 @@ namespace netlist
|
||||
state_var<netlist_sig_t> m_last_state;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// factory class to wrap macro based chips/elements
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class factory_lib_entry_t : public base_factory_t
|
||||
{
|
||||
P_PREVENT_COPYING(factory_lib_entry_t)
|
||||
public:
|
||||
|
||||
factory_lib_entry_t(setup_t &setup, const pstring &name, const pstring &classname,
|
||||
const pstring &def_param)
|
||||
: base_factory_t(name, classname, def_param), m_setup(setup) { }
|
||||
|
||||
class wrapper : public device_t
|
||||
{
|
||||
public:
|
||||
wrapper(netlist_t &anetlist, const pstring &name)
|
||||
: device_t(anetlist, name)
|
||||
{
|
||||
}
|
||||
protected:
|
||||
NETLIB_RESETI() { }
|
||||
NETLIB_UPDATEI() { }
|
||||
};
|
||||
|
||||
plib::owned_ptr<device_t> Create(netlist_t &anetlist, const pstring &name) override
|
||||
{
|
||||
return plib::owned_ptr<device_t>::Create<wrapper>(anetlist, name);
|
||||
}
|
||||
|
||||
void macro_actions(netlist_t &anetlist, const pstring &name) override
|
||||
{
|
||||
anetlist.setup().namespace_push(name);
|
||||
anetlist.setup().include(this->name());
|
||||
anetlist.setup().namespace_pop();
|
||||
}
|
||||
|
||||
private:
|
||||
setup_t &m_setup;
|
||||
};
|
||||
|
||||
} //namespace devices
|
||||
} // namespace netlist
|
||||
|
||||
|
@ -12,28 +12,28 @@
|
||||
#include "nl_setup.h"
|
||||
#include "plib/putil.h"
|
||||
|
||||
namespace netlist
|
||||
namespace netlist { namespace factory
|
||||
{
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// net_device_t_base_factory
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
factory_list_t::factory_list_t( setup_t &setup)
|
||||
list_t::list_t( setup_t &setup)
|
||||
: m_setup(setup)
|
||||
{
|
||||
}
|
||||
|
||||
factory_list_t::~factory_list_t()
|
||||
list_t::~list_t()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void factory_list_t::error(const pstring &s)
|
||||
void list_t::error(const pstring &s)
|
||||
{
|
||||
m_setup.log().fatal("{1}", s);
|
||||
}
|
||||
|
||||
base_factory_t * factory_list_t::factory_by_name(const pstring &devname)
|
||||
factory::element_t * list_t::factory_by_name(const pstring &devname)
|
||||
{
|
||||
for (auto & e : *this)
|
||||
{
|
||||
@ -45,4 +45,21 @@ base_factory_t * factory_list_t::factory_by_name(const pstring &devname)
|
||||
return nullptr; // appease code analysis
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// factory_lib_entry_t: factory class to wrap macro based chips/elements
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
plib::owned_ptr<device_t> library_element_t::Create(netlist_t &anetlist, const pstring &name)
|
||||
{
|
||||
return plib::owned_ptr<device_t>::Create<wrapper>(anetlist, name);
|
||||
}
|
||||
|
||||
void library_element_t::macro_actions(netlist_t &anetlist, const pstring &name)
|
||||
{
|
||||
anetlist.setup().namespace_push(name);
|
||||
anetlist.setup().include(this->name());
|
||||
anetlist.setup().namespace_pop();
|
||||
}
|
||||
|
||||
|
||||
} }
|
||||
|
@ -17,24 +17,24 @@
|
||||
#include "plib/putil.h"
|
||||
#include "nl_base.h"
|
||||
|
||||
#define NETLIB_DEVICE_IMPL(chip) factory_creator_ptr_t decl_ ## chip = factory_creator_t< NETLIB_NAME(chip) >;
|
||||
#define NETLIB_DEVICE_IMPL(chip) factory::constructor_ptr_t decl_ ## chip = factory::constructor_t< NETLIB_NAME(chip) >;
|
||||
|
||||
namespace netlist
|
||||
namespace netlist { namespace factory
|
||||
{
|
||||
// -----------------------------------------------------------------------------
|
||||
// net_dev class factory
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class base_factory_t
|
||||
class element_t
|
||||
{
|
||||
P_PREVENT_COPYING(base_factory_t)
|
||||
P_PREVENT_COPYING(element_t)
|
||||
public:
|
||||
base_factory_t(const pstring &name, const pstring &classname,
|
||||
element_t(const pstring &name, const pstring &classname,
|
||||
const pstring &def_param)
|
||||
: m_name(name), m_classname(classname), m_def_param(def_param)
|
||||
{}
|
||||
|
||||
virtual ~base_factory_t() {}
|
||||
virtual ~element_t() {}
|
||||
|
||||
virtual plib::owned_ptr<device_t> Create(netlist_t &anetlist, const pstring &name) = 0;
|
||||
virtual void macro_actions(netlist_t &anetlist, const pstring &name) {};
|
||||
@ -50,13 +50,13 @@ namespace netlist
|
||||
};
|
||||
|
||||
template <class C>
|
||||
class factory_t : public base_factory_t
|
||||
class device_element_t : public element_t
|
||||
{
|
||||
P_PREVENT_COPYING(factory_t)
|
||||
P_PREVENT_COPYING(device_element_t)
|
||||
public:
|
||||
factory_t(const pstring &name, const pstring &classname,
|
||||
device_element_t(const pstring &name, const pstring &classname,
|
||||
const pstring &def_param)
|
||||
: base_factory_t(name, classname, def_param) { }
|
||||
: element_t(name, classname, def_param) { }
|
||||
|
||||
plib::owned_ptr<device_t> Create(netlist_t &anetlist, const pstring &name) override
|
||||
{
|
||||
@ -64,20 +64,20 @@ namespace netlist
|
||||
}
|
||||
};
|
||||
|
||||
class factory_list_t : public std::vector<std::unique_ptr<base_factory_t>>
|
||||
class list_t : public std::vector<std::unique_ptr<element_t>>
|
||||
{
|
||||
public:
|
||||
factory_list_t(setup_t &m_setup);
|
||||
~factory_list_t();
|
||||
list_t(setup_t &m_setup);
|
||||
~list_t();
|
||||
|
||||
template<class device_class>
|
||||
void register_device(const pstring &name, const pstring &classname,
|
||||
const pstring &def_param)
|
||||
{
|
||||
register_device(std::unique_ptr<base_factory_t>(new factory_t<device_class>(name, classname, def_param)));
|
||||
register_device(std::unique_ptr<element_t>(new device_element_t<device_class>(name, classname, def_param)));
|
||||
}
|
||||
|
||||
void register_device(std::unique_ptr<base_factory_t> factory)
|
||||
void register_device(std::unique_ptr<element_t> factory)
|
||||
{
|
||||
for (auto & e : *this)
|
||||
if (e->name() == factory->name())
|
||||
@ -85,12 +85,12 @@ namespace netlist
|
||||
push_back(std::move(factory));
|
||||
}
|
||||
|
||||
base_factory_t * factory_by_name(const pstring &devname);
|
||||
element_t * factory_by_name(const pstring &devname);
|
||||
|
||||
template <class C>
|
||||
bool is_class(base_factory_t *f)
|
||||
bool is_class(element_t *f)
|
||||
{
|
||||
return dynamic_cast<factory_t<C> *>(f) != nullptr;
|
||||
return dynamic_cast<device_element_t<C> *>(f) != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -103,16 +103,49 @@ namespace netlist
|
||||
// factory_creator_ptr_t
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using factory_creator_ptr_t = std::unique_ptr<base_factory_t> (*)(const pstring &name, const pstring &classname,
|
||||
using constructor_ptr_t = std::unique_ptr<element_t> (*)(const pstring &name, const pstring &classname,
|
||||
const pstring &def_param);
|
||||
|
||||
template <typename T>
|
||||
std::unique_ptr<base_factory_t> factory_creator_t(const pstring &name, const pstring &classname,
|
||||
std::unique_ptr<element_t> constructor_t(const pstring &name, const pstring &classname,
|
||||
const pstring &def_param)
|
||||
{
|
||||
return std::unique_ptr<base_factory_t>(new factory_t<T>(name, classname, def_param));
|
||||
return std::unique_ptr<element_t>(new device_element_t<T>(name, classname, def_param));
|
||||
}
|
||||
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
// factory_lib_entry_t: factory class to wrap macro based chips/elements
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class library_element_t : public element_t
|
||||
{
|
||||
P_PREVENT_COPYING(library_element_t)
|
||||
public:
|
||||
|
||||
library_element_t(setup_t &setup, const pstring &name, const pstring &classname,
|
||||
const pstring &def_param)
|
||||
: element_t(name, classname, def_param), m_setup(setup) { }
|
||||
|
||||
class wrapper : public device_t
|
||||
{
|
||||
public:
|
||||
wrapper(netlist_t &anetlist, const pstring &name)
|
||||
: device_t(anetlist, name)
|
||||
{
|
||||
}
|
||||
protected:
|
||||
NETLIB_RESETI() { }
|
||||
NETLIB_UPDATEI() { }
|
||||
};
|
||||
|
||||
plib::owned_ptr<device_t> Create(netlist_t &anetlist, const pstring &name) override;
|
||||
|
||||
void macro_actions(netlist_t &anetlist, const pstring &name) override;
|
||||
|
||||
private:
|
||||
setup_t &m_setup;
|
||||
};
|
||||
|
||||
} }
|
||||
|
||||
#endif /* NLFACTORY_H_ */
|
||||
|
@ -356,7 +356,7 @@ void parser_t::netdev_hint()
|
||||
|
||||
void parser_t::device(const pstring &dev_type)
|
||||
{
|
||||
base_factory_t *f = m_setup.factory().factory_by_name(dev_type);
|
||||
factory::element_t *f = m_setup.factory().factory_by_name(dev_type);
|
||||
auto paramlist = plib::pstring_vector_t(f->param_desc(), ",");
|
||||
|
||||
pstring devname = get_identifier();
|
||||
|
@ -103,7 +103,7 @@ void setup_t::namespace_pop()
|
||||
|
||||
void setup_t::register_lib_entry(const pstring &name)
|
||||
{
|
||||
factory().register_device(plib::make_unique_base<base_factory_t, devices::factory_lib_entry_t>(*this, name, name, ""));
|
||||
factory().register_device(plib::make_unique_base<factory::element_t, factory::library_element_t>(*this, name, name, ""));
|
||||
}
|
||||
|
||||
void setup_t::register_dev(const pstring &classname, const pstring &name)
|
||||
@ -113,7 +113,7 @@ void setup_t::register_dev(const pstring &classname, const pstring &name)
|
||||
log().fatal("Class {1} not found!\n", classname);
|
||||
/* make sure we parse macro library entries */
|
||||
f->macro_actions(netlist(), build_fqn(name));
|
||||
m_device_factory.push_back(std::pair<pstring, base_factory_t *>(build_fqn(name), f));
|
||||
m_device_factory.push_back(std::pair<pstring, factory::element_t *>(build_fqn(name), f));
|
||||
}
|
||||
|
||||
bool setup_t::device_exists(const pstring name) const
|
||||
|
@ -252,8 +252,8 @@ namespace netlist
|
||||
void register_define(pstring def, pstring val) { m_defines.push_back(plib::ppreprocessor::define_t(def, val)); }
|
||||
void register_define(pstring defstr);
|
||||
|
||||
factory_list_t &factory() { return m_factory; }
|
||||
const factory_list_t &factory() const { return m_factory; }
|
||||
factory::list_t &factory() { return m_factory; }
|
||||
const factory::list_t &factory() const { return m_factory; }
|
||||
|
||||
/* model / family related */
|
||||
|
||||
@ -273,7 +273,7 @@ namespace netlist
|
||||
plib::plog_base<NL_DEBUG> &log();
|
||||
const plib::plog_base<NL_DEBUG> &log() const;
|
||||
|
||||
std::vector<std::pair<pstring, base_factory_t *>> m_device_factory;
|
||||
std::vector<std::pair<pstring, factory::element_t *>> m_device_factory;
|
||||
|
||||
std::unordered_map<pstring, pstring> m_alias;
|
||||
std::unordered_map<pstring, pstring> m_param_values;
|
||||
@ -303,7 +303,7 @@ namespace netlist
|
||||
netlist_t &m_netlist;
|
||||
std::unordered_map<pstring, param_ref_t> m_params;
|
||||
std::vector<link_t> m_links;
|
||||
factory_list_t m_factory;
|
||||
factory::list_t m_factory;
|
||||
std::unordered_map<pstring, pstring> m_models;
|
||||
|
||||
std::stack<pstring> m_namespace_stack;
|
||||
|
@ -346,7 +346,7 @@ static void listdevices(tool_options_t &opts)
|
||||
if (opts.opt_quiet())
|
||||
nt.log().warning.set_enabled(false);
|
||||
|
||||
netlist::factory_list_t &list = nt.setup().factory();
|
||||
netlist::factory::list_t &list = nt.setup().factory();
|
||||
|
||||
nt.setup().register_source(plib::make_unique_base<netlist::source_t,
|
||||
netlist::source_proc_t>(nt.setup(), "dummy", &netlist_dummy));
|
||||
@ -382,10 +382,12 @@ static void listdevices(tool_options_t &opts)
|
||||
if (t.first.startsWith(d->name()))
|
||||
{
|
||||
pstring tn(t.first.substr(d->name().len()+1));
|
||||
//printf("\t%s %s %s\n", t.first.c_str(), t.second.c_str(), tn.c_str());
|
||||
if (tn.find(".") == tn.end())
|
||||
{
|
||||
terms.push_back(tn);
|
||||
pstring resolved = nt.setup().resolve_alias(t.first);
|
||||
//printf("\t%s %s %s\n", t.first.c_str(), t.second.c_str(), resolved.c_str());
|
||||
if (resolved != t.first)
|
||||
{
|
||||
auto found = std::find(terms.begin(), terms.end(), resolved.substr(d->name().len()+1));
|
||||
@ -411,7 +413,7 @@ static void listdevices(tool_options_t &opts)
|
||||
pstring t = "";
|
||||
for (auto & j : terms)
|
||||
t += "," + j;
|
||||
printf("Terminals: %s\n", t.substr(1).c_str());
|
||||
printf("\tTerminals: %s\n", t.substr(1).c_str());
|
||||
}
|
||||
devs.push_back(std::move(d));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user