remove all usages of tagmap

This commit is contained in:
Miodrag Milanovic 2016-06-18 12:52:53 +02:00
parent 78c3929217
commit 1d0e0ac12a
12 changed files with 44 additions and 145 deletions

View File

@ -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",

View File

@ -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<rpk_socket> 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_socket> 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<rpk_socket>(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_socket> 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<rpk_socket>(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 <rom> or <ram>");
}

View File

@ -475,12 +475,12 @@ class rpk;
class rpk_socket
{
friend class simple_list<rpk_socket>;
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<rpk_socket> load_rom_resource(util::archive_file &zip, xml_data_node* rom_resource_node, const char* socketname);
std::unique_ptr<rpk_socket> 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<rpk_socket> m_sockets;
std::unordered_map<std::string,std::unique_ptr<rpk_socket>> m_sockets;
void add_socket(const char* id, rpk_socket *newsock);
void add_socket(const char* id, std::unique_ptr<rpk_socket> newsock);
};
enum rpk_open_error

View File

@ -12,7 +12,6 @@
#define NETLIST_H
#include "emu.h"
#include "tagmap.h"
#include "netlist/nl_base.h"
#include "netlist/nl_setup.h"

View File

@ -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<device_slot_option>(name, devtype)));
}

View File

@ -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

View File

@ -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<ioport_port>(m_owner, fulltag.c_str())));
m_curport = m_portlist.find(fulltag)->second.get();
m_curfield = nullptr;

View File

@ -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)

View File

@ -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)

View File

@ -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 <string>
#include <utility>
#include <unordered_map>
//**************************************************************************
// 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 _ElementType>
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<std::string,_ElementType *> m_map;
};
#endif /* __TAGMAP_H__ */

View File

@ -17,7 +17,6 @@
#include "md5.h"
#include "sha1.h"
#include "vbiparse.h"
#include "tagmap.h"
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>

View File

@ -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)