summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/device.h
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2018-05-04 03:01:32 +1000
committer Vas Crabb <vas@vastheman.com>2018-05-04 03:01:32 +1000
commit32a73f450da82c345b0f694bee311af34a5e717d (patch)
treede6259ee4c0120e992f348afcc9078e16bbe49d4 /src/emu/device.h
parentaa96f47092f764f089c2ce9e0f26d756197150e8 (diff)
Make MCFG_DEVICE_ADD and callable device types more flexible:
* Allows defaulted clocks (see subtle example with vboy) * Allows additional constructors (see RS232 port in tranz330) * Allows use of device finder in place of tag in MCFG_DEVICE_ADD * Requires out-of-line destructor for devices using incomplete types * Requires XTAL or explicit u32 for clocks for devices with private types Devices must still define the standard constructor. When writing additional constructors, be aware that the constructor runs before device_add_mconfig in the context of the existing device, not the new device. See osborne1, zorba, tranz330, and vboy for examples of this in use. Compilation is a bit slower, but this is temporary while refactoring is in progress. Eliminated the need for MCFG_SOUND_ROUTE_EX. Removed macros from slot option configuration - they just obfuscated code and slowed it down with needless dynamic casts, but didn't actually simplify it.
Diffstat (limited to 'src/emu/device.h')
-rw-r--r--src/emu/device.h32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/emu/device.h b/src/emu/device.h
index 3dbaa5f4e37..cc8b5209945 100644
--- a/src/emu/device.h
+++ b/src/emu/device.h
@@ -75,6 +75,17 @@ namespace emu { namespace detail {
class device_type_impl_base;
+template <typename T> struct is_device_implementation
+{
+ static constexpr bool value = std::is_base_of<device_t, T>::value;
+};
+
+template <typename T> struct is_device_interface
+{
+ static constexpr bool value = std::is_base_of<device_interface, T>::value && !is_device_implementation<T>::value;
+};
+
+
struct device_feature
{
enum type : u32
@@ -203,6 +214,8 @@ private:
device_type_impl_base *m_next;
public:
+ using exposed_type = device_t;
+
device_type_impl_base(std::nullptr_t)
: m_creator(nullptr)
, m_type(typeid(std::nullptr_t))
@@ -252,6 +265,10 @@ public:
{
return m_creator(*this, mconfig, tag, owner, clock);
}
+ std::unique_ptr<device_t> create(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock) const
+ {
+ return m_creator(*this, mconfig, tag, owner, clock);
+ }
explicit operator bool() const { return bool(m_creator); }
bool operator==(device_type_impl_base const &that) const { return &that == this; }
@@ -263,9 +280,20 @@ template <class DeviceClass>
class device_type_impl : public device_type_impl_base
{
public:
+ using exposed_type = DeviceClass;
+
using device_type_impl_base::device_type_impl_base;
- template <typename... Params> DeviceClass &operator()(machine_config &config, char const *tag, Params &&... args) const;
- template <typename Exposed, bool Required, typename... Params> DeviceClass &operator()(machine_config &config, device_finder<Exposed, Required> &finder, Params &&... args) const;
+ using device_type_impl_base::create;
+ using device_type_impl_base::operator();
+
+ template <typename... Params>
+ std::unique_ptr<DeviceClass> create(machine_config &mconfig, char const *tag, device_t *owner, Params &&... args) const
+ {
+ return make_unique_clear<DeviceClass>(mconfig, tag, owner, std::forward<Params>(args)...);
+ }
+
+ template <typename... Params> DeviceClass &operator()(machine_config &mconfig, char const *tag, Params &&... args) const;
+ template <typename Exposed, bool Required, typename... Params> DeviceClass &operator()(machine_config &mconfig, device_finder<Exposed, Required> &finder, Params &&... args) const;
};