From 0d08c04009a954a64b7bf4d7be978a744940d721 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Thu, 25 Aug 2016 04:02:08 +1000 Subject: [PATCH] Devices can be found array-style, too --- src/emu/devfind.h | 121 +++++++++++++++++++++++++-------------- src/mame/drivers/cmi.cpp | 12 +--- 2 files changed, 81 insertions(+), 52 deletions(-) diff --git a/src/emu/devfind.h b/src/emu/devfind.h index 5d0ecce94ed..ab20cd83571 100644 --- a/src/emu/devfind.h +++ b/src/emu/devfind.h @@ -23,6 +23,44 @@ // TYPE DEFINITIONS //************************************************************************** +// ======================> array_finder_base + +template +class array_finder_base +{ +private: + template struct indices { }; + template struct range : public range { }; + template struct range<0U, V...> { typedef indices type; }; + template using index_range = typename range::type; + + template + array_finder_base(device_t &base, F const &fmt, unsigned start, indices) + : m_tag{ util::string_format(fmt, start + V)... } + , m_array{ { base, m_tag[V].c_str() }... } + { + } + + template + array_finder_base(device_t &base, std::array const &tags, indices) + : m_array{ { base, tags[V] }... } + { + } + +protected: + template array_finder_base(device_t &base, F const &fmt, unsigned start) : array_finder_base(base, fmt, start, index_range()) { } + array_finder_base(device_t &base, std::array const &tags) : array_finder_base(base, tags, index_range()) { } + + std::string m_tag[Count]; + T m_array[Count]; + +public: + const T &operator[](unsigned index) const { assert(index < Count); return m_array[index]; } + T &operator[](unsigned index) { assert(index < Count); return m_array[index]; } + +}; + + // ======================> finder_base // helper class to request auto-object discovery in the constructor of a derived class @@ -131,6 +169,44 @@ public: }; +// ======================> device_array_finder + +// device array finder template +template +class device_array_finder : public array_finder_base, Count> +{ +public: + template + device_array_finder(device_t &base, F const &fmt, unsigned start) + : array_finder_base, Count>(base, fmt, start) + { + } + + device_array_finder(device_t &base, std::array const &tags) + : array_finder_base, Count>(base, tags) + { + } +}; + +// optional device array finder +template +class optional_device_array : public device_array_finder +{ +public: + template optional_device_array(device_t &base, F const &fmt, unsigned start) : device_array_finder(base, fmt, start) { } + optional_device_array(device_t &base, std::array const &tags) : device_array_finder(base, tags) { } +}; + +// required device array finder +template +class required_device_array : public device_array_finder +{ +public: + template required_device_array(device_t &base, F const &fmt, unsigned start) : device_array_finder(base, fmt, start) { } + required_device_array(device_t &base, std::array const &tags) : device_array_finder(base, tags) { } +}; + + // ======================> memory_region_finder // device finder template @@ -217,7 +293,7 @@ public: // ======================> ioport_finder -// device finder template +// ioport finder template template class ioport_finder : public object_finder_base { @@ -242,59 +318,20 @@ public: } }; -// optional device finder +// optional ioport finder class optional_ioport : public ioport_finder { public: optional_ioport(device_t &base, const char *tag = FINDER_DUMMY_TAG) : ioport_finder(base, tag) { } }; -// required devices are similar but throw an error if they are not found +// required ioports are similar but throw an error if they are not found class required_ioport : public ioport_finder { public: required_ioport(device_t &base, const char *tag = FINDER_DUMMY_TAG) : ioport_finder(base, tag) { } }; - -// ======================> array_finder_base - -template -class array_finder_base -{ -private: - template struct indices { }; - template struct range : public range { }; - template struct range<0U, V...> { typedef indices type; }; - template using index_range = typename range::type; - - template - array_finder_base(device_t &base, F const &fmt, unsigned start, indices) - : m_tag{ util::string_format(fmt, start + V)... } - , m_array{ { base, m_tag[V].c_str() }... } - { - } - - template - array_finder_base(device_t &base, std::array const &tags, indices) - : m_array{ { base, tags[V] }... } - { - } - -protected: - template array_finder_base(device_t &base, F const &fmt, unsigned start) : array_finder_base(base, fmt, start, index_range()) { } - array_finder_base(device_t &base, std::array const &tags) : array_finder_base(base, tags, index_range()) { } - - std::string m_tag[Count]; - T m_array[Count]; - -public: - const T &operator[](unsigned index) const { assert(index < Count); return m_array[index]; } - T &operator[](unsigned index) { assert(index < Count); return m_array[index]; } - -}; - - // ======================> ioport_array_finder // ioport array finder template diff --git a/src/mame/drivers/cmi.cpp b/src/mame/drivers/cmi.cpp index 9b55e5d5828..4fa59141e73 100644 --- a/src/mame/drivers/cmi.cpp +++ b/src/mame/drivers/cmi.cpp @@ -385,15 +385,7 @@ public: , m_floppy_1(*this, "wd1791:1") , m_floppy(nullptr) , m_wd1791(*this, "wd1791") - , m_channels{ - { *this, "cmi01a_0" }, - { *this, "cmi01a_1" }, - { *this, "cmi01a_2" }, - { *this, "cmi01a_3" }, - { *this, "cmi01a_4" }, - { *this, "cmi01a_5" }, - { *this, "cmi01a_6" }, - { *this, "cmi01a_7" } } + , m_channels(*this, "cmi01a_%u", 0) , m_cmi10_pia_u20(*this, "cmi10_pia_u20") , m_cmi10_pia_u21(*this, "cmi10_pia_u21") , m_dp1(*this, "dp1") @@ -555,7 +547,7 @@ protected: floppy_image_device *m_floppy; required_device m_wd1791; - required_device m_channels[8]; + required_device_array m_channels; required_device m_cmi10_pia_u20; required_device m_cmi10_pia_u21;