From 1d0e0ac12ab7498df6084123aed9eae614bfde01 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 18 Jun 2016 12:52:53 +0200 Subject: [PATCH] remove all usages of tagmap --- scripts/src/lib.lua | 1 - src/devices/bus/ti99x/gromport.cpp | 52 +++++++--------- src/devices/bus/ti99x/gromport.h | 11 ++-- src/devices/machine/netlist.h | 1 - src/emu/dislot.cpp | 2 +- src/emu/emucore.h | 11 +++- src/emu/ioport.cpp | 2 +- src/emu/machine.cpp | 4 +- src/frontend/mame/clifront.cpp | 4 +- src/lib/util/tagmap.h | 96 ------------------------------ src/tools/chdman.cpp | 1 - src/tools/unidasm.cpp | 4 +- 12 files changed, 44 insertions(+), 145 deletions(-) delete mode 100644 src/lib/util/tagmap.h diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index 77f6f4344dd..2352dd6a3a3 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -80,7 +80,6 @@ project "utils" MAME_DIR .. "src/lib/util/sha1.cpp", MAME_DIR .. "src/lib/util/sha1.h", MAME_DIR .. "src/lib/util/strformat.h", - MAME_DIR .. "src/lib/util/tagmap.h", MAME_DIR .. "src/lib/util/unicode.cpp", MAME_DIR .. "src/lib/util/unicode.h", MAME_DIR .. "src/lib/util/unzip.cpp", diff --git a/src/devices/bus/ti99x/gromport.cpp b/src/devices/bus/ti99x/gromport.cpp index 32456359a40..4e9df13cdea 100644 --- a/src/devices/bus/ti99x/gromport.cpp +++ b/src/devices/bus/ti99x/gromport.cpp @@ -2446,7 +2446,7 @@ rpk::rpk(emu_options& options, const char* sysname) :m_options(options), m_type(0) //,m_system_name(sysname) { - m_sockets.reset(); + m_sockets.clear(); } rpk::~rpk() @@ -2459,9 +2459,9 @@ rpk::~rpk() */ UINT8* rpk::get_contents_of_socket(const char *socket_name) { - rpk_socket *socket = m_sockets.find(socket_name); - if (socket==nullptr) return nullptr; - return socket->get_contents(); + auto socket = m_sockets.find(socket_name); + if (socket == m_sockets.end()) return nullptr; + return socket->second->get_contents(); } /* @@ -2469,14 +2469,14 @@ UINT8* rpk::get_contents_of_socket(const char *socket_name) */ int rpk::get_resource_length(const char *socket_name) { - rpk_socket *socket = m_sockets.find(socket_name); - if (socket==nullptr) return 0; - return socket->get_content_length(); + auto socket = m_sockets.find(socket_name); + if (socket == m_sockets.end()) return 0; + return socket->second->get_content_length(); } -void rpk::add_socket(const char* id, rpk_socket *newsock) +void rpk::add_socket(const char* id, std::unique_ptr newsock) { - m_sockets.append(id, *newsock); + m_sockets.emplace(id, std::move(newsock)); } /*------------------------------------------------- @@ -2487,22 +2487,20 @@ void rpk::add_socket(const char* id, rpk_socket *newsock) void rpk::close() { // Save the NVRAM contents - rpk_socket *socket = m_sockets.first(); - while (socket != nullptr) + for(auto &socket : m_sockets) { - if (socket->persistent_ram()) + if (socket.second->persistent_ram()) { // try to open the battery file and write it if possible - assert_always(socket->get_contents() && (socket->get_content_length() > 0), "Buffer is null or length is 0"); + assert_always(socket.second->get_contents() && (socket.second->get_content_length() > 0), "Buffer is null or length is 0"); emu_file file(m_options.nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - osd_file::error filerr = file.open(socket->get_pathname()); + osd_file::error filerr = file.open(socket.second->get_pathname()); if (filerr == osd_file::error::NONE) - file.write(socket->get_contents(), socket->get_content_length()); + file.write(socket.second->get_contents(), socket.second->get_content_length()); } - socket->cleanup(); - socket = socket->m_next; + socket.second->cleanup(); } } @@ -2512,12 +2510,12 @@ void rpk::close() ***************************************************************/ rpk_socket::rpk_socket(const char* id, int length, UINT8* contents, const char *pathname) -: m_id(id), m_length(length), m_next(nullptr), m_contents(contents), m_pathname(pathname) +: m_id(id), m_length(length), m_contents(contents), m_pathname(pathname) { } rpk_socket::rpk_socket(const char* id, int length, UINT8* contents) -: m_id(id), m_length(length), m_next(nullptr), m_contents(contents), m_pathname(nullptr) +: m_id(id), m_length(length), m_contents(contents), m_pathname(nullptr) { } @@ -2554,7 +2552,7 @@ int rpk_reader::find_file(util::archive_file &zip, const char *filename, UINT32 /* Load a rom resource and put it in a pcb socket instance. */ -rpk_socket* rpk_reader::load_rom_resource(util::archive_file &zip, xml_data_node* rom_resource_node, const char* socketname) +std::unique_ptr rpk_reader::load_rom_resource(util::archive_file &zip, xml_data_node* rom_resource_node, const char* socketname) { const char* file; const char* crcstr; @@ -2613,13 +2611,13 @@ rpk_socket* rpk_reader::load_rom_resource(util::archive_file &zip, xml_data_node } // Create a socket instance - return new rpk_socket(socketname, length, contents); + return std::make_unique(socketname, length, contents); } /* Load a ram resource and put it in a pcb socket instance. */ -rpk_socket* rpk_reader::load_ram_resource(emu_options &options, xml_data_node* ram_resource_node, const char* socketname, const char* system_name) +std::unique_ptr rpk_reader::load_ram_resource(emu_options &options, xml_data_node* ram_resource_node, const char* socketname, const char* system_name) { const char* length_string; const char* ram_type; @@ -2697,7 +2695,7 @@ rpk_socket* rpk_reader::load_ram_resource(emu_options &options, xml_data_node* r } // Create a socket instance - return new rpk_socket(socketname, length, contents, ram_pname); + return std::make_unique(socketname, length, contents, ram_pname); } /*------------------------------------------------- @@ -2726,8 +2724,6 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy xml_data_node *socket_node; xml_data_node *pcb_node; - rpk_socket *newsock; - int i; auto newrpk = new rpk(options, system_name); @@ -2815,15 +2811,13 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy // found it if (strcmp(resource_node->name, "rom")==0) { - newsock = load_rom_resource(*zipfile, resource_node, id); - newrpk->add_socket(id, newsock); + newrpk->add_socket(id, load_rom_resource(*zipfile, resource_node, id)); } else { if (strcmp(resource_node->name, "ram")==0) { - newsock = load_ram_resource(options, resource_node, id, system_name); - newrpk->add_socket(id, newsock); + newrpk->add_socket(id, load_ram_resource(options, resource_node, id, system_name)); } else throw rpk_exception(RPK_INVALID_LAYOUT, "resource node must be or "); } diff --git a/src/devices/bus/ti99x/gromport.h b/src/devices/bus/ti99x/gromport.h index bebc7d9b05f..76983631e70 100644 --- a/src/devices/bus/ti99x/gromport.h +++ b/src/devices/bus/ti99x/gromport.h @@ -475,12 +475,12 @@ class rpk; class rpk_socket { - friend class simple_list; friend class rpk; public: rpk_socket(const char *id, int length, UINT8 *contents); rpk_socket(const char *id, int length, UINT8 *contents, const char *pathname); + ~rpk_socket() {} const char* id() { return m_id; } int get_content_length() { return m_length; } @@ -492,7 +492,6 @@ public: private: const char* m_id; UINT32 m_length; - rpk_socket* m_next; UINT8* m_contents; const char* m_pathname; }; @@ -507,8 +506,8 @@ public: private: int find_file(util::archive_file &zip, const char *filename, UINT32 crc); - rpk_socket* load_rom_resource(util::archive_file &zip, xml_data_node* rom_resource_node, const char* socketname); - rpk_socket* load_ram_resource(emu_options &options, xml_data_node* ram_resource_node, const char* socketname, const char* system_name); + std::unique_ptr load_rom_resource(util::archive_file &zip, xml_data_node* rom_resource_node, const char* socketname); + std::unique_ptr load_ram_resource(emu_options &options, xml_data_node* ram_resource_node, const char* socketname, const char* system_name); const pcb_type* m_types; }; @@ -528,9 +527,9 @@ private: emu_options& m_options; // need this to find the path to the nvram files int m_type; //const char* m_system_name; // need this to find the path to the nvram files - tagged_list m_sockets; + std::unordered_map> m_sockets; - void add_socket(const char* id, rpk_socket *newsock); + void add_socket(const char* id, std::unique_ptr newsock); }; enum rpk_open_error diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index 98b9c03244d..606cd4af283 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -12,7 +12,6 @@ #define NETLIST_H #include "emu.h" -#include "tagmap.h" #include "netlist/nl_base.h" #include "netlist/nl_setup.h" diff --git a/src/emu/dislot.cpp b/src/emu/dislot.cpp index 033ed05112b..416030834c8 100644 --- a/src/emu/dislot.cpp +++ b/src/emu/dislot.cpp @@ -46,7 +46,7 @@ void device_slot_interface::static_option_add(device_t &device, const char *name if (option != nullptr) throw emu_fatalerror("slot '%s' duplicate option '%s\n", device.tag(), name); - if (intf.m_options.count(name) != 0) throw add_exception(name); + if (intf.m_options.count(name) != 0) throw tag_add_exception(name); intf.m_options.emplace(std::make_pair(name, std::make_unique(name, devtype))); } diff --git a/src/emu/emucore.h b/src/emu/emucore.h index 68b9e2f0467..121ea41481c 100644 --- a/src/emu/emucore.h +++ b/src/emu/emucore.h @@ -36,8 +36,6 @@ #include "emualloc.h" #include "corestr.h" #include "bitmap.h" -#include "tagmap.h" - //************************************************************************** @@ -302,7 +300,14 @@ private: int code; }; - +class tag_add_exception +{ +public: + tag_add_exception(const char *tag) : m_tag(tag) { } + const char *tag() const { return m_tag.c_str(); } +private: + std::string m_tag; +}; //************************************************************************** // CASTING TEMPLATES diff --git a/src/emu/ioport.cpp b/src/emu/ioport.cpp index f8c03feeac7..0590f22c71a 100644 --- a/src/emu/ioport.cpp +++ b/src/emu/ioport.cpp @@ -3802,7 +3802,7 @@ void ioport_configurer::port_alloc(const char *tag) std::string fulltag = m_owner.subtag(tag); // add it to the list, and reset current field/setting - if (m_portlist.count(fulltag) != 0) throw add_exception(fulltag.c_str()); + if (m_portlist.count(fulltag) != 0) throw tag_add_exception(fulltag.c_str()); m_portlist.emplace(std::make_pair(fulltag, std::make_unique(m_owner, fulltag.c_str()))); m_curport = m_portlist.find(fulltag)->second.get(); m_curfield = nullptr; diff --git a/src/emu/machine.cpp b/src/emu/machine.cpp index 0bb7ac0ba37..4759432ff00 100644 --- a/src/emu/machine.cpp +++ b/src/emu/machine.cpp @@ -377,9 +377,9 @@ int running_machine::run(bool quiet) osd_printf_error("Error performing a late bind of type %s to %s\n", btex.m_actual_type.name(), btex.m_target_type.name()); error = EMU_ERR_FATALERROR; } - catch (add_exception &aex) + catch (tag_add_exception &aex) { - osd_printf_error("Tag '%s' already exists in tagged_list\n", aex.tag()); + osd_printf_error("Tag '%s' already exists in tagged map\n", aex.tag()); error = EMU_ERR_FATALERROR; } catch (std::exception &ex) diff --git a/src/frontend/mame/clifront.cpp b/src/frontend/mame/clifront.cpp index 0ee056ec6c7..39033e84d20 100644 --- a/src/frontend/mame/clifront.cpp +++ b/src/frontend/mame/clifront.cpp @@ -313,9 +313,9 @@ int cli_frontend::execute(int argc, char **argv) osd_printf_error("Caught unhandled emulator exception\n"); m_result = EMU_ERR_FATALERROR; } - catch (add_exception &aex) + catch (tag_add_exception &aex) { - osd_printf_error("Tag '%s' already exists in tagged_list\n", aex.tag()); + osd_printf_error("Tag '%s' already exists in tagged map\n", aex.tag()); m_result = EMU_ERR_FATALERROR; } catch (std::exception &ex) diff --git a/src/lib/util/tagmap.h b/src/lib/util/tagmap.h deleted file mode 100644 index ee4f16b96e3..00000000000 --- a/src/lib/util/tagmap.h +++ /dev/null @@ -1,96 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/*************************************************************************** - - tagmap.h - - Simple tag->object mapping functions. - -***************************************************************************/ - -#pragma once - -#ifndef __TAGMAP_H__ -#define __TAGMAP_H__ - -#include "osdcore.h" -#include "coretmpl.h" -#include -#include -#include - -//************************************************************************** -// CONSTANTS -//************************************************************************** - -enum tagmap_error -{ - TMERR_NONE, - TMERR_DUPLICATE -}; - -// ======================> tagged_list - -class add_exception -{ -public: - add_exception(const char *tag) : m_tag(tag) { } - const char *tag() const { return m_tag.c_str(); } -private: - std::string m_tag; -}; - -// a tagged_list is a class that maintains a list of objects that can be quickly looked up by tag -template -class tagged_list -{ - // we don't support deep copying - tagged_list(const tagged_list &); - tagged_list &operator=(const tagged_list &); - -public: - // construction - tagged_list() { } - - // simple getters - _ElementType *first() const { return m_list.first(); } - _ElementType *last() const { return m_list.last(); } - int count() const { return m_list.count(); } - bool empty() const { return m_list.empty(); } - - // range iterators - using auto_iterator = typename simple_list<_ElementType>::auto_iterator; - auto_iterator begin() const { return m_list.begin(); } - auto_iterator end() const { return m_list.end(); } - - // remove (free) all objects in the list, leaving an empty list - void reset() { m_list.reset(); m_map.clear(); } - - // add the given object to the head of the list - _ElementType &prepend(const char *tag, _ElementType &object) - { - if (!m_map.insert(std::make_pair(tag, &object)).second) - throw add_exception(tag); - return m_list.prepend(object); - } - - // add the given object to the tail of the list - _ElementType &append(const char *tag, _ElementType &object) - { - if (!m_map.insert(std::make_pair(tag, &object)).second) - throw add_exception(tag); - return m_list.append(object); - } - - // operations by tag - void remove(const char *tag) { auto search = m_map.find(tag); if (search != m_map.end()) { m_list.remove(*search->second); m_map.erase(search); } } - _ElementType *find(const char *tag) const { auto search = m_map.find(tag); return (search == m_map.end()) ? nullptr : search->second; } - -private: - // internal state - simple_list<_ElementType> m_list; - std::unordered_map m_map; -}; - - -#endif /* __TAGMAP_H__ */ diff --git a/src/tools/chdman.cpp b/src/tools/chdman.cpp index e54d69b0c3e..a2f154bcfc6 100644 --- a/src/tools/chdman.cpp +++ b/src/tools/chdman.cpp @@ -17,7 +17,6 @@ #include "md5.h" #include "sha1.h" #include "vbiparse.h" -#include "tagmap.h" #include #include #include diff --git a/src/tools/unidasm.cpp b/src/tools/unidasm.cpp index e70f1fc13ac..ee125761ee6 100644 --- a/src/tools/unidasm.cpp +++ b/src/tools/unidasm.cpp @@ -662,9 +662,9 @@ int main(int argc, char *argv[]) fprintf(stderr, "Caught unhandled emulator exception\n"); result = 1; } - catch (add_exception &aex) + catch (tag_add_exception &aex) { - fprintf(stderr, "Tag '%s' already exists in tagged_list\n", aex.tag()); + fprintf(stderr, "Tag '%s' already exists in tagged map\n", aex.tag()); result = 1; } catch (std::exception &ex)