summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2021-01-20 17:46:03 -0500
committer AJR <ajrhacker@users.noreply.github.com>2021-01-20 18:06:15 -0500
commit91921618c2e06bd0ed073b8efccd31a127c9012d (patch)
treed3958b32d8db82540cd31083766b22991eb8e8ae /src/emu
parentc691b79cce315acdfabe1901cb2b5a1e39957bc1 (diff)
Much more core std::string_view modernization
- Remove corestr.h from emu.h; update a few source files to not use it at all - Change strtrimspace, strtrimrightspace and core_filename_extract_* to be pure functions taking a std::string_view by value and returning the same type - Change strmakeupper and strmakelower to be pure functions taking a std::string_view and constructing a std::string - Remove the string-modifying version of zippath_parent - Change tag-based lookup functions in device_t to take std::string_view instead of const std::string & or const char * - Remove the subdevice tag cache from device_t (since device finders are now recommended) and replace it with a map covering directly owned subdevices only - Move the working directory setup method out of device_image_interface (only the UI seems to actually use the full version of this) - Change output_manager to use std::string_view for output name arguments - Change core_options to accept std::string_view for most name and value arguments (return values are still C strings for now) - Change miscellaneous other functions to accept std::string_view arguments - Remove a few string accessor macros from romload.h - Remove many unnecessary c_str() calls from logging/error messages
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/debug/debugcmd.cpp3
-rw-r--r--src/emu/debug/debugcon.cpp3
-rw-r--r--src/emu/debug/debugcpu.cpp4
-rw-r--r--src/emu/debug/debughlp.cpp1
-rw-r--r--src/emu/debug/express.cpp6
-rw-r--r--src/emu/devcb.h30
-rw-r--r--src/emu/device.cpp90
-rw-r--r--src/emu/device.h63
-rw-r--r--src/emu/diimage.cpp175
-rw-r--r--src/emu/diimage.h39
-rw-r--r--src/emu/dislot.cpp8
-rw-r--r--src/emu/dislot.h2
-rw-r--r--src/emu/disound.cpp10
-rw-r--r--src/emu/drivenum.cpp2
-rw-r--r--src/emu/emu.h1
-rw-r--r--src/emu/emuopts.cpp45
-rw-r--r--src/emu/emuopts.h9
-rw-r--r--src/emu/fileio.cpp18
-rw-r--r--src/emu/fileio.h10
-rw-r--r--src/emu/image.cpp95
-rw-r--r--src/emu/image.h5
-rw-r--r--src/emu/input.cpp19
-rw-r--r--src/emu/inputdev.cpp10
-rw-r--r--src/emu/inputdev.h2
-rw-r--r--src/emu/ioport.cpp3
-rw-r--r--src/emu/ioport.h2
-rw-r--r--src/emu/machine.cpp1
-rw-r--r--src/emu/mconfig.cpp17
-rw-r--r--src/emu/natkeyboard.cpp2
-rw-r--r--src/emu/output.cpp51
-rw-r--r--src/emu/output.h21
-rw-r--r--src/emu/render.cpp1
-rw-r--r--src/emu/rendfont.cpp1
-rw-r--r--src/emu/rendlay.cpp14
-rw-r--r--src/emu/romload.cpp89
-rw-r--r--src/emu/romload.h20
-rw-r--r--src/emu/screen.cpp2
-rw-r--r--src/emu/softlist.cpp10
-rw-r--r--src/emu/softlist.h2
-rw-r--r--src/emu/softlist_dev.cpp15
-rw-r--r--src/emu/softlist_dev.h14
-rw-r--r--src/emu/validity.cpp11
-rw-r--r--src/emu/video.cpp3
43 files changed, 509 insertions, 420 deletions
diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp
index 7e820bafa84..65a0218eddb 100644
--- a/src/emu/debug/debugcmd.cpp
+++ b/src/emu/debug/debugcmd.cpp
@@ -21,6 +21,7 @@
#include "points.h"
#include "natkeyboard.h"
#include "render.h"
+#include "corestr.h"
#include <cctype>
#include <algorithm>
#include <fstream>
@@ -3670,7 +3671,7 @@ void debugger_commands::execute_snap(int ref, const std::vector<std::string> &pa
if (fname.find(".png") == -1)
fname.append(".png");
emu_file file(m_machine.options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- osd_file::error filerr = file.open(fname);
+ osd_file::error filerr = file.open(std::move(fname));
if (filerr != osd_file::error::NONE)
{
diff --git a/src/emu/debug/debugcon.cpp b/src/emu/debug/debugcon.cpp
index 6aebd1843da..b282b000283 100644
--- a/src/emu/debug/debugcon.cpp
+++ b/src/emu/debug/debugcon.cpp
@@ -14,6 +14,7 @@
#include "debugvw.h"
#include "textbuf.h"
#include "debugger.h"
+#include "corestr.h"
#include <cctype>
#include <fstream>
@@ -517,7 +518,7 @@ void debugger_console::process_source_file()
buf.resize(pos);
// strip whitespace
- strtrimrightspace(buf);
+ buf = strtrimrightspace(buf);
// execute the command
if (!buf.empty())
diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp
index e91a7801b3c..3a06e1f8e42 100644
--- a/src/emu/debug/debugcpu.cpp
+++ b/src/emu/debug/debugcpu.cpp
@@ -22,6 +22,7 @@
#include "screen.h"
#include "uiinput.h"
+#include "corestr.h"
#include "coreutil.h"
#include "osdepend.h"
#include "xmlfile.h"
@@ -503,14 +504,13 @@ device_debug::device_debug(device_t &device)
}
// add all registers into it
- std::string tempstr;
for (const auto &entry : m_state->state_entries())
{
// TODO: floating point registers
if (!entry->is_float())
{
using namespace std::placeholders;
- strmakelower(tempstr.assign(entry->symbol()));
+ std::string tempstr(strmakelower(entry->symbol()));
m_symtable->add(
tempstr.c_str(),
std::bind(&device_state_entry::value, entry.get()),
diff --git a/src/emu/debug/debughlp.cpp b/src/emu/debug/debughlp.cpp
index cfb923cc694..e3106c647e5 100644
--- a/src/emu/debug/debughlp.cpp
+++ b/src/emu/debug/debughlp.cpp
@@ -10,6 +10,7 @@
#include "emu.h"
#include "debughlp.h"
+#include "corestr.h"
#include <cctype>
diff --git a/src/emu/debug/express.cpp b/src/emu/debug/express.cpp
index b0d72d045ec..351c340333a 100644
--- a/src/emu/debug/express.cpp
+++ b/src/emu/debug/express.cpp
@@ -31,6 +31,8 @@
#include "emu.h"
#include "express.h"
+
+#include "corestr.h"
#include <cctype>
@@ -543,9 +545,7 @@ void symbol_table::write_memory(address_space &space, offs_t address, u64 data,
device_t *symbol_table::expression_get_device(const char *tag)
{
// convert to lowercase then lookup the name (tags are enforced to be all lower case)
- std::string fullname(tag);
- strmakelower(fullname);
- return m_machine.root_device().subdevice(fullname.c_str());
+ return m_machine.root_device().subdevice(strmakelower(tag));
}
diff --git a/src/emu/devcb.h b/src/emu/devcb.h
index cdfa9321a5b..ec543aa48d6 100644
--- a/src/emu/devcb.h
+++ b/src/emu/devcb.h
@@ -605,7 +605,7 @@ private:
{
auto const target(m_delegate.finder_target());
if (target.second && !target.first.subdevice(target.second))
- osd_printf_error("Read callback bound to non-existent object tag %s (%s)\n", target.first.subtag(target.second).c_str(), m_delegate.name());
+ osd_printf_error("Read callback bound to non-existent object tag %s (%s)\n", target.first.subtag(target.second), m_delegate.name());
}
template <typename T>
@@ -668,9 +668,9 @@ private:
{
assert(this->m_consumed);
this->built();
- ioport_port *const ioport(m_devbase.ioport(m_tag.c_str()));
+ ioport_port *const ioport(m_devbase.ioport(m_tag));
if (!ioport)
- throw emu_fatalerror("Read callback bound to non-existent I/O port %s of device %s (%s)\n", m_tag.c_str(), m_devbase.tag(), m_devbase.name());
+ throw emu_fatalerror("Read callback bound to non-existent I/O port %s of device %s (%s)\n", m_tag, m_devbase.tag(), m_devbase.name());
chain(
[&port = *ioport, exor = this->exor(), mask = this->mask()] (offs_t offset, input_mask_t mem_mask)
{ return (port.read() ^ exor) & mask; });
@@ -1282,7 +1282,7 @@ private:
{
auto const target(m_delegate.finder_target());
if (target.second && !target.first.subdevice(target.second))
- osd_printf_error("Write callback bound to non-existent object tag %s (%s)\n", target.first.subtag(target.second).c_str(), m_delegate.name());
+ osd_printf_error("Write callback bound to non-existent object tag %s (%s)\n", target.first.subtag(target.second), m_delegate.name());
}
auto build()
@@ -1348,7 +1348,7 @@ private:
{
auto const target(m_delegate.finder_target());
if (target.second && !target.first.subdevice(target.second))
- osd_printf_error("Write callback bound to non-existent object tag %s (%s)\n", target.first.subtag(target.second).c_str(), m_delegate.name());
+ osd_printf_error("Write callback bound to non-existent object tag %s (%s)\n", target.first.subtag(target.second), m_delegate.name());
}
auto build()
@@ -1707,9 +1707,9 @@ private:
{
assert(this->m_consumed);
this->built();
- ioport_port *const ioport(m_devbase.ioport(m_tag.c_str()));
+ ioport_port *const ioport(m_devbase.ioport(m_tag));
if (!ioport)
- throw emu_fatalerror("Write callback bound to non-existent I/O port %s of device %s (%s)\n", m_tag.c_str(), m_devbase.tag(), m_devbase.name());
+ throw emu_fatalerror("Write callback bound to non-existent I/O port %s of device %s (%s)\n", m_tag, m_devbase.tag(), m_devbase.name());
return
[&port = *ioport] (offs_t offset, input_t data, std::make_unsigned_t<input_t> mem_mask)
{ port.write(data); };
@@ -1765,9 +1765,9 @@ private:
{
assert(this->m_consumed);
this->built();
- ioport_port *const ioport(m_devbase.ioport(m_tag.c_str()));
+ ioport_port *const ioport(m_devbase.ioport(m_tag));
if (!ioport)
- throw emu_fatalerror("Write callback bound to non-existent I/O port %s of device %s (%s)\n", m_tag.c_str(), m_devbase.tag(), m_devbase.name());
+ throw emu_fatalerror("Write callback bound to non-existent I/O port %s of device %s (%s)\n", m_tag, m_devbase.tag(), m_devbase.name());
return
[&port = *ioport, exor = this->exor(), mask = this->mask()] (offs_t offset, input_t data, std::make_unsigned_t<input_t> mem_mask)
{ port.write((data ^ exor) & mask); };
@@ -1807,9 +1807,9 @@ private:
{
assert(this->m_consumed);
this->built();
- memory_bank *const bank(m_devbase.membank(m_tag.c_str()));
+ memory_bank *const bank(m_devbase.membank(m_tag));
if (!bank)
- throw emu_fatalerror("Write callback bound to non-existent memory bank %s of device %s (%s)\n", m_tag.c_str(), m_devbase.tag(), m_devbase.name());
+ throw emu_fatalerror("Write callback bound to non-existent memory bank %s of device %s (%s)\n", m_tag, m_devbase.tag(), m_devbase.name());
return
[&membank = *bank] (offs_t offset, input_t data, std::make_unsigned_t<input_t> mem_mask)
{ membank.set_entry(data); };
@@ -1865,9 +1865,9 @@ private:
{
assert(this->m_consumed);
this->built();
- memory_bank *const bank(m_devbase.membank(m_tag.c_str()));
+ memory_bank *const bank(m_devbase.membank(m_tag));
if (!bank)
- throw emu_fatalerror("Write callback bound to non-existent memory bank %s of device %s (%s)\n", m_tag.c_str(), m_devbase.tag(), m_devbase.name());
+ throw emu_fatalerror("Write callback bound to non-existent memory bank %s of device %s (%s)\n", m_tag, m_devbase.tag(), m_devbase.name());
return
[&membank = *bank, exor = this->exor(), mask = this->mask()] (offs_t offset, input_t data, std::make_unsigned_t<input_t> mem_mask)
{ membank.set_entry((data ^ exor) & mask); };
@@ -1908,7 +1908,7 @@ private:
assert(this->m_consumed);
this->built();
return
- [&item = m_devbase.machine().output().find_or_create_item(m_tag.c_str(), 0)] (offs_t offset, input_t data, std::make_unsigned_t<input_t> mem_mask)
+ [&item = m_devbase.machine().output().find_or_create_item(m_tag, 0)] (offs_t offset, input_t data, std::make_unsigned_t<input_t> mem_mask)
{ item.set(data); };
}
@@ -1963,7 +1963,7 @@ private:
assert(this->m_consumed);
this->built();
return
- [&item = m_devbase.machine().output().find_or_create_item(m_tag.c_str(), 0), exor = this->exor(), mask = this->mask()] (offs_t offset, input_t data, std::make_unsigned_t<input_t> mem_mask)
+ [&item = m_devbase.machine().output().find_or_create_item(m_tag, 0), exor = this->exor(), mask = this->mask()] (offs_t offset, input_t data, std::make_unsigned_t<input_t> mem_mask)
{ item.set((data ^ exor) & mask); };
}
};
diff --git a/src/emu/device.cpp b/src/emu/device.cpp
index 99f3fcc7ce5..51088b02d4a 100644
--- a/src/emu/device.cpp
+++ b/src/emu/device.cpp
@@ -146,10 +146,10 @@ std::vector<std::string> device_t::searchpath() const
// info for a given region
//-------------------------------------------------
-memory_region *device_t::memregion(std::string _tag) const
+memory_region *device_t::memregion(std::string_view tag) const
{
// build a fully-qualified name and look it up
- auto search = machine().memory().regions().find(subtag(std::move(_tag)));
+ auto search = machine().memory().regions().find(subtag(tag));
if (search != machine().memory().regions().end())
return search->second.get();
else
@@ -162,10 +162,10 @@ memory_region *device_t::memregion(std::string _tag) const
// info for a given share
//-------------------------------------------------
-memory_share *device_t::memshare(std::string _tag) const
+memory_share *device_t::memshare(std::string_view tag) const
{
// build a fully-qualified name and look it up
- auto search = machine().memory().shares().find(subtag(std::move(_tag)));
+ auto search = machine().memory().shares().find(subtag(tag));
if (search != machine().memory().shares().end())
return search->second.get();
else
@@ -178,9 +178,9 @@ memory_share *device_t::memshare(std::string _tag) const
// bank info for a given bank
//-------------------------------------------------
-memory_bank *device_t::membank(std::string _tag) const
+memory_bank *device_t::membank(std::string_view tag) const
{
- auto search = machine().memory().banks().find(subtag(std::move(_tag)));
+ auto search = machine().memory().banks().find(subtag(tag));
if (search != machine().memory().banks().end())
return search->second.get();
else
@@ -193,10 +193,10 @@ memory_bank *device_t::membank(std::string _tag) const
// object for a given port name
//-------------------------------------------------
-ioport_port *device_t::ioport(std::string tag) const
+ioport_port *device_t::ioport(std::string_view tag) const
{
// build a fully-qualified name and look it up
- return machine().ioport().port(subtag(std::move(tag)).c_str());
+ return machine().ioport().port(subtag(tag));
}
@@ -205,7 +205,7 @@ ioport_port *device_t::ioport(std::string tag) const
// parameter
//-------------------------------------------------
-std::string device_t::parameter(const char *tag) const
+std::string device_t::parameter(std::string_view tag) const
{
// build a fully-qualified name and look it up
return machine().parameters().lookup(subtag(tag));
@@ -881,7 +881,7 @@ void device_t::device_timer(emu_timer &timer, device_timer_id id, int param, voi
// caching the results
//-------------------------------------------------
-device_t *device_t::subdevice_slow(const char *tag) const
+device_t *device_t::subdevice_slow(std::string_view tag) const
{
// resolve the full path
std::string fulltag = subtag(tag);
@@ -893,16 +893,22 @@ device_t *device_t::subdevice_slow(const char *tag) const
// walk the device list to the final path
device_t *curdevice = &mconfig().root_device();
- if (fulltag.length() > 1)
- for (int start = 1, end = fulltag.find_first_of(':', start); start != 0 && curdevice != nullptr; start = end + 1, end = fulltag.find_first_of(':', start))
+ std::string_view part(std::string_view(fulltag).substr(1));
+ while (!part.empty() && curdevice != nullptr)
+ {
+ std::string_view::size_type end = part.find_first_of(':');
+ if (end == std::string::npos)
{
- std::string part(fulltag, start, (end == -1) ? -1 : end - start);
curdevice = curdevice->subdevices().find(part);
+ part = std::string_view();
+ }
+ else
+ {
+ curdevice = curdevice->subdevices().find(part.substr(0, end));
+ part.remove_prefix(end + 1);
}
+ }
- // if we got a match, add to the fast map
- if (curdevice != nullptr)
- m_subdevices.m_tagmap.insert(std::make_pair(tag, curdevice));
return curdevice;
}
@@ -912,14 +918,13 @@ device_t *device_t::subdevice_slow(const char *tag) const
// to our device based on the provided tag
//-------------------------------------------------
-std::string device_t::subtag(std::string _tag) const
+std::string device_t::subtag(std::string_view tag) const
{
- const char *tag = _tag.c_str();
std::string result;
- if (*tag == ':')
+ if (!tag.empty() && tag[0] == ':')
{
// if the tag begins with a colon, ignore our path and start from the root
- tag++;
+ tag.remove_prefix(1);
result.assign(":");
}
else
@@ -931,12 +936,12 @@ std::string device_t::subtag(std::string _tag) const
}
// iterate over the tag, look for special path characters to resolve
- const char *caret;
- while ((caret = strchr(tag, '^')) != nullptr)
+ std::string_view::size_type caret;
+ while ((caret = tag.find('^')) != std::string_view::npos)
{
// copy everything up to there
- result.append(tag, caret - tag);
- tag = caret + 1;
+ result.append(tag, 0, caret);
+ tag.remove_prefix(caret + 1);
// strip trailing colons
int len = result.length();
@@ -964,6 +969,43 @@ std::string device_t::subtag(std::string _tag) const
//-------------------------------------------------
+// append - add a new subdevice to the list
+//-------------------------------------------------
+
+device_t &device_t::subdevice_list::append(std::unique_ptr<device_t> &&device)
+{
+ device_t &result(m_list.append(*device.release()));
+ m_tagmap.emplace(result.m_basetag, std::ref(result));
+ return result;
+}
+
+
+//-------------------------------------------------
+// replace_and_remove - add a new device to
+// replace an existing subdevice
+//-------------------------------------------------
+
+device_t &device_t::subdevice_list::replace_and_remove(std::unique_ptr<device_t> &&device, device_t &existing)
+{
+ m_tagmap.erase(existing.m_basetag);
+ device_t &result(m_list.replace_and_remove(*device.release(), existing));
+ m_tagmap.emplace(result.m_basetag, std::ref(result));
+ return result;
+}
+
+
+//-------------------------------------------------
+// remove - remove a subdevice from the list
+//-------------------------------------------------
+
+void device_t::subdevice_list::remove(device_t &device)
+{
+ m_tagmap.erase(device.m_basetag);
+ m_list.remove(device);
+}
+
+
+//-------------------------------------------------
// register_auto_finder - add a new item to the
// list of stuff to find after we go live
//-------------------------------------------------
diff --git a/src/emu/device.h b/src/emu/device.h
index 794f691e623..774930690b7 100644
--- a/src/emu/device.h
+++ b/src/emu/device.h
@@ -44,8 +44,8 @@
#define DECLARE_READ_LINE_MEMBER(name) int name()
#define READ_LINE_MEMBER(name) int name()
-#define DECLARE_WRITE_LINE_MEMBER(name) void name(ATTR_UNUSED int state)
-#define WRITE_LINE_MEMBER(name) void name(ATTR_UNUSED int state)
+#define DECLARE_WRITE_LINE_MEMBER(name) void name([[maybe_unused]] int state)
+#define WRITE_LINE_MEMBER(name) void name([[maybe_unused]] int state)
@@ -412,18 +412,21 @@ class device_t : public delegate_late_bind
private:
// private helpers
- device_t *find(const std::string &name) const
+ device_t &append(std::unique_ptr<device_t> &&device);
+ device_t &replace_and_remove(std::unique_ptr<device_t> &&device, device_t &existing);
+ void remove(device_t &device);
+ device_t *find(std::string_view name) const
{
- device_t *curdevice;
- for (curdevice = m_list.first(); curdevice != nullptr; curdevice = curdevice->next())
- if (name.compare(curdevice->m_basetag) == 0)
- return curdevice;
- return nullptr;
+ auto result = m_tagmap.find(name);
+ if (result != m_tagmap.end())
+ return &result->second.get();
+ else
+ return nullptr;
}
// private state
simple_list<device_t> m_list; // list of sub-devices we own
- mutable std::unordered_map<std::string,device_t *> m_tagmap; // map of devices looked up and found by subtag
+ std::unordered_map<std::string_view, std::reference_wrapper<device_t>> m_tagmap; // map of devices looked up and found by subtag
};
class interface_list
@@ -566,17 +569,17 @@ public:
const subdevice_list &subdevices() const { return m_subdevices; }
// device-relative tag lookups
- std::string subtag(std::string tag) const;
- std::string siblingtag(std::string tag) const { return (m_owner != nullptr) ? m_owner->subtag(tag) : tag; }
- memory_region *memregion(std::string tag) const;
- memory_share *memshare(std::string tag) const;
- memory_bank *membank(std::string tag) const;
- ioport_port *ioport(std::string tag) const;
- device_t *subdevice(const char *tag) const;
- device_t *siblingdevice(const char *tag) const;
- template<class DeviceClass> DeviceClass *subdevice(const char *tag) const { return downcast<DeviceClass *>(subdevice(tag)); }
- template<class DeviceClass> DeviceClass *siblingdevice(const char *tag) const { return downcast<DeviceClass *>(siblingdevice(tag)); }
- std::string parameter(const char *tag) const;
+ std::string subtag(std::string_view tag) const;
+ std::string siblingtag(std::string_view tag) const { return (m_owner != nullptr) ? m_owner->subtag(tag) : std::string(tag); }
+ memory_region *memregion(std::string_view tag) const;
+ memory_share *memshare(std::string_view tag) const;
+ memory_bank *membank(std::string_view tag) const;
+ ioport_port *ioport(std::string_view tag) const;
+ device_t *subdevice(std::string_view tag) const;
+ device_t *siblingdevice(std::string_view tag) const;
+ template<class DeviceClass> DeviceClass *subdevice(std::string_view tag) const { return downcast<DeviceClass *>(subdevice(tag)); }
+ template<class DeviceClass> DeviceClass *siblingdevice(std::string_view tag) const { return downcast<DeviceClass *>(siblingdevice(tag)); }
+ std::string parameter(std::string_view tag) const;
// configuration helpers
void add_machine_configuration(machine_config &config);
@@ -824,7 +827,7 @@ protected:
private:
// internal helpers
- device_t *subdevice_slow(const char *tag) const;
+ device_t *subdevice_slow(std::string_view tag) const;
void calculate_derived_clock();
// private state; accessor use required
@@ -1336,15 +1339,15 @@ private:
// name relative to this device
//-------------------------------------------------
-inline device_t *device_t::subdevice(const char *tag) const
+inline device_t *device_t::subdevice(std::string_view tag) const
{
- // empty string or nullptr means this device
- if (tag == nullptr || *tag == 0)
+ // empty string means this device (DEVICE_SELF)
+ if (tag.empty())
return const_cast<device_t *>(this);
// do a quick lookup and return that if possible
auto quick = m_subdevices.m_tagmap.find(tag);
- return (quick != m_subdevices.m_tagmap.end()) ? quick->second : subdevice_slow(tag);
+ return (quick != m_subdevices.m_tagmap.end()) ? &quick->second.get() : subdevice_slow(tag);
}
@@ -1353,21 +1356,21 @@ inline device_t *device_t::subdevice(const char *tag) const
// by name relative to this device's parent
//-------------------------------------------------
-inline device_t *device_t::siblingdevice(const char *tag) const
+inline device_t *device_t::siblingdevice(std::string_view tag) const
{
- // empty string or nullptr means this device
- if (tag == nullptr || *tag == 0)
+ // empty string means this device (DEVICE_SELF)
+ if (tag.empty())
return const_cast<device_t *>(this);
// leading caret implies the owner, just skip it
- if (tag[0] == '^') tag++;
+ if (tag[0] == '^') tag.remove_prefix(1);
// query relative to the parent, if we have one
if (m_owner != nullptr)
return m_owner->subdevice(tag);
// otherwise, it's nullptr unless the tag is absolute
- return (tag[0] == ':') ? subdevice(tag) : nullptr;
+ return (!tag.empty() && tag[0] == ':') ? subdevice(tag) : nullptr;
}
diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp
index 4a61fcdecc3..0fbee95dce8 100644
--- a/src/emu/diimage.cpp
+++ b/src/emu/diimage.cpp
@@ -10,8 +10,8 @@
#include "emu.h"
+#include "corestr.h"
#include "emuopts.h"
-#include "drivenum.h"
#include "romload.h"
#include "ui/uimain.h"
#include "zippath.h"
@@ -19,6 +19,8 @@
#include "softlist_dev.h"
#include "formats/ioprocs.h"
+#include <algorithm>
+#include <cctype>
#include <cstring>
#include <regex>
@@ -184,10 +186,10 @@ iodevice_t device_image_interface::device_typeid(const char *name)
// an image
//-------------------------------------------------
-void device_image_interface::set_image_filename(const std::string &filename)
+void device_image_interface::set_image_filename(std::string_view filename)
{
m_image_name = filename;
- util::zippath_parent(m_working_directory, filename);
+ m_working_directory = util::zippath_parent(m_image_name);
m_basename.assign(m_image_name);
// find the last "path separator"
@@ -208,6 +210,17 @@ void device_image_interface::set_image_filename(const std::string &filename)
}
+//-------------------------------------------------
+// is_filetype - check if the filetype matches
+//-------------------------------------------------
+
+bool device_image_interface::is_filetype(std::string_view candidate_filetype) const
+{
+ return std::equal(m_filetype.begin(), m_filetype.end(), candidate_filetype.begin(), candidate_filetype.end(),
+ [] (unsigned char c1, unsigned char c2) { return std::tolower(c1) == c2; });
+}
+
+
/****************************************************************************
CREATION FORMATS
****************************************************************************/
@@ -273,7 +286,7 @@ void device_image_interface::clear_error()
// error
//-------------------------------------------------
-static const char *const messages[] =
+static std::string_view messages[] =
{
"",
"Internal error",
@@ -285,9 +298,9 @@ static const char *const messages[] =
"Unspecified error"
};
-const char *device_image_interface::error()
+std::string_view device_image_interface::error()
{
- return (!m_err_message.empty()) ? m_err_message.c_str() : messages[m_err];
+ return (!m_err_message.empty()) ? m_err_message : messages[m_err];
}
@@ -330,102 +343,6 @@ void device_image_interface::message(const char *format, ...)
}
-/***************************************************************************
- WORKING DIRECTORIES
-***************************************************************************/
-
-//-------------------------------------------------
-// try_change_working_directory - tries to change
-// the working directory, but only if the directory
-// actually exists
-//-------------------------------------------------
-
-bool device_image_interface::try_change_working_directory(const std::string &subdir)
-{
- const osd::directory::entry *entry;
- bool success = false;
- bool done = false;
-
- auto directory = osd::directory::open(m_working_directory);
- if (directory)
- {
- while (!done && (entry = directory->read()) != nullptr)
- {
- if (!core_stricmp(subdir.c_str(), entry->name))
- {
- done = true;
- success = entry->type == osd::directory::entry::entry_type::DIR;
- }
- }
-
- directory.reset();
- }
-
- // did we successfully identify the directory?
- if (success)
- m_working_directory = util::zippath_combine(m_working_directory, subdir);
-
- return success;
-}
-
-
-//-------------------------------------------------
-// setup_working_directory - sets up the working
-// directory according to a few defaults
-//-------------------------------------------------
-
-void device_image_interface::setup_working_directory()
-{
- bool success = false;
- // get user-specified directory and make sure it exists
- m_working_directory = device().mconfig().options().sw_path();
- // if multipath, get first
- size_t i = m_working_directory.find_first_of(';');
- if (i != std::string::npos)
- m_working_directory.resize(i);
- // validate directory
- if (!m_working_directory.empty())
- if (osd::directory::open(m_working_directory))
- success = true;
-
- // if not exist, use previous method
- if (!success)
- {
- // first set up the working directory to be the starting directory
- osd_get_full_path(m_working_directory, ".");
- // now try browsing down to "software"
- if (try_change_working_directory("software"))
- success = true;
- }
-
- if (success)
- {
- // now down to a directory for this computer
- int gamedrv = driver_list::find(device().machine().system());
- while(gamedrv != -1 && !try_change_working_directory(driver_list::driver(gamedrv).name))
- {
- gamedrv = driver_list::compatible_with(gamedrv);
- }
- }
-}
-
-
-//-------------------------------------------------
-// working_directory - returns the working
-// directory to use for this image; this is
-// valid even if not mounted
-//-------------------------------------------------
-
-const std::string &device_image_interface::working_directory()
-{
- // check to see if we've never initialized the working directory
- if (m_working_directory.empty())
- setup_working_directory();
-
- return m_working_directory;
-}
-
-
//-------------------------------------------------
// software_entry - return a pointer to the
// software_info structure from the softlist
@@ -722,16 +639,6 @@ bool device_image_interface::uses_file_extension(const char *file_extension) con
// ***************************************************************************
//-------------------------------------------------
-// is_loaded - quick check to determine whether an
-// image is loaded
-//-------------------------------------------------
-
-bool device_image_interface::is_loaded()
-{
- return (m_file != nullptr);
-}
-
-//-------------------------------------------------
// image_error_from_file_error - converts an image
// error to a file error
//-------------------------------------------------
@@ -771,7 +678,7 @@ image_error_t device_image_interface::image_error_from_file_error(osd_file::erro
// specific path
//-------------------------------------------------
-image_error_t device_image_interface::load_image_by_path(u32 open_flags, const std::string &path)
+image_error_t device_image_interface::load_image_by_path(u32 open_flags, std::string_view path)
{
std::string revised_path;
@@ -791,7 +698,7 @@ image_error_t device_image_interface::load_image_by_path(u32 open_flags, const s
// reopen_for_write
//-------------------------------------------------
-int device_image_interface::reopen_for_write(const std::string &path)
+int device_image_interface::reopen_for_write(std::string_view path)
{
m_file.reset();
@@ -839,7 +746,7 @@ std::vector<u32> device_image_interface::determine_open_plan(bool is_create)
// and hash signatures of a file
//-------------------------------------------------
-static int verify_length_and_hash(emu_file *file, const char *name, u32 explength, const util::hash_collection &hashes)
+static int verify_length_and_hash(emu_file *file, std::string_view name, u32 explength, const util::hash_collection &hashes)
{
int retval = 0;
if (!file)
@@ -853,7 +760,7 @@ static int verify_length_and_hash(emu_file *file, const char *name, u32 explengt
retval++;
}
- util::hash_collection &acthashes = file->hashes(hashes.hash_types().c_str());
+ util::hash_collection &acthashes = file->hashes(hashes.hash_types());
if (hashes.flag(util::hash_collection::FLAG_NO_DUMP))
{
// If there is no good dump known, write it
@@ -880,7 +787,7 @@ static int verify_length_and_hash(emu_file *file, const char *name, u32 explengt
// load_software - software image loading
//-------------------------------------------------
-bool device_image_interface::load_software(software_list_device &swlist, const char *swname, const rom_entry *start)
+bool device_image_interface::load_software(software_list_device &swlist, std::string_view swname, const rom_entry *start)
{
bool retval = false;
int warningcount = 0;
@@ -892,7 +799,7 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
// handle files
if (ROMENTRY_ISFILE(romp))
{
- const software_info *const swinfo = swlist.find(swname);
+ const software_info *const swinfo = swlist.find(std::string(swname));
if (!swinfo)
return false;
@@ -903,7 +810,7 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
osd_printf_error("WARNING: support for software %s (in list %s) is only preliminary\n", swname, swlist.list_name());
u32 crc = 0;
- const bool has_crc = util::hash_collection(ROM_GETHASHDATA(romp)).crc(crc);
+ const bool has_crc = util::hash_collection(romp->hashdata()).crc(crc);
std::vector<const software_info *> parents;
std::vector<std::string> searchpath = rom_load_manager::get_software_searchpath(swlist, *swinfo);
@@ -921,13 +828,13 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
m_mame_file->set_restrict_to_mediapath(1);
osd_file::error filerr;
if (has_crc)
- filerr = m_mame_file->open(ROM_GETNAME(romp), crc);
+ filerr = m_mame_file->open(romp->name(), crc);
else
- filerr = m_mame_file->open(ROM_GETNAME(romp));
+ filerr = m_mame_file->open(romp->name());
if (filerr != osd_file::error::NONE)
m_mame_file.reset();
- warningcount += verify_length_and_hash(m_mame_file.get(), ROM_GETNAME(romp), ROM_GETLENGTH(romp), util::hash_collection(ROM_GETHASHDATA(romp)));
+ warningcount += verify_length_and_hash(m_mame_file.get(), romp->name(), romp->get_length(), util::hash_collection(romp->hashdata()));
if (filerr == osd_file::error::NONE)
filerr = util::core_file::open_proxy(*m_mame_file, m_file);
@@ -950,7 +857,7 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
// load_internal - core image loading
//-------------------------------------------------
-image_init_result device_image_interface::load_internal(const std::string &path, bool is_create, int create_format, util::option_resolution *create_args)
+image_init_result device_image_interface::load_internal(std::string_view path, bool is_create, int create_format, util::option_resolution *create_args)
{
// first unload the image
unload();
@@ -979,7 +886,7 @@ image_init_result device_image_interface::load_internal(const std::string &path,
}
// did we fail to find the file?
- if (!is_loaded())
+ if (!m_file)
{
m_err = IMAGE_ERROR_FILENOTFOUND;
goto done;
@@ -1016,7 +923,7 @@ done:
// load - load an image into MAME
//-------------------------------------------------
-image_init_result device_image_interface::load(const std::string &path)
+image_init_result device_image_interface::load(std::string_view path)
{
// is this a reset on load item?
if (is_reset_on_load() && !init_phase())
@@ -1033,7 +940,7 @@ image_init_result device_image_interface::load(const std::string &path)
// load_software - loads a softlist item by name
//-------------------------------------------------
-image_init_result device_image_interface::load_software(const std::string &software_identifier)
+image_init_result device_image_interface::load_software(std::string_view software_identifier)
{
// Is this a software part that forces a reset and we're at runtime? If so, get this loaded through reset_and_load
if (is_reset_on_load() && !init_phase())
@@ -1063,7 +970,7 @@ image_init_result device_image_interface::load_software(const std::string &softw
m_basename = m_full_software_name;
m_basename_noext = m_full_software_name;
m_filetype = use_software_list_file_extension_for_filetype() && m_mame_file != nullptr
- ? core_filename_extract_extension(m_mame_file->filename(), true)
+ ? std::string(core_filename_extract_extension(m_mame_file->filename(), true))
: "";
// Copy some image information when we have been loaded through a software list
@@ -1138,7 +1045,7 @@ image_init_result device_image_interface::finish_load()
// create - create a image
//-------------------------------------------------
-image_init_result device_image_interface::create(const std::string &path)
+image_init_result device_image_interface::create(std::string_view path)
{
return create(path, nullptr, nullptr);
}
@@ -1148,7 +1055,7 @@ image_init_result device_image_interface::create(const std::string &path)
// create - create a image
//-------------------------------------------------
-image_init_result device_image_interface::create(const std::string &path, const image_device_format *create_format, util::option_resolution *create_args)
+image_init_result device_image_interface::create(std::string_view path, const image_device_format *create_format, util::option_resolution *create_args)
{
int format_index = 0;
int cnt = 0;
@@ -1170,7 +1077,7 @@ image_init_result device_image_interface::create(const std::string &path, const
// the emulation and record this image to be loaded
//-------------------------------------------------
-void device_image_interface::reset_and_load(const std::string &path)
+void device_image_interface::reset_and_load(std::string_view path)
{
// first make sure the reset is scheduled
device().machine().schedule_hard_reset();
@@ -1283,7 +1190,7 @@ void device_image_interface::update_names()
// find_software_item
//-------------------------------------------------
-const software_part *device_image_interface::find_software_item(const std::string &identifier, bool restrict_to_interface, software_list_device **dev) const
+const software_part *device_image_interface::find_software_item(std::string_view identifier, bool restrict_to_interface, software_list_device **dev) const
{
// split full software name into software list name and short software name
std::string list_name, software_name, part_name;
@@ -1363,7 +1270,7 @@ const software_list_loader &device_image_interface::get_software_list_loader() c
// sw_info and sw_part are also set.
//-------------------------------------------------
-bool device_image_interface::load_software_part(const std::string &identifier)
+bool device_image_interface::load_software_part(std::string_view identifier)
{
// if no match has been found, we suggest similar shortnames
software_list_device *swlist;
@@ -1375,7 +1282,7 @@ bool device_image_interface::load_software_part(const std::string &identifier)
}
// Load the software part
- const char *swname = m_software_part_ptr->info().shortname().c_str();
+ const std::string &swname = m_software_part_ptr->info().shortname();
const rom_entry *start_entry = m_software_part_ptr->romdata().data();
const software_list_loader &loader = get_software_list_loader();
bool result = loader.load_software(*this, *swlist, swname, start_entry);
@@ -1416,7 +1323,7 @@ bool device_image_interface::load_software_part(const std::string &identifier)
// software_get_default_slot
//-------------------------------------------------
-std::string device_image_interface::software_get_default_slot(const char *default_card_slot) const
+std::string device_image_interface::software_get_default_slot(std::string_view default_card_slot) const
{
std::string result;
diff --git a/src/emu/diimage.h b/src/emu/diimage.h
index e9292f2f472..507fd34e1d3 100644
--- a/src/emu/diimage.h
+++ b/src/emu/diimage.h
@@ -149,7 +149,7 @@ public:
const image_device_format *device_get_named_creatable_format(const std::string &format_name) noexcept;
const util::option_guide &device_get_creation_option_guide() const { return create_option_guide(); }
- const char *error();
+ std::string_view error();
void seterror(image_error_t err, const char *message);
void message(const char *format, ...) ATTR_PRINTF(2,3);
@@ -158,7 +158,7 @@ public:
const char *basename() const noexcept { return m_basename.empty() ? nullptr : m_basename.c_str(); }
const char *basename_noext() const noexcept { return m_basename_noext.empty() ? nullptr : m_basename_noext.c_str(); }
const std::string &filetype() const noexcept { return m_filetype; }
- bool is_filetype(const std::string &candidate_filetype) { return !core_stricmp(filetype().c_str(), candidate_filetype.c_str()); }
+ bool is_filetype(std::string_view candidate_filetype) const;
bool is_open() const noexcept { return bool(m_file); }
util::core_file &image_core_file() const noexcept { return *m_file; }
u64 length() { check_for_file(); return m_file->size(); }
@@ -180,8 +180,10 @@ public:
const char *software_list_name() const noexcept { return m_software_list_name.c_str(); }
bool loaded_through_softlist() const noexcept { return m_software_part_ptr != nullptr; }
+ void set_working_directory(std::string_view working_directory) { m_working_directory = working_directory; }
void set_working_directory(const char *working_directory) { m_working_directory = working_directory; }
- const std::string &working_directory();
+ void set_working_directory(std::string &&working_directory) { m_working_directory = std::move(working_directory); }
+ const std::string &working_directory() const { return m_working_directory; }
u8 *get_software_region(const char *tag);
u32 get_software_region_length(const char *tag);
@@ -205,17 +207,17 @@ public:
const formatlist_type &formatlist() const { return m_formatlist; }
// loads an image file
- image_init_result load(const std::string &path);
+ image_init_result load(std::string_view path);
// loads a softlist item by name
- image_init_result load_software(const std::string &software_identifier);
+ image_init_result load_software(std::string_view software_identifier);
image_init_result finish_load();
void unload();
- image_init_result create(const std::string &path, const image_device_format *create_format, util::option_resolution *create_args);
- image_init_result create(const std::string &path);
- bool load_software(software_list_device &swlist, const char *swname, const rom_entry *entry);
- int reopen_for_write(const std::string &path);
+ image_init_result create(std::string_view path, const image_device_format *create_format, util::option_resolution *create_args);
+ image_init_result create(std::string_view path);
+ bool load_software(software_list_device &swlist, std::string_view swname, const rom_entry *entry);
+ int reopen_for_write(std::string_view path);
void set_user_loadable(bool user_loadable) { m_user_loadable = user_loadable; }
@@ -230,26 +232,23 @@ protected:
virtual const software_list_loader &get_software_list_loader() const;
virtual const bool use_software_list_file_extension_for_filetype() const { return false; }
- image_init_result load_internal(const std::string &path, bool is_create, int create_format, util::option_resolution *create_args);
- image_error_t load_image_by_path(u32 open_flags, const std::string &path);
+ image_init_result load_internal(std::string_view path, bool is_create, int create_format, util::option_resolution *create_args);
+ image_error_t load_image_by_path(u32 open_flags, std::string_view path);
void clear();
- bool is_loaded();
+ bool is_loaded() const { return m_file != nullptr; }
- void set_image_filename(const std::string &filename);
+ void set_image_filename(std::string_view filename);
void clear_error();
void check_for_file() const { if (!m_file) throw emu_fatalerror("%s(%s): Illegal operation on unmounted image", device().shortname(), device().tag()); }
- void setup_working_directory();
- bool try_change_working_directory(const std::string &subdir);
-
void make_readonly() noexcept { m_readonly = true; }
bool image_checkhash();
- const software_part *find_software_item(const std::string &identifier, bool restrict_to_interface, software_list_device **device = nullptr) const;
- std::string software_get_default_slot(const char *default_card_slot) const;
+ const software_part *find_software_item(std::string_view identifier, bool restrict_to_interface, software_list_device **device = nullptr) const;
+ std::string software_get_default_slot(std::string_view default_card_slot) const;
void add_format(std::unique_ptr<image_device_format> &&format);
void add_format(std::string &&name, std::string &&description, std::string &&extensions, std::string &&optspec);
@@ -281,14 +280,14 @@ private:
static image_error_t image_error_from_file_error(osd_file::error filerr);
std::vector<u32> determine_open_plan(bool is_create);
void update_names();
- bool load_software_part(const std::string &identifier);
+ bool load_software_part(std::string_view identifier);
bool init_phase() const;
static bool run_hash(util::core_file &file, u32 skip_bytes, util::hash_collection &hashes, const char *types);
// loads an image or software items and resets - called internally when we
// load an is_reset_on_load() item
- void reset_and_load(const std::string &path);
+ void reset_and_load(std::string_view path);
// creation info
formatlist_type m_formatlist;
diff --git a/src/emu/dislot.cpp b/src/emu/dislot.cpp
index 9e8a5128996..e30cd41d46f 100644
--- a/src/emu/dislot.cpp
+++ b/src/emu/dislot.cpp
@@ -9,6 +9,8 @@
#include "emu.h"
#include "emuopts.h"
#include "zippath.h"
+#include <algorithm>
+#include <cctype>
device_slot_interface::device_slot_interface(const machine_config &mconfig, device_t &device) :
@@ -129,3 +131,9 @@ bool get_default_card_software_hook::hashfile_extrainfo(std::string &extrainfo)
extrainfo = m_hash_extrainfo;
return m_has_hash_extrainfo;
}
+
+bool get_default_card_software_hook::is_filetype(std::string_view candidate_filetype) const
+{
+ return std::equal(m_file_type.begin(), m_file_type.end(), candidate_filetype.begin(), candidate_filetype.end(),
+ [] (unsigned char c1, unsigned char c2) { return std::tolower(c1) == c2; });
+}
diff --git a/src/emu/dislot.h b/src/emu/dislot.h
index ae9d8ec4575..97d314028a2 100644
--- a/src/emu/dislot.h
+++ b/src/emu/dislot.h
@@ -24,7 +24,7 @@ public:
util::core_file::ptr &image_file() { return m_image_file; }
// checks to see if image is of the specified "file type" (in practice, file extension)
- bool is_filetype(const char *candidate_filetype) const { return !core_stricmp(m_file_type.c_str(), candidate_filetype); }
+ bool is_filetype(std::string_view candidate_filetype) const;
// extra info from hashfile
bool hashfile_extrainfo(std::string &extrainfo);
diff --git a/src/emu/disound.cpp b/src/emu/disound.cpp
index abd5e4f4e12..83d2c2bf084 100644
--- a/src/emu/disound.cpp
+++ b/src/emu/disound.cpp
@@ -267,7 +267,7 @@ void device_sound_interface::interface_validity_check(validity_checker &valid) c
for (sound_route const &route : routes())
{
// find a device with the requested tag
- device_t const *const target = route.m_base.get().subdevice(route.m_target.c_str());
+ device_t const *const target = route.m_base.get().subdevice(route.m_target);
if (!target)
osd_printf_error("Attempting to route sound to non-existent device '%s'\n", route.m_base.get().subtag(route.m_target));
@@ -293,7 +293,7 @@ void device_sound_interface::interface_pre_start()
// scan each route on the device
for (sound_route const &route : sound.routes())
{
- device_t *const target_device = route.m_base.get().subdevice(route.m_target.c_str());
+ device_t *const target_device = route.m_base.get().subdevice(route.m_target);
if (target_device == &device())
{
// see if we are the target of this route; if we are, make sure the source device is started
@@ -313,7 +313,7 @@ void device_sound_interface::interface_pre_start()
for (sound_route &route : sound.routes())
{
// see if we are the target of this route
- device_t *const target_device = route.m_base.get().subdevice(route.m_target.c_str());
+ device_t *const target_device = route.m_base.get().subdevice(route.m_target);
if (target_device == &device() && route.m_input == AUTO_ALLOC_INPUT)
{
route.m_input = m_auto_allocated_inputs;
@@ -338,7 +338,7 @@ void device_sound_interface::interface_post_start()
for (sound_route const &route : sound.routes())
{
// if we are the target of this route, hook it up
- device_t *const target_device = route.m_base.get().subdevice(route.m_target.c_str());
+ device_t *const target_device = route.m_base.get().subdevice(route.m_target);
if (target_device == &device())
{
// iterate over all outputs, matching any that apply
@@ -445,7 +445,7 @@ void device_mixer_interface::interface_pre_start()
for (sound_route const &route : sound.routes())
{
// see if we are the target of this route
- device_t *const target_device = route.m_base.get().subdevice(route.m_target.c_str());
+ device_t *const target_device = route.m_base.get().subdevice(route.m_target);
if (target_device == &device() && route.m_input < m_auto_allocated_inputs)
{
int const count = (route.m_output == ALL_OUTPUTS) ? sound.outputs() : 1;
diff --git a/src/emu/drivenum.cpp b/src/emu/drivenum.cpp
index 52ac8c54fef..3db8a3334d5 100644
--- a/src/emu/drivenum.cpp
+++ b/src/emu/drivenum.cpp
@@ -10,6 +10,8 @@
#include "emu.h"
#include "drivenum.h"
+
+#include "corestr.h"
#include "softlist_dev.h"
#include "unicode.h"
diff --git a/src/emu/emu.h b/src/emu/emu.h
index 9b67c78403d..a3f4a3869a3 100644
--- a/src/emu/emu.h
+++ b/src/emu/emu.h
@@ -38,7 +38,6 @@
#include "http.h"
// commonly-referenced utilities imported from lib/util
-#include "corestr.h"
#include "palette.h"
// emulator-specific utilities
diff --git a/src/emu/emuopts.cpp b/src/emu/emuopts.cpp
index 6c4ec9d2655..eda6df9b6b6 100644
--- a/src/emu/emuopts.cpp
+++ b/src/emu/emuopts.cpp
@@ -14,6 +14,8 @@
#include "softlist_dev.h"
#include "hashfile.h"
+#include "corestr.h"
+
#include <stack>
@@ -488,7 +490,7 @@ void emu_options::set_system_name(std::string &&new_system_name)
{
// if so, first extract the base name (the reason for this is drag-and-drop on Windows; a side
// effect is a command line like 'mame pacman.foo' will work correctly, but so be it)
- std::string new_system_base_name = core_filename_extract_base(m_attempted_system_name, true);
+ std::string new_system_base_name(core_filename_extract_base(m_attempted_system_name, true));
// perform the lookup (and error if it cannot be found)
int index = driver_list::find(new_system_base_name.c_str());
@@ -510,17 +512,6 @@ void emu_options::set_system_name(std::string &&new_system_name)
//-------------------------------------------------
-// set_system_name - called to set the system
-// name; will adjust slot/image options as appropriate
-//-------------------------------------------------
-
-void emu_options::set_system_name(const std::string &new_system_name)
-{
- set_system_name(std::string(new_system_name));
-}
-
-
-//-------------------------------------------------
// update_slot_and_image_options
//-------------------------------------------------
@@ -1139,7 +1130,7 @@ void slot_option::specify(std::string &&text, bool peg_priority)
// we need to do some elementary parsing here
const char *bios_arg = ",bios=";
- const size_t pos = text.find(bios_arg);
+ const std::string::size_type pos = text.find(bios_arg);
if (pos != std::string::npos)
{
m_specified = true;
@@ -1164,9 +1155,31 @@ void slot_option::specify(std::string &&text, bool peg_priority)
// slot_option::specify
//-------------------------------------------------
-void slot_option::specify(const std::string &text, bool peg_priority)
+void slot_option::specify(std::string_view text, bool peg_priority)
{
- specify(std::string(text), peg_priority);
+ // record the old value; we may need to trigger an update
+ const std::string old_value = value();
+
+ // we need to do some elementary parsing here
+ const char *bios_arg = ",bios=";
+ const std::string_view::size_type pos = text.find(bios_arg);
+ if (pos != std::string_view::npos)
+ {
+ m_specified = true;
+ m_specified_value = text.substr(0, pos);
+ m_specified_bios = text.substr(pos + strlen(bios_arg));
+ }
+ else
+ {
+ m_specified = true;
+ m_specified_value = text;
+ m_specified_bios = "";
+ }
+
+ conditionally_peg_priority(m_entry, peg_priority);
+
+ // we may have changed
+ possibly_changed(old_value);
}
@@ -1248,7 +1261,7 @@ image_option::image_option(emu_options &host, const std::string &canonical_insta
// image_option::specify
//-------------------------------------------------
-void image_option::specify(const std::string &value, bool peg_priority)
+void image_option::specify(std::string_view value, bool peg_priority)
{
if (value != m_value)
{
diff --git a/src/emu/emuopts.h b/src/emu/emuopts.h
index bb989016cf3..6ad1d70bcf4 100644
--- a/src/emu/emuopts.h
+++ b/src/emu/emuopts.h
@@ -220,8 +220,9 @@ public:
core_options::entry::shared_ptr option_entry() const { return m_entry.lock(); }
// seters
- void specify(const std::string &text, bool peg_priority = true);
+ void specify(std::string_view text, bool peg_priority = true);
void specify(std::string &&text, bool peg_priority = true);
+ void specify(const char *text, bool peg_priority = true) { specify(std::string_view(text), peg_priority); }
void set_bios(std::string &&text);
void set_default_card_software(std::string &&s);
@@ -254,8 +255,9 @@ public:
core_options::entry::shared_ptr option_entry() const { return m_entry.lock(); }
// mutators
- void specify(const std::string &value, bool peg_priority = true);
+ void specify(std::string_view value, bool peg_priority = true);
void specify(std::string &&value, bool peg_priority = true);
+ void specify(const char *value, bool peg_priority = true) { specify(std::string_view(value), peg_priority); }
// instantiates an option entry (don't call outside of emuopts.cpp)
core_options::entry::shared_ptr setup_option_entry(std::vector<std::string> &&names);
@@ -291,7 +293,8 @@ public:
~emu_options();
// mutation
- void set_system_name(const std::string &new_system_name);
+ void set_system_name(const char *new_system_name) { set_system_name(std::string(new_system_name)); }
+ void set_system_name(std::string_view new_system_name) { set_system_name(std::string(new_system_name)); }
void set_system_name(std::string &&new_system_name);
void set_software(std::string &&new_software);
diff --git a/src/emu/fileio.cpp b/src/emu/fileio.cpp
index 6149e65a048..a1c983da39f 100644
--- a/src/emu/fileio.cpp
+++ b/src/emu/fileio.cpp
@@ -135,7 +135,7 @@ bool path_iterator::next(std::string &buffer, const char *name)
//-------------------------------------------------
-// path_iteratr::reset - let's go again
+// path_iterator::reset - let's go again
//-------------------------------------------------
void path_iterator::reset()
@@ -255,16 +255,16 @@ emu_file::operator util::core_file &()
// hash - returns the hash for a file
//-------------------------------------------------
-util::hash_collection &emu_file::hashes(const char *types)
+util::hash_collection &emu_file::hashes(std::string_view types)
{
// determine the hashes we already have
std::string already_have = m_hashes.hash_types();
// determine which hashes we need
std::string needed;
- for (const char *scan = types; *scan != 0; scan++)
- if (already_have.find_first_of(*scan) == -1)
- needed.push_back(*scan);
+ for (char scan : types)
+ if (already_have.find_first_of(scan) == -1)
+ needed.push_back(scan);
// if we need nothing, skip it
if (needed.empty())
@@ -298,10 +298,10 @@ util::hash_collection &emu_file::hashes(const char *types)
// open - open a file by searching paths
//-------------------------------------------------
-osd_file::error emu_file::open(const std::string &name)
+osd_file::error emu_file::open(std::string &&name)
{
// remember the filename and CRC info
- m_filename = name;
+ m_filename = std::move(name);
m_crc = 0;
m_openflags &= ~OPEN_FLAG_HAS_CRC;
@@ -310,10 +310,10 @@ osd_file::error emu_file::open(const std::string &name)
return open_next();
}
-osd_file::error emu_file::open(const std::string &name, u32 crc)
+osd_file::error emu_file::open(std::string &&name, u32 crc)
{
// remember the filename and CRC info
- m_filename = name;
+ m_filename = std::move(name);
m_crc = crc;
m_openflags |= OPEN_FLAG_HAS_CRC;
diff --git a/src/emu/fileio.h b/src/emu/fileio.h
index aaa1b564b12..4b4c823f8d3 100644
--- a/src/emu/fileio.h
+++ b/src/emu/fileio.h
@@ -148,7 +148,7 @@ public:
const char *filename() const { return m_filename.c_str(); }
const char *fullpath() const { return m_fullpath.c_str(); }
u32 openflags() const { return m_openflags; }
- util::hash_collection &hashes(const char *types);
+ util::hash_collection &hashes(std::string_view types);
// setters
void remove_on_close() { m_remove_on_close = true; }
@@ -156,8 +156,12 @@ public:
void set_restrict_to_mediapath(int rtmp) { m_restrict_to_mediapath = rtmp; }
// open/close
- osd_file::error open(const std::string &name);
- osd_file::error open(const std::string &name, u32 crc);
+ osd_file::error open(std::string &&name);
+ osd_file::error open(std::string &&name, u32 crc);
+ osd_file::error open(std::string_view name) { return open(std::string(name)); }
+ osd_file::error open(std::string_view name, u32 crc) { return open(std::string(name), crc); }
+ osd_file::error open(const char *name) { return open(std::string(name)); }
+ osd_file::error open(const char *name, u32 crc) { return open(std::string(name), crc); }
osd_file::error open_next();
osd_file::error open_ram(const void *data, u32 length);
void close();
diff --git a/src/emu/image.cpp b/src/emu/image.cpp
index 28a704354f0..4b9302fa9d3 100644
--- a/src/emu/image.cpp
+++ b/src/emu/image.cpp
@@ -8,15 +8,20 @@
***************************************************************************/
-#include <cctype>
-
#include "emu.h"
-#include "emuopts.h"
#include "image.h"
+
#include "config.h"
-#include "xmlfile.h"
+#include "drivenum.h"
+#include "emuopts.h"
#include "softlist.h"
+#include "corestr.h"
+#include "xmlfile.h"
+#include "zippath.h"
+
+#include <cctype>
+
//**************************************************************************
// IMAGE MANAGER
@@ -251,3 +256,85 @@ void image_manager::postdevice_init()
/* add a callback for when we shut down */
machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(&image_manager::unload_all, this));
}
+
+
+//**************************************************************************
+// WORKING DIRECTORIES
+//**************************************************************************
+
+//-------------------------------------------------
+// try_change_working_directory - tries to change
+// the working directory, but only if the directory
+// actually exists
+//-------------------------------------------------
+
+bool image_manager::try_change_working_directory(std::string &working_directory, const std::string &subdir)
+{
+ const osd::directory::entry *entry;
+ bool success = false;
+ bool done = false;
+
+ auto directory = osd::directory::open(working_directory);
+ if (directory)
+ {
+ while (!done && (entry = directory->read()) != nullptr)
+ {
+ if (!core_stricmp(subdir.c_str(), entry->name))
+ {
+ done = true;
+ success = entry->type == osd::directory::entry::entry_type::DIR;
+ }
+ }
+
+ directory.reset();
+ }
+
+ // did we successfully identify the directory?
+ if (success)
+ working_directory = util::zippath_combine(working_directory, subdir);
+
+ return success;
+}
+
+
+//-------------------------------------------------
+// setup_working_directory - sets up the working
+// directory according to a few defaults
+//-------------------------------------------------
+
+std::string image_manager::setup_working_directory()
+{
+ bool success = false;
+ // get user-specified directory and make sure it exists
+ std::string working_directory = machine().options().sw_path();
+ // if multipath, get first
+ size_t i = working_directory.find_first_of(';');
+ if (i != std::string::npos)
+ working_directory.resize(i);
+ // validate directory
+ if (!working_directory.empty())
+ if (osd::directory::open(working_directory))
+ success = true;
+
+ // if not exist, use previous method
+ if (!success)
+ {
+ // first set up the working directory to be the starting directory
+ osd_get_full_path(working_directory, ".");
+ // now try browsing down to "software"
+ if (try_change_working_directory(working_directory, "software"))
+ success = true;
+ }
+
+ if (success)
+ {
+ // now down to a directory for this computer
+ int gamedrv = driver_list::find(machine().system());
+ while(gamedrv != -1 && !try_change_working_directory(working_directory, driver_list::driver(gamedrv).name))
+ {
+ gamedrv = driver_list::compatible_with(gamedrv);
+ }
+ }
+
+ return working_directory;
+}
diff --git a/src/emu/image.h b/src/emu/image.h
index b0cc5f60852..c7ad11eea66 100644
--- a/src/emu/image.h
+++ b/src/emu/image.h
@@ -26,6 +26,9 @@ public:
// getters
running_machine &machine() const { return m_machine; }
+
+ std::string setup_working_directory();
+
private:
void config_load(config_type cfg_type, util::xml::data_node const *parentnode);
void config_save(config_type cfg_type, util::xml::data_node *parentnode);
@@ -33,6 +36,8 @@ private:
void options_extract();
int write_config(emu_options &options, const char *filename, const game_driver *gamedrv);
+ bool try_change_working_directory(std::string &working_directory, const std::string &subdir);;
+
// internal state
running_machine & m_machine; // reference to our machine
};
diff --git a/src/emu/input.cpp b/src/emu/input.cpp
index ffcdaf722be..0cc37abc1c9 100644
--- a/src/emu/input.cpp
+++ b/src/emu/input.cpp
@@ -20,6 +20,8 @@
#include "emu.h"
#include "inputdev.h"
+#include "corestr.h"
+
//**************************************************************************
@@ -46,10 +48,10 @@ const input_seq input_seq::empty_seq;
// simple class to match codes to strings
struct code_string_table
{
- u32 operator[](const char *string) const
+ u32 operator[](std::string_view string) const
{
for (const code_string_table *current = this; current->m_code != ~0; current++)
- if (strcmp(current->m_string, string) == 0)
+ if (current->m_string == string)
return current->m_code;
return ~0;
}
@@ -818,8 +820,7 @@ std::string input_manager::code_name(input_code code) const
str.append(" ").append(modifier);
// delete any leading spaces
- strtrimspace(str);
- return str;
+ return std::string(strtrimspace(str));
}
@@ -887,7 +888,7 @@ input_code input_manager::code_from_token(const char *_token)
// first token should be the devclass
int curtok = 0;
- input_device_class devclass = input_device_class((*devclass_token_table)[token[curtok++].c_str()]);
+ input_device_class devclass = input_device_class((*devclass_token_table)[token[curtok++]]);
if (devclass == ~input_device_class(0))
return INPUT_CODE_INVALID;
@@ -902,7 +903,7 @@ input_code input_manager::code_from_token(const char *_token)
return INPUT_CODE_INVALID;
// next token is the item ID
- input_item_id itemid = input_item_id((*itemid_token_table)[token[curtok].c_str()]);
+ input_item_id itemid = input_item_id((*itemid_token_table)[token[curtok]]);
bool standard = (itemid != ~input_item_id(0));
// if we're a standard code, default the itemclass based on it
@@ -940,7 +941,7 @@ input_code input_manager::code_from_token(const char *_token)
input_item_modifier modifier = ITEM_MODIFIER_NONE;
if (curtok < numtokens)
{
- modifier = input_item_modifier((*modifier_token_table)[token[curtok].c_str()]);
+ modifier = input_item_modifier((*modifier_token_table)[token[curtok]]);
if (modifier != ~input_item_modifier(0))
curtok++;
else
@@ -950,7 +951,7 @@ input_code input_manager::code_from_token(const char *_token)
// if we have another token, it is the item class
if (curtok < numtokens)
{
- u32 temp = (*itemclass_token_table)[token[curtok].c_str()];
+ u32 temp = (*itemclass_token_table)[token[curtok]];
if (temp != ~0)
{
curtok++;
@@ -1340,7 +1341,7 @@ bool input_manager::map_device_to_controller(const devicemap_table_type *devicem
return false;
// first token should be the devclass
- input_device_class devclass = input_device_class((*devclass_token_table)[strmakeupper(token[0]).c_str()]);
+ input_device_class devclass = input_device_class((*devclass_token_table)[strmakeupper(token[0])]);
if (devclass == ~input_device_class(0))
return false;
diff --git a/src/emu/inputdev.cpp b/src/emu/inputdev.cpp
index 66a0794f6cd..3ca876ff0d8 100644
--- a/src/emu/inputdev.cpp
+++ b/src/emu/inputdev.cpp
@@ -11,6 +11,7 @@
#include "emu.h"
#include "inputdev.h"
+#include "corestr.h"
#include "emuopts.h"
@@ -328,13 +329,10 @@ input_item_id input_device::add_item(const char *name, input_item_id itemid, ite
// substring search
//-------------------------------------------------
-bool input_device::match_device_id(const char *deviceid)
+bool input_device::match_device_id(const char *deviceid) const
{
- std::string deviceidupper(deviceid);
- std::string idupper(m_id);
-
- strmakeupper(deviceidupper);
- strmakeupper(idupper);
+ std::string deviceidupper(strmakeupper(deviceid));
+ std::string idupper(strmakeupper(m_id));
return std::string::npos == idupper.find(deviceidupper) ? false : true;
}
diff --git a/src/emu/inputdev.h b/src/emu/inputdev.h
index 9c9f63c3961..58a3f40dca3 100644
--- a/src/emu/inputdev.h
+++ b/src/emu/inputdev.h
@@ -164,7 +164,7 @@ public:
// helpers
s32 adjust_absolute(s32 value) const { return adjust_absolute_value(value); }
- bool match_device_id(const char *deviceid);
+ bool match_device_id(const char *deviceid) const;
protected:
// specific overrides
diff --git a/src/emu/ioport.cpp b/src/emu/ioport.cpp
index aa9385e883b..9a220b9c12f 100644
--- a/src/emu/ioport.cpp
+++ b/src/emu/ioport.cpp
@@ -99,6 +99,7 @@
#include "inputdev.h"
#include "natkeyboard.h"
+#include "corestr.h"
#include "osdepend.h"
#include "unicode.h"
@@ -1366,7 +1367,7 @@ ioport_field_live::ioport_field_live(ioport_field &field, analog_field *analog)
}
// trim extra spaces
- strtrimspace(name);
+ name = strtrimspace(name);
// special case
if (name.empty())
diff --git a/src/emu/ioport.h b/src/emu/ioport.h
index 8554455b114..fe8ce4a83ab 100644
--- a/src/emu/ioport.h
+++ b/src/emu/ioport.h
@@ -1415,7 +1415,7 @@ private:
void frame_update_callback();
void frame_update();
- ioport_port *port(const char *tag) const { if (tag) { auto search = m_portlist.find(tag); if (search != m_portlist.end()) return search->second.get(); else return nullptr; } else return nullptr; }
+ ioport_port *port(const std::string &tag) const { auto search = m_portlist.find(tag); if (search != m_portlist.end()) return search->second.get(); else return nullptr; }
void exit();
input_seq_type token_to_seq_type(const char *string);
static const char *const seqtypestrings[];
diff --git a/src/emu/machine.cpp b/src/emu/machine.cpp
index a7fdddc5fd2..f17f6c47d49 100644
--- a/src/emu/machine.cpp
+++ b/src/emu/machine.cpp
@@ -86,6 +86,7 @@
#include "tilemap.h"
#include "natkeyboard.h"
#include "ui/uimain.h"
+#include "corestr.h"
#include <ctime>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
diff --git a/src/emu/mconfig.cpp b/src/emu/mconfig.cpp
index c2a09ec8df7..fb97c3138a3 100644
--- a/src/emu/mconfig.cpp
+++ b/src/emu/mconfig.cpp
@@ -143,7 +143,7 @@ device_execute_interface *machine_config::perfect_quantum_device() const
if (!m_perfect_quantum_device.first)
return nullptr;
- device_t *const found(m_perfect_quantum_device.first->subdevice(m_perfect_quantum_device.second.c_str()));
+ device_t *const found(m_perfect_quantum_device.first->subdevice(m_perfect_quantum_device.second));
if (!found)
{
throw emu_fatalerror(
@@ -239,7 +239,7 @@ device_t *machine_config::device_remove(const char *tag)
remove_references(*device);
// let the device's owner do the work
- owner->subdevices().m_list.remove(*device);
+ owner->subdevices().remove(*device);
}
return nullptr;
}
@@ -264,12 +264,11 @@ std::pair<const char *, device_t *> machine_config::resolve_owner(const char *ta
}
// go down the path until we're done with it
- std::string part;
while (strchr(tag, ':'))
{
const char *next = strchr(tag, ':');
assert(next != tag);
- part.assign(tag, next - tag);
+ std::string_view part(tag, next - tag);
owner = owner->subdevices().find(part);
if (!owner)
throw emu_fatalerror("Could not find %s when looking up path for device %s\n", part, orig_tag);
@@ -314,7 +313,7 @@ device_t &machine_config::add_device(std::unique_ptr<device_t> &&device, device_
if (owner)
{
// allocate the new device and append it to the owner's list
- device_t &result(owner->subdevices().m_list.append(*device.release()));
+ device_t &result(owner->subdevices().append(std::move(device)));
result.add_machine_configuration(*this);
return result;
}
@@ -338,8 +337,8 @@ device_t &machine_config::replace_device(std::unique_ptr<device_t> &&device, dev
{
current_device_stack const context(*this);
device_t &result(existing
- ? owner.subdevices().m_list.replace_and_remove(*device.release(), *existing)
- : owner.subdevices().m_list.append(*device.release()));
+ ? owner.subdevices().replace_and_remove(std::move(device), *existing)
+ : owner.subdevices().append(std::move(device)));
result.add_machine_configuration(*this);
return result;
}
@@ -378,10 +377,6 @@ void machine_config::remove_references(device_t &device)
else
++it;
}
-
- // iterate over all devices and remove any references
- for (device_t &scan : device_enumerator(root_device()))
- scan.subdevices().m_tagmap.clear();
}
diff --git a/src/emu/natkeyboard.cpp b/src/emu/natkeyboard.cpp
index d01b64311cf..fd5e2a1be44 100644
--- a/src/emu/natkeyboard.cpp
+++ b/src/emu/natkeyboard.cpp
@@ -10,6 +10,8 @@
#include "emu.h"
#include "natkeyboard.h"
+
+#include "corestr.h"
#include "emuopts.h"
#include "unicode.h"
diff --git a/src/emu/output.cpp b/src/emu/output.cpp
index d374ef1e9a8..3fe5d7629a4 100644
--- a/src/emu/output.cpp
+++ b/src/emu/output.cpp
@@ -59,10 +59,10 @@ void output_manager::output_item::notify(s32 value)
// OUTPUT ITEM PROXY
//**************************************************************************
-void output_manager::item_proxy::resolve(device_t &device, std::string const &name)
+void output_manager::item_proxy::resolve(device_t &device, std::string_view name)
{
assert(!m_item);
- m_item = &device.machine().output().find_or_create_item(name.c_str(), 0);
+ m_item = &device.machine().output().find_or_create_item(name, 0);
}
@@ -118,7 +118,7 @@ void output_manager::register_save()
find_item - find an item based on a string
-------------------------------------------------*/
-output_manager::output_item *output_manager::find_item(char const *string)
+output_manager::output_item *output_manager::find_item(std::string_view string)
{
auto item = m_itemtable.find(std::string(string));
if (item != m_itemtable.end())
@@ -132,7 +132,7 @@ output_manager::output_item *output_manager::find_item(char const *string)
create_new_item - create a new item
-------------------------------------------------*/
-output_manager::output_item &output_manager::create_new_item(char const *outname, s32 value)
+output_manager::output_item &output_manager::create_new_item(std::string_view outname, s32 value)
{
if (OUTPUT_VERBOSE)
osd_printf_verbose("Creating output %s = %d%s\n", outname, value, m_save_data ? " (will not be saved)" : "");
@@ -140,12 +140,12 @@ output_manager::output_item &output_manager::create_new_item(char const *outname
auto const ins(m_itemtable.emplace(
std::piecewise_construct,
std::forward_as_tuple(outname),
- std::forward_as_tuple(*this, outname, m_uniqueid++, value)));
+ std::forward_as_tuple(*this, std::string(outname), m_uniqueid++, value)));
assert(ins.second);
return ins.first->second;
}
-output_manager::output_item &output_manager::find_or_create_item(char const *outname, s32 value)
+output_manager::output_item &output_manager::find_or_create_item(std::string_view outname, s32 value)
{
output_item *const item = find_item(outname);
return item ? *item : create_new_item(outname, value);
@@ -193,7 +193,7 @@ void output_manager::postload()
output_set_value - set the value of an output
-------------------------------------------------*/
-void output_manager::set_value(char const *outname, s32 value)
+void output_manager::set_value(std::string_view outname, s32 value)
{
output_item *const item = find_item(outname);
@@ -210,7 +210,7 @@ void output_manager::set_value(char const *outname, s32 value)
output
-------------------------------------------------*/
-s32 output_manager::get_value(char const *outname)
+s32 output_manager::get_value(std::string_view outname)
{
output_item const *const item = find_item(outname);
@@ -219,24 +219,27 @@ s32 output_manager::get_value(char const *outname)
}
-/*-------------------------------------------------
- output_set_notifier - sets a notifier callback
- for a particular output, or for all outputs
- if nullptr is specified
--------------------------------------------------*/
+//-------------------------------------------------
+// set_notifier - sets a notifier callback for a
+// particular output
+//-------------------------------------------------
-void output_manager::set_notifier(char const *outname, notifier_func callback, void *param)
+void output_manager::set_notifier(std::string_view outname, notifier_func callback, void *param)
{
// if an item is specified, find/create it
- if (outname)
- {
- output_item *const item = find_item(outname);
- (item ? *item : create_new_item(outname, 0)).set_notifier(callback, param);
- }
- else
- {
- m_global_notifylist.emplace_back(callback, param);
- }
+ output_item *const item = find_item(outname);
+ (item ? *item : create_new_item(outname, 0)).set_notifier(callback, param);
+}
+
+
+//-------------------------------------------------
+// set_global_notifier - sets a notifier callback
+// for all outputs
+//-------------------------------------------------
+
+void output_manager::set_global_notifier(notifier_func callback, void *param)
+{
+ m_global_notifylist.emplace_back(callback, param);
}
@@ -245,7 +248,7 @@ void output_manager::set_notifier(char const *outname, notifier_func callback, v
a given name
-------------------------------------------------*/
-u32 output_manager::name_to_id(char const *outname)
+u32 output_manager::name_to_id(std::string_view outname)
{
// if no item, ID is 0
output_item const *const item = find_item(outname);
diff --git a/src/emu/output.h b/src/emu/output.h
index 92e7c6ead5f..3571cc1f24b 100644
--- a/src/emu/output.h
+++ b/src/emu/output.h
@@ -85,7 +85,7 @@ private:
{
public:
item_proxy() = default;
- void resolve(device_t &device, std::string const &name);
+ void resolve(device_t &device, std::string_view name);
operator s32() const { return m_item->get(); }
s32 operator=(s32 value) { m_item->set(value); return m_item->get(); }
private:
@@ -169,13 +169,16 @@ public:
running_machine &machine() const { return m_machine; }
// set the value for a given output
- void set_value(const char *outname, s32 value);
+ void set_value(std::string_view outname, s32 value);
// return the current value for a given output
- s32 get_value(const char *outname);
+ s32 get_value(std::string_view outname);
- // set a notifier on a particular output, or globally if nullptr
- void set_notifier(const char *outname, notifier_func callback, void *param);
+ // set a notifier on a particular output
+ void set_notifier(std::string_view outname, notifier_func callback, void *param);
+
+ // set a notifier globally
+ void set_global_notifier(notifier_func callback, void *param);
// immdediately call a notifier for all outputs
template <typename T> void notify_all(T &&notifier) const
@@ -185,15 +188,15 @@ public:
}
// map a name to a unique ID
- u32 name_to_id(const char *outname);
+ u32 name_to_id(std::string_view outname);
// map a unique ID back to a name
const char *id_to_name(u32 id);
private:
- output_item *find_item(const char *string);
- output_item &create_new_item(const char *outname, s32 value);
- output_item &find_or_create_item(const char *outname, s32 value);
+ output_item *find_item(std::string_view string);
+ output_item &create_new_item(std::string_view outname, s32 value);
+ output_item &find_or_create_item(std::string_view outname, s32 value);
// event handlers
void pause();
diff --git a/src/emu/render.cpp b/src/emu/render.cpp
index b9b98528547..3ef1fb32fec 100644
--- a/src/emu/render.cpp
+++ b/src/emu/render.cpp
@@ -39,6 +39,7 @@
#include "emu.h"
#include "render.h"
+#include "corestr.h"
#include "emuopts.h"
#include "rendfont.h"
#include "rendlay.h"
diff --git a/src/emu/rendfont.cpp b/src/emu/rendfont.cpp
index 36f5b7367a9..8fa59c20257 100644
--- a/src/emu/rendfont.cpp
+++ b/src/emu/rendfont.cpp
@@ -11,6 +11,7 @@
#include "emu.h"
#include "rendfont.h"
#include "emuopts.h"
+#include "corestr.h"
#include "coreutil.h"
#include "osdepend.h"
diff --git a/src/emu/rendlay.cpp b/src/emu/rendlay.cpp
index ec2cec7c336..e7ba920af84 100644
--- a/src/emu/rendlay.cpp
+++ b/src/emu/rendlay.cpp
@@ -149,6 +149,16 @@ private:
, m_text(std::move(t))
, m_text_valid(true)
{ }
+ entry(std::string &&name, std::string_view t)
+ : m_name(std::move(name))
+ , m_text(t)
+ , m_text_valid(true)
+ { }
+ entry(std::string &&name, const char *t)
+ : m_name(std::move(name))
+ , m_text(t)
+ , m_text_valid(true)
+ { }
entry(std::string &&name, s64 i)
: m_name(std::move(name))
, m_int(i)
@@ -766,7 +776,7 @@ public:
std::string get_attribute_subtag(util::xml::data_node const &node, char const *name)
{
std::string const *const attrib(node.get_attribute_string_ptr(name));
- return attrib ? device().subtag(std::string(expand(*attrib)).c_str()) : std::string();
+ return attrib ? device().subtag(expand(*attrib)) : std::string();
}
int get_attribute_int(util::xml::data_node const &node, const char *name, int defvalue)
@@ -4499,7 +4509,7 @@ layout_view::item::item(
if (itemnode.has_attribute("tag"))
{
std::string_view const tag(env.get_attribute_string(itemnode, "tag"));
- m_screen = dynamic_cast<screen_device *>(env.device().subdevice(std::string(tag).c_str()));
+ m_screen = dynamic_cast<screen_device *>(env.device().subdevice(tag));
if (!m_screen)
throw layout_reference_error(util::string_format("invalid screen tag '%d'", tag));
}
diff --git a/src/emu/romload.cpp b/src/emu/romload.cpp
index f7b55c18229..6ecc8ad6547 100644
--- a/src/emu/romload.cpp
+++ b/src/emu/romload.cpp
@@ -11,6 +11,7 @@
#include "emu.h"
#include "romload.h"
+#include "corestr.h"
#include "emuopts.h"
#include "drivenum.h"
#include "softlist_dev.h"
@@ -104,14 +105,13 @@ chd_error do_open_disk(const emu_options &options, std::initializer_list<std::re
{
// hashes are fixed, but we might need to try multiple filenames
std::set<std::string> tried;
- const util::hash_collection hashes(ROM_GETHASHDATA(romp));
+ const util::hash_collection hashes(romp->hashdata());
std::string filename, fullpath;
const rom_entry *parent(nullptr);
chd_error result(CHDERR_FILE_NOT_FOUND);
while (romp && (CHDERR_NONE != result))
{
- filename = ROM_GETNAME(romp);
- filename.append(".chd");
+ filename = romp->name() + ".chd";
if (tried.insert(filename).second)
{
// piggyback on emu_file to find the disk image file
@@ -170,7 +170,7 @@ chd_error do_open_disk(const emu_options &options, std::initializer_list<std::re
}
// try it if it matches the hashes
- if (romp && (util::hash_collection(ROM_GETHASHDATA(romp)) == hashes))
+ if (romp && (util::hash_collection(romp->hashdata()) == hashes))
break;
}
}
@@ -331,10 +331,10 @@ static void CLIB_DECL ATTR_PRINTF(1,2) debugload(const char *string, ...)
CHD file associated with the given region
-------------------------------------------------*/
-chd_file *rom_load_manager::get_disk_handle(const char *region)
+chd_file *rom_load_manager::get_disk_handle(std::string_view region)
{
for (auto &curdisk : m_chd_list)
- if (strcmp(curdisk->region(), region) == 0)
+ if (curdisk->region() == region)
return &curdisk->chd();
return nullptr;
}
@@ -345,7 +345,7 @@ chd_file *rom_load_manager::get_disk_handle(const char *region)
file associated with the given region
-------------------------------------------------*/
-int rom_load_manager::set_disk_handle(const char *region, const char *fullpath)
+int rom_load_manager::set_disk_handle(std::string_view region, const char *fullpath)
{
auto chd = std::make_unique<open_chd>(region);
auto err = chd->orig_chd().open(fullpath);
@@ -453,15 +453,12 @@ void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vec
tried += ')';
}
- std::string name(ROM_GETNAME(romp));
-
const bool is_chd(chderr != CHDERR_NONE);
- if (is_chd)
- name += ".chd";
+ const std::string name(is_chd ? romp->name() + ".chd" : romp->name());
const bool is_chd_error(is_chd && chderr != CHDERR_FILE_NOT_FOUND);
if (is_chd_error)
- m_errorstring.append(string_format("%s CHD ERROR: %s\n", name.c_str(), chd_file::error_string(chderr)));
+ m_errorstring.append(string_format("%s CHD ERROR: %s\n", name, chd_file::error_string(chderr)));
if (ROM_ISOPTIONAL(romp))
{
@@ -470,7 +467,7 @@ void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vec
m_errorstring.append(string_format("OPTIONAL %s NOT FOUND%s\n", name, tried));
m_warnings++;
}
- else if (util::hash_collection(ROM_GETHASHDATA(romp)).flag(util::hash_collection::FLAG_NO_DUMP))
+ else if (util::hash_collection(romp->hashdata()).flag(util::hash_collection::FLAG_NO_DUMP))
{
// no good dumps are okay
if (!is_chd_error)
@@ -495,8 +492,8 @@ void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vec
void rom_load_manager::dump_wrong_and_correct_checksums(const util::hash_collection &hashes, const util::hash_collection &acthashes)
{
- m_errorstring.append(string_format(" EXPECTED: %s\n", hashes.macro_string().c_str()));
- m_errorstring.append(string_format(" FOUND: %s\n", acthashes.macro_string().c_str()));
+ m_errorstring.append(string_format(" EXPECTED: %s\n", hashes.macro_string()));
+ m_errorstring.append(string_format(" FOUND: %s\n", acthashes.macro_string()));
}
@@ -505,7 +502,7 @@ void rom_load_manager::dump_wrong_and_correct_checksums(const util::hash_collect
and hash signatures of a file
-------------------------------------------------*/
-void rom_load_manager::verify_length_and_hash(emu_file *file, const char *name, u32 explength, const util::hash_collection &hashes)
+void rom_load_manager::verify_length_and_hash(emu_file *file, std::string_view name, u32 explength, const util::hash_collection &hashes)
{
// we've already complained if there is no file
if (!file)
@@ -528,7 +525,7 @@ void rom_load_manager::verify_length_and_hash(emu_file *file, const char *name,
else
{
// verify checksums
- util::hash_collection const &acthashes = file->hashes(hashes.hash_types().c_str());
+ util::hash_collection const &acthashes = file->hashes(hashes.hash_types());
if (hashes != acthashes)
{
// otherwise, it's just bad
@@ -650,7 +647,7 @@ std::unique_ptr<emu_file> rom_load_manager::open_rom_file(std::initializer_list<
// extract CRC to use for searching
u32 crc = 0;
- bool const has_crc = util::hash_collection(ROM_GETHASHDATA(romp)).crc(crc);
+ bool const has_crc = util::hash_collection(romp->hashdata()).crc(crc);
// attempt reading up the chain through the parents
// it also automatically attempts any kind of load by checksum supported by the archives.
@@ -674,7 +671,7 @@ std::unique_ptr<emu_file> rom_load_manager::open_rom_file(std::initializer_list<
}
-std::unique_ptr<emu_file> rom_load_manager::open_rom_file(const std::vector<std::string> &paths, std::vector<std::string> &tried, bool has_crc, u32 crc, const std::string &name, osd_file::error &filerr)
+std::unique_ptr<emu_file> rom_load_manager::open_rom_file(const std::vector<std::string> &paths, std::vector<std::string> &tried, bool has_crc, u32 crc, std::string_view name, osd_file::error &filerr)
{
// record the set names we search
tried.insert(tried.end(), paths.begin(), paths.end());
@@ -734,15 +731,15 @@ int rom_load_manager::read_rom_data(emu_file *file, const rom_entry *parent_regi
/* make sure the length was an even multiple of the group size */
if (numbytes % groupsize != 0)
- osd_printf_warning("Warning in RomModule definition: %s length not an even multiple of group size\n", ROM_GETNAME(romp));
+ osd_printf_warning("Warning in RomModule definition: %s length not an even multiple of group size\n", romp->name());
/* make sure we only fill within the region space */
if (ROM_GETOFFSET(romp) + numgroups * groupsize + (numgroups - 1) * skip > m_region->bytes())
- throw emu_fatalerror("Error in RomModule definition: %s out of memory region space\n", ROM_GETNAME(romp));
+ throw emu_fatalerror("Error in RomModule definition: %s out of memory region space\n", romp->name());
/* make sure the length was valid */
if (numbytes == 0)
- throw emu_fatalerror("Error in RomModule definition: %s has an invalid length\n", ROM_GETNAME(romp));
+ throw emu_fatalerror("Error in RomModule definition: %s has an invalid length\n", romp->name());
/* special case for simple loads */
if (datamask == 0xff && (groupsize == 1 || !reversed) && skip == 0)
@@ -847,7 +844,7 @@ void rom_load_manager::fill_rom_data(const rom_entry *romp)
throw emu_fatalerror("Error in RomModule definition: FILL has an invalid length\n");
// for fill bytes, the byte that gets filled is the first byte of the hashdata string
- u8 fill_byte = u8(strtol(ROM_GETHASHDATA(romp), nullptr, 0));
+ u8 fill_byte = u8(strtol(romp->hashdata().c_str(), nullptr, 0));
// fill the data (filling value is stored in place of the hashdata)
if(skip != 0)
@@ -867,9 +864,9 @@ void rom_load_manager::fill_rom_data(const rom_entry *romp)
void rom_load_manager::copy_rom_data(const rom_entry *romp)
{
u8 *base = m_region->base() + ROM_GETOFFSET(romp);
- const char *srcrgntag = ROM_GETNAME(romp);
+ const std::string &srcrgntag = romp->name();
u32 numbytes = ROM_GETLENGTH(romp);
- u32 srcoffs = u32(strtol(ROM_GETHASHDATA(romp), nullptr, 0)); /* srcoffset in place of hashdata */
+ u32 srcoffs = u32(strtol(romp->hashdata().c_str(), nullptr, 0)); /* srcoffset in place of hashdata */
/* make sure we copy within the region space */
if (ROM_GETOFFSET(romp) + numbytes > m_region->bytes())
@@ -972,7 +969,7 @@ void rom_load_manager::process_rom_entries(std::initializer_list<std::reference_
if (baserom)
{
LOG("Verifying length (%X) and checksums\n", explength);
- verify_length_and_hash(file.get(), ROM_GETNAME(baserom), explength, util::hash_collection(ROM_GETHASHDATA(baserom)));
+ verify_length_and_hash(file.get(), baserom->name(), explength, util::hash_collection(baserom->hashdata()));
LOG("Verify finished\n");
}
@@ -1006,7 +1003,7 @@ void rom_load_manager::process_rom_entries(std::initializer_list<std::reference_
chd_error rom_load_manager::open_disk_diff(emu_options &options, const rom_entry *romp, chd_file &source, chd_file &diff_chd)
{
// TODO: use system name and/or software list name in the path - the current setup doesn't scale
- std::string fname = std::string(ROM_GETNAME(romp)).append(".dif");
+ std::string fname = romp->name() + ".dif";
/* try to open the diff */
LOG("Opening differencing image file: %s\n", fname.c_str());
@@ -1049,11 +1046,11 @@ chd_error rom_load_manager::open_disk_diff(emu_options &options, const rom_entry
for a region
-------------------------------------------------*/
-void rom_load_manager::process_disk_entries(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, const char *regiontag, const rom_entry *romp, std::function<const rom_entry * ()> next_parent)
+void rom_load_manager::process_disk_entries(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, std::string_view regiontag, const rom_entry *romp, std::function<const rom_entry * ()> next_parent)
{
/* remove existing disk entries for this region */
m_chd_list.erase(std::remove_if(m_chd_list.begin(), m_chd_list.end(),
- [regiontag] (std::unique_ptr<open_chd> &chd) { return !strcmp(chd->region(), regiontag); }), m_chd_list.end());
+ [regiontag] (std::unique_ptr<open_chd> &chd) { return chd->region() == regiontag; }), m_chd_list.end());
/* loop until we hit the end of this region */
for ( ; !ROMENTRY_ISREGIONEND(romp); romp++)
@@ -1065,7 +1062,7 @@ void rom_load_manager::process_disk_entries(std::initializer_list<std::reference
chd_error err;
/* make the filename of the source */
- const std::string filename = std::string(ROM_GETNAME(romp)).append(".chd");
+ const std::string filename = romp->name() + ".chd";
/* first open the source drive */
// FIXME: we've lost the ability to search parents here
@@ -1083,7 +1080,7 @@ void rom_load_manager::process_disk_entries(std::initializer_list<std::reference
acthashes.add_sha1(chd->orig_chd().sha1());
/* verify the hash */
- const util::hash_collection hashes(ROM_GETHASHDATA(romp));
+ const util::hash_collection hashes(romp->hashdata());
if (hashes != acthashes)
{
m_errorstring.append(string_format("%s WRONG CHECKSUMS:\n", filename));
@@ -1168,7 +1165,7 @@ chd_error rom_load_manager::open_disk_image(const emu_options &options, software
flags for the given device
-------------------------------------------------*/
-void rom_load_manager::normalize_flags_for_device(const char *rgntag, u8 &width, endianness_t &endian)
+void rom_load_manager::normalize_flags_for_device(std::string_view rgntag, u8 &width, endianness_t &endian)
{
device_t *device = machine().root_device().subdevice(rgntag);
device_memory_interface *memory;
@@ -1209,7 +1206,7 @@ void rom_load_manager::normalize_flags_for_device(const char *rgntag, u8 &width,
more general process_region_list.
-------------------------------------------------*/
-void rom_load_manager::load_software_part_region(device_t &device, software_list_device &swlist, const char *swname, const rom_entry *start_region)
+void rom_load_manager::load_software_part_region(device_t &device, software_list_device &swlist, std::string_view swname, const rom_entry *start_region)
{
m_errorstring.clear();
m_softwarningstring.clear();
@@ -1220,7 +1217,7 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list
std::vector<const software_info *> parents;
std::vector<std::string> swsearch, disksearch, devsearch;
- const software_info *const swinfo = swlist.find(swname);
+ const software_info *const swinfo = swlist.find(std::string(swname));
if (swinfo)
{
// dispay a warning for unsupported software
@@ -1260,7 +1257,7 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list
{
u32 regionlength = ROMREGION_GETLENGTH(region);
- std::string regiontag = device.subtag(ROMREGION_GETTAG(region));
+ std::string regiontag = device.subtag(region->name());
LOG("Processing region \"%s\" (length=%X)\n", regiontag.c_str(), regionlength);
// the first entry must be a region
@@ -1272,7 +1269,7 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list
memory_region *memregion = machine().root_device().memregion(regiontag);
if (memregion != nullptr)
{
- normalize_flags_for_device(regiontag.c_str(), width, endianness);
+ normalize_flags_for_device(regiontag, width, endianness);
// clear old region (TODO: should be moved to an image unload function)
machine().memory().region_free(memregion->name());
@@ -1316,15 +1313,15 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list
next_parent = [] () { return nullptr; };
}
if (devsearch.empty())
- process_disk_entries({ swsearch, disksearch }, regiontag.c_str(), region + 1, next_parent);
+ process_disk_entries({ swsearch, disksearch }, regiontag, region + 1, next_parent);
else
- process_disk_entries({ swsearch, disksearch, devsearch }, regiontag.c_str(), region + 1, next_parent);
+ process_disk_entries({ swsearch, disksearch, devsearch }, regiontag, region + 1, next_parent);
}
}
// now go back and post-process all the regions
for (const rom_entry *region = start_region; region != nullptr; region = rom_next_region(region))
- region_post_process(device.memregion(ROMREGION_GETTAG(region)), ROMREGION_ISINVERTED(region));
+ region_post_process(device.memregion(region->name()), ROMREGION_ISINVERTED(region));
// display the results and exit
display_rom_load_results(true);
@@ -1348,7 +1345,7 @@ void rom_load_manager::process_region_list()
{
u32 regionlength = ROMREGION_GETLENGTH(region);
- std::string regiontag = device.subtag(ROM_GETNAME(region));
+ std::string regiontag = device.subtag(region->name());
LOG("Processing region \"%s\" (length=%X)\n", regiontag.c_str(), regionlength);
// the first entry must be a region
@@ -1359,10 +1356,10 @@ void rom_load_manager::process_region_list()
// if this is a device region, override with the device width and endianness
u8 width = ROMREGION_GETWIDTH(region) / 8;
endianness_t endianness = ROMREGION_ISBIGENDIAN(region) ? ENDIANNESS_BIG : ENDIANNESS_LITTLE;
- normalize_flags_for_device(regiontag.c_str(), width, endianness);
+ normalize_flags_for_device(regiontag, width, endianness);
// remember the base and length
- m_region = machine().memory().region_alloc(regiontag.c_str(), regionlength, width, endianness);
+ m_region = machine().memory().region_alloc(regiontag, regionlength, width, endianness);
LOG("Allocated %X bytes @ %p\n", m_region->bytes(), m_region->base());
if (ROMREGION_ISERASE(region)) // clear the region if it's requested
@@ -1393,7 +1390,7 @@ void rom_load_manager::process_region_list()
else
next_parent = [] () { return nullptr; };
}
- process_disk_entries({ searchpath }, regiontag.c_str(), region + 1, next_parent);
+ process_disk_entries({ searchpath }, regiontag, region + 1, next_parent);
}
}
}
@@ -1401,7 +1398,7 @@ void rom_load_manager::process_region_list()
// now go back and post-process all the regions
for (device_t &device : deviter)
for (const rom_entry *region = rom_first_region(device); region != nullptr; region = rom_next_region(region))
- region_post_process(device.memregion(ROM_GETNAME(region)), ROMREGION_ISINVERTED(region));
+ region_post_process(device.memregion(region->name()), ROMREGION_ISINVERTED(region));
// and finally register all per-game parameters
for (device_t &device : deviter)
@@ -1435,7 +1432,7 @@ rom_load_manager::rom_load_manager(running_machine &machine)
, m_softwarningstring()
{
// figure out which BIOS we are using
- std::map<std::string, std::string> card_bios;
+ std::map<std::string_view, std::string> card_bios;
for (device_t &device : device_enumerator(machine.config().root_device()))
{
device_slot_interface const *const slot(dynamic_cast<device_slot_interface *>(&device));
@@ -1444,7 +1441,7 @@ rom_load_manager::rom_load_manager(running_machine &machine)
device_t const *const card(slot->get_card_device());
slot_option const &slot_opt(machine.options().slot_option(slot->slot_name()));
if (card && !slot_opt.bios().empty())
- card_bios.emplace(std::make_pair(std::string(card->tag()), slot_opt.bios()));
+ card_bios.emplace(card->tag(), slot_opt.bios());
}
if (device.rom_region())
diff --git a/src/emu/romload.h b/src/emu/romload.h
index 2b9955a1590..29caaf8e124 100644
--- a/src/emu/romload.h
+++ b/src/emu/romload.h
@@ -51,7 +51,6 @@ template <typename T> inline bool ROMENTRY_ISPARAMETER(T const &r) { return
template <typename T> inline bool ROMENTRY_ISREGIONEND(T const &r) { return ROMENTRY_ISREGION(r) || ROMENTRY_ISPARAMETER(r) || ROMENTRY_ISEND(r); }
/* ----- per-region macros ----- */
-#define ROMREGION_GETTAG(r) ((r)->name().c_str())
template <typename T> inline u32 ROMREGION_GETLENGTH(T const &r) { return ROMENTRY_UNWRAP(r).get_length(); }
template <typename T> inline u32 ROMREGION_GETFLAGS(T const &r) { return ROMENTRY_UNWRAP(r).get_flags(); }
template <typename T> inline u32 ROMREGION_GETWIDTH(T const &r) { return 8 << ((ROMREGION_GETFLAGS(r) & ROMREGION_WIDTHMASK) >> 8); }
@@ -71,7 +70,6 @@ template <typename T> inline bool ROMREGION_ISDISKDATA(T const &r) { return
template <typename T> inline u32 ROM_GETOFFSET(T const &r) { return ROMENTRY_UNWRAP(r).get_offset(); }
template <typename T> inline u32 ROM_GETLENGTH(T const &r) { return ROMENTRY_UNWRAP(r).get_length(); }
template <typename T> inline u32 ROM_GETFLAGS(T const &r) { return ROMENTRY_UNWRAP(r).get_flags(); }
-#define ROM_GETHASHDATA(r) ((r)->hashdata().c_str())
template <typename T> inline bool ROM_ISOPTIONAL(T const &r) { return (ROM_GETFLAGS(r) & ROM_OPTIONALMASK) == ROM_OPTIONAL; }
template <typename T> inline u32 ROM_GETGROUPSIZE(T const &r) { return ((ROM_GETFLAGS(r) & ROM_GROUPMASK) >> 8) + 1; }
template <typename T> inline u32 ROM_GETSKIPCOUNT(T const &r) { return (ROM_GETFLAGS(r) & ROM_SKIPMASK) >> 12; }
@@ -387,9 +385,9 @@ class rom_load_manager
class open_chd
{
public:
- open_chd(const char *region) : m_region(region) { }
+ open_chd(std::string_view region) : m_region(region) { }
- const char *region() const { return m_region.c_str(); }
+ std::string_view region() const { return m_region; }
chd_file &chd() { return m_diffchd.opened() ? m_diffchd : m_origchd; }
chd_file &orig_chd() { return m_origchd; }
chd_file &diff_chd() { return m_diffchd; }
@@ -418,12 +416,12 @@ public:
/* ----- disk handling ----- */
/* return a pointer to the CHD file associated with the given region */
- chd_file *get_disk_handle(const char *region);
+ chd_file *get_disk_handle(std::string_view region);
/* set a pointer to the CHD file associated with the given region */
- int set_disk_handle(const char *region, const char *fullpath);
+ int set_disk_handle(std::string_view region, const char *fullpath);
- void load_software_part_region(device_t &device, software_list_device &swlist, const char *swname, const rom_entry *start_region);
+ void load_software_part_region(device_t &device, software_list_device &swlist, std::string_view swname, const rom_entry *start_region);
/* get search path for a software item */
static std::vector<std::string> get_software_searchpath(software_list_device &swlist, const software_info &swinfo);
@@ -438,20 +436,20 @@ private:
void fill_random(u8 *base, u32 length);
void handle_missing_file(const rom_entry *romp, const std::vector<std::string> &tried_file_names, chd_error chderr);
void dump_wrong_and_correct_checksums(const util::hash_collection &hashes, const util::hash_collection &acthashes);
- void verify_length_and_hash(emu_file *file, const char *name, u32 explength, const util::hash_collection &hashes);
+ void verify_length_and_hash(emu_file *file, std::string_view name, u32 explength, const util::hash_collection &hashes);
void display_loading_rom_message(const char *name, bool from_list);
void display_rom_load_results(bool from_list);
void region_post_process(memory_region *region, bool invert);
std::unique_ptr<emu_file> open_rom_file(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, const rom_entry *romp, std::vector<std::string> &tried_file_names, bool from_list);
- std::unique_ptr<emu_file> open_rom_file(const std::vector<std::string> &paths, std::vector<std::string> &tried, bool has_crc, u32 crc, const std::string &name, osd_file::error &filerr);
+ std::unique_ptr<emu_file> open_rom_file(const std::vector<std::string> &paths, std::vector<std::string> &tried, bool has_crc, u32 crc, std::string_view name, osd_file::error &filerr);
int rom_fread(emu_file *file, u8 *buffer, int length, const rom_entry *parent_region);
int read_rom_data(emu_file *file, const rom_entry *parent_region, const rom_entry *romp);
void fill_rom_data(const rom_entry *romp);
void copy_rom_data(const rom_entry *romp);
void process_rom_entries(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, u8 bios, const rom_entry *parent_region, const rom_entry *romp, bool from_list);
chd_error open_disk_diff(emu_options &options, const rom_entry *romp, chd_file &source, chd_file &diff_chd);
- void process_disk_entries(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, const char *regiontag, const rom_entry *romp, std::function<const rom_entry * ()> next_parent);
- void normalize_flags_for_device(const char *rgntag, u8 &width, endianness_t &endian);
+ void process_disk_entries(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, std::string_view regiontag, const rom_entry *romp, std::function<const rom_entry * ()> next_parent);
+ void normalize_flags_for_device(std::string_view rgntag, u8 &width, endianness_t &endian);
void process_region_list();
// internal state
diff --git a/src/emu/screen.cpp b/src/emu/screen.cpp
index ad62bda0688..1a1c5dee8ad 100644
--- a/src/emu/screen.cpp
+++ b/src/emu/screen.cpp
@@ -794,7 +794,7 @@ void screen_device::device_start()
if (!m_svg_region)
fatalerror("%s: SVG region \"%s\" does not exist\n", tag(), m_svg_region.finder_tag());
m_svg = std::make_unique<svg_renderer>(m_svg_region);
- machine().output().set_notifier(nullptr, svg_renderer::output_notifier, m_svg.get());
+ machine().output().set_global_notifier(svg_renderer::output_notifier, m_svg.get());
// don't do this - SVG units are arbitrary and interpreting them as pixels causes bad things to happen
// just render at the size/aspect ratio supplied by the driver
diff --git a/src/emu/softlist.cpp b/src/emu/softlist.cpp
index 690bb47415f..8166888f80a 100644
--- a/src/emu/softlist.cpp
+++ b/src/emu/softlist.cpp
@@ -24,7 +24,7 @@
// STATIC VARIABLES
//**************************************************************************
-static std::regex s_potenial_softlist_regex("\\w+(\\:\\w+)*");
+static std::regex s_potential_softlist_regex("\\w+(\\:\\w+)*");
//**************************************************************************
@@ -848,10 +848,10 @@ void softlist_parser::parse_soft_end(const char *tagname)
// case.
//-------------------------------------------------
-bool software_name_parse(const std::string &identifier, std::string *list_name, std::string *software_name, std::string *part_name)
+bool software_name_parse(std::string_view identifier, std::string *list_name, std::string *software_name, std::string *part_name)
{
// first, sanity check the arguments
- if (!std::regex_match(identifier, s_potenial_softlist_regex))
+ if (!std::regex_match(identifier.begin(), identifier.end(), s_potential_softlist_regex))
return false;
// reset all output parameters (if specified of course)
@@ -864,7 +864,7 @@ bool software_name_parse(const std::string &identifier, std::string *list_name,
// if no colon, this is the swname by itself
auto split1 = identifier.find_first_of(':');
- if (split1 == std::string::npos)
+ if (split1 == std::string_view::npos)
{
if (software_name != nullptr)
*software_name = identifier;
@@ -873,7 +873,7 @@ bool software_name_parse(const std::string &identifier, std::string *list_name,
// if one colon, it is the swname and swpart alone
auto split2 = identifier.find_first_of(':', split1 + 1);
- if (split2 == std::string::npos)
+ if (split2 == std::string_view::npos)
{
if (software_name != nullptr)
*software_name = identifier.substr(0, split1);
diff --git a/src/emu/softlist.h b/src/emu/softlist.h
index 5bc6705f9f6..5f8f7fd2fbd 100644
--- a/src/emu/softlist.h
+++ b/src/emu/softlist.h
@@ -210,6 +210,6 @@ private:
// ----- Helpers -----
// parses a software identifier (e.g. - 'apple2e:agentusa:flop1') into its constituent parts (returns false if cannot parse)
-bool software_name_parse(const std::string &identifier, std::string *list_name = nullptr, std::string *software_name = nullptr, std::string *part_name = nullptr);
+bool software_name_parse(std::string_view identifier, std::string *list_name = nullptr, std::string *software_name = nullptr, std::string *part_name = nullptr);
#endif // MAME_EMU_SOFTLIST_H
diff --git a/src/emu/softlist_dev.cpp b/src/emu/softlist_dev.cpp
index 56ca2a65d02..e6ee818b449 100644
--- a/src/emu/softlist_dev.cpp
+++ b/src/emu/softlist_dev.cpp
@@ -16,6 +16,7 @@
#include "romload.h"
#include "validity.h"
+#include "corestr.h"
#include "unicode.h"
#include <cctype>
@@ -48,7 +49,7 @@ image_software_list_loader image_software_list_loader::s_instance;
// false_software_list_loader::load_software
//-------------------------------------------------
-bool false_software_list_loader::load_software(device_image_interface &image, software_list_device &swlist, const char *swname, const rom_entry *start_entry) const
+bool false_software_list_loader::load_software(device_image_interface &image, software_list_device &swlist, std::string_view swname, const rom_entry *start_entry) const
{
return false;
}
@@ -58,7 +59,7 @@ bool false_software_list_loader::load_software(device_image_interface &image, so
// rom_software_list_loader::load_software
//-------------------------------------------------
-bool rom_software_list_loader::load_software(device_image_interface &image, software_list_device &swlist, const char *swname, const rom_entry *start_entry) const
+bool rom_software_list_loader::load_software(device_image_interface &image, software_list_device &swlist, std::string_view swname, const rom_entry *start_entry) const
{
swlist.machine().rom_load().load_software_part_region(image.device(), swlist, swname, start_entry);
return true;
@@ -69,7 +70,7 @@ bool rom_software_list_loader::load_software(device_image_interface &image, soft
// image_software_list_loader::load_software
//-------------------------------------------------
-bool image_software_list_loader::load_software(device_image_interface &image, software_list_device &swlist, const char *swname, const rom_entry *start_entry) const
+bool image_software_list_loader::load_software(device_image_interface &image, software_list_device &swlist, std::string_view swname, const rom_entry *start_entry) const
{
return image.load_software(swlist, swname, start_entry);
}
@@ -109,7 +110,7 @@ void software_list_device::device_start()
// and optional interface
//-------------------------------------------------
-void software_list_device::find_approx_matches(const std::string &name, int matches, const software_info **list, const char *interface)
+void software_list_device::find_approx_matches(std::string_view name, int matches, const software_info **list, const char *interface)
{
// if no name, return
if (name.empty())
@@ -188,7 +189,7 @@ void software_list_device::release()
// across all software list devices
//-------------------------------------------------
-software_list_device *software_list_device::find_by_name(const machine_config &config, const std::string &name)
+software_list_device *software_list_device::find_by_name(const machine_config &config, std::string_view name)
{
// iterate over each device in the system and find a match
for (software_list_device &swlistdev : software_list_device_enumerator(config.root_device()))
@@ -204,13 +205,13 @@ software_list_device *software_list_device::find_by_name(const machine_config &c
// name, across all software list devices
//-------------------------------------------------
-void software_list_device::display_matches(const machine_config &config, const char *interface, const std::string &name)
+void software_list_device::display_matches(const machine_config &config, const char *interface, std::string_view name)
{
// check if there is at least one software list
software_list_device_enumerator deviter(config.root_device());
if (deviter.first() != nullptr)
osd_printf_error("\n\"%s\" approximately matches the following\n"
- "supported software items (best match first):\n\n", name.c_str());
+ "supported software items (best match first):\n\n", name);
// iterate through lists
for (software_list_device &swlistdev : deviter)
diff --git a/src/emu/softlist_dev.h b/src/emu/softlist_dev.h
index d6f7f078553..598ea413b4f 100644
--- a/src/emu/softlist_dev.h
+++ b/src/emu/softlist_dev.h
@@ -43,7 +43,7 @@ enum software_compatibility
class software_list_loader
{
public:
- virtual bool load_software(device_image_interface &image, software_list_device &swlist, const char *swname, const rom_entry *start_entry) const = 0;
+ virtual bool load_software(device_image_interface &image, software_list_device &swlist, std::string_view swname, const rom_entry *start_entry) const = 0;
};
@@ -52,7 +52,7 @@ public:
class false_software_list_loader : public software_list_loader
{
public:
- virtual bool load_software(device_image_interface &image, software_list_device &swlist, const char *swname, const rom_entry *start_entry) const override;
+ virtual bool load_software(device_image_interface &image, software_list_device &swlist, std::string_view swname, const rom_entry *start_entry) const override;
static const software_list_loader &instance() { return s_instance; }
private:
@@ -65,7 +65,7 @@ private:
class rom_software_list_loader : public software_list_loader
{
public:
- virtual bool load_software(device_image_interface &image, software_list_device &swlist, const char *swname, const rom_entry *start_entry) const override;
+ virtual bool load_software(device_image_interface &image, software_list_device &swlist, std::string_view swname, const rom_entry *start_entry) const override;
static const software_list_loader &instance() { return s_instance; }
private:
@@ -78,7 +78,7 @@ private:
class image_software_list_loader : public software_list_loader
{
public:
- virtual bool load_software(device_image_interface &image, software_list_device &swlist, const char *swname, const rom_entry *start_entry) const override;
+ virtual bool load_software(device_image_interface &image, software_list_device &swlist, std::string_view swname, const rom_entry *start_entry) const override;
static const software_list_loader &instance() { return s_instance; }
private:
@@ -125,13 +125,13 @@ public:
// operations
const software_info *find(const std::string &look_for);
- void find_approx_matches(const std::string &name, int matches, const software_info **list, const char *interface);
+ void find_approx_matches(std::string_view name, int matches, const software_info **list, const char *interface);
void release();
software_compatibility is_compatible(const software_part &part) const;
// static helpers
- static software_list_device *find_by_name(const machine_config &mconfig, const std::string &name);
- static void display_matches(const machine_config &config, const char *interface, const std::string &name);
+ static software_list_device *find_by_name(const machine_config &mconfig, std::string_view name);
+ static void display_matches(const machine_config &config, const char *interface, std::string_view name);
static device_image_interface *find_mountable_image(const machine_config &mconfig, const software_part &part, std::function<bool (const device_image_interface &)> filter);
static device_image_interface *find_mountable_image(const machine_config &mconfig, const software_part &part);
diff --git a/src/emu/validity.cpp b/src/emu/validity.cpp
index 09758807e8e..710473b85f9 100644
--- a/src/emu/validity.cpp
+++ b/src/emu/validity.cpp
@@ -11,6 +11,7 @@
#include "emu.h"
#include "validity.h"
+#include "corestr.h"
#include "emuopts.h"
#include "romload.h"
#include "video/rgbutil.h"
@@ -291,7 +292,7 @@ void validity_checker::validate_one(const game_driver &driver)
{
// help verbose validation detect configuration-related crashes
if (m_print_verbose)
- output_via_delegate(OSD_OUTPUT_CHANNEL_ERROR, "Validating driver %s (%s)...\n", driver.name, core_filename_extract_base(driver.type.source()).c_str());
+ output_via_delegate(OSD_OUTPUT_CHANNEL_ERROR, "Validating driver %s (%s)...\n", driver.name, core_filename_extract_base(driver.type.source()));
// set the current driver
m_current_driver = &driver;
@@ -326,7 +327,7 @@ void validity_checker::validate_one(const game_driver &driver)
if (m_errors > start_errors || m_warnings > start_warnings || !m_verbose_text.empty())
{
if (!m_print_verbose)
- output_via_delegate(OSD_OUTPUT_CHANNEL_ERROR, "Driver %s (file %s): ", driver.name, core_filename_extract_base(driver.type.source()).c_str());
+ output_via_delegate(OSD_OUTPUT_CHANNEL_ERROR, "Driver %s (file %s): ", driver.name, core_filename_extract_base(driver.type.source()));
output_via_delegate(OSD_OUTPUT_CHANNEL_ERROR, "%d errors, %d warnings\n", m_errors - start_errors, m_warnings - start_warnings);
if (m_errors > start_errors)
output_indented_errors(m_error_text, "Errors");
@@ -2121,10 +2122,10 @@ void validity_checker::validate_device_types()
device_t *const dev = config.device_add(type.shortname(), type, 0);
char const *name((dev->shortname() && *dev->shortname()) ? dev->shortname() : type.type().name());
- std::string const description((dev->source() && *dev->source()) ? util::string_format("%s(%s)", core_filename_extract_base(dev->source()).c_str(), name) : name);
+ std::string const description((dev->source() && *dev->source()) ? util::string_format("%s(%s)", core_filename_extract_base(dev->source()), name) : name);
if (m_print_verbose)
- output_via_delegate(OSD_OUTPUT_CHANNEL_ERROR, "Validating device %s...\n", description.c_str());
+ output_via_delegate(OSD_OUTPUT_CHANNEL_ERROR, "Validating device %s...\n", description);
// ensure shortname exists
if (!dev->shortname() || !*dev->shortname())
@@ -2327,5 +2328,5 @@ void validity_checker::output_indented_errors(std::string &text, const char *hea
if (text[text.size()-1] == '\n')
text.erase(text.size()-1, 1);
strreplace(text, "\n", "\n ");
- output_via_delegate(OSD_OUTPUT_CHANNEL_ERROR, "%s:\n %s\n", header, text.c_str());
+ output_via_delegate(OSD_OUTPUT_CHANNEL_ERROR, "%s:\n %s\n", header, text);
}
diff --git a/src/emu/video.cpp b/src/emu/video.cpp
index 749e9113464..a4b02e2e2f3 100644
--- a/src/emu/video.cpp
+++ b/src/emu/video.cpp
@@ -16,6 +16,7 @@
#include "rendersw.hxx"
#include "output.h"
+#include "corestr.h"
#include "png.h"
#include "xmlfile.h"
@@ -173,7 +174,7 @@ video_manager::video_manager(running_machine &machine)
{
m_screenless_frame_timer = machine.scheduler().timer_alloc(timer_expired_delegate(FUNC(video_manager::screenless_update_callback), this));
m_screenless_frame_timer->adjust(screen_device::DEFAULT_FRAME_PERIOD, 0, screen_device::DEFAULT_FRAME_PERIOD);
- machine.output().set_notifier(nullptr, video_notifier_callback, this);
+ machine.output().set_global_notifier(video_notifier_callback, this);
}
}