From 91921618c2e06bd0ed073b8efccd31a127c9012d Mon Sep 17 00:00:00 2001 From: AJR Date: Wed, 20 Jan 2021 17:46:03 -0500 Subject: 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 --- src/devices/bus/gba/gba_slot.cpp | 6 +- src/devices/bus/nes/nes_unif.hxx | 1 + src/devices/bus/ti99/gromport/cartridges.cpp | 2 + src/devices/cpu/es5510/es5510.cpp | 2 + src/devices/machine/nscsi_bus.cpp | 2 +- src/devices/machine/ram.cpp | 2 + src/devices/sound/spu.cpp | 1 + src/emu/debug/debugcmd.cpp | 3 +- src/emu/debug/debugcon.cpp | 3 +- src/emu/debug/debugcpu.cpp | 4 +- src/emu/debug/debughlp.cpp | 1 + src/emu/debug/express.cpp | 6 +- src/emu/devcb.h | 30 ++-- src/emu/device.cpp | 90 ++++++++--- src/emu/device.h | 63 ++++---- src/emu/diimage.cpp | 175 +++++----------------- src/emu/diimage.h | 39 +++-- src/emu/dislot.cpp | 8 + src/emu/dislot.h | 2 +- src/emu/disound.cpp | 10 +- src/emu/drivenum.cpp | 2 + src/emu/emu.h | 1 - src/emu/emuopts.cpp | 45 ++++-- src/emu/emuopts.h | 9 +- src/emu/fileio.cpp | 18 +-- src/emu/fileio.h | 10 +- src/emu/image.cpp | 95 +++++++++++- src/emu/image.h | 5 + src/emu/input.cpp | 19 +-- src/emu/inputdev.cpp | 10 +- src/emu/inputdev.h | 2 +- src/emu/ioport.cpp | 3 +- src/emu/ioport.h | 2 +- src/emu/machine.cpp | 1 + src/emu/mconfig.cpp | 17 +-- src/emu/natkeyboard.cpp | 2 + src/emu/output.cpp | 51 ++++--- src/emu/output.h | 21 +-- src/emu/render.cpp | 1 + src/emu/rendfont.cpp | 1 + src/emu/rendlay.cpp | 14 +- src/emu/romload.cpp | 89 ++++++----- src/emu/romload.h | 20 ++- src/emu/screen.cpp | 2 +- src/emu/softlist.cpp | 10 +- src/emu/softlist.h | 2 +- src/emu/softlist_dev.cpp | 15 +- src/emu/softlist_dev.h | 14 +- src/emu/validity.cpp | 11 +- src/emu/video.cpp | 3 +- src/frontend/mame/audit.cpp | 17 +-- src/frontend/mame/audit.h | 4 +- src/frontend/mame/cheat.cpp | 3 +- src/frontend/mame/clifront.cpp | 35 ++--- src/frontend/mame/clifront.h | 4 +- src/frontend/mame/infoxml.cpp | 1 + src/frontend/mame/language.cpp | 2 + src/frontend/mame/luaengine.cpp | 16 +- src/frontend/mame/mame.cpp | 1 + src/frontend/mame/mameopts.cpp | 4 +- src/frontend/mame/media_ident.cpp | 4 +- src/frontend/mame/pluginopts.cpp | 2 +- src/frontend/mame/ui/auditmenu.cpp | 1 + src/frontend/mame/ui/custui.cpp | 1 + src/frontend/mame/ui/dirmenu.cpp | 2 + src/frontend/mame/ui/filesel.cpp | 1 + src/frontend/mame/ui/imgcntrl.cpp | 10 +- src/frontend/mame/ui/inifile.cpp | 1 + src/frontend/mame/ui/menu.cpp | 1 + src/frontend/mame/ui/miscmenu.cpp | 3 +- src/frontend/mame/ui/selector.cpp | 2 + src/frontend/mame/ui/selgame.cpp | 4 +- src/frontend/mame/ui/selmenu.cpp | 1 + src/frontend/mame/ui/selsoft.cpp | 1 + src/frontend/mame/ui/slotopt.cpp | 4 +- src/frontend/mame/ui/slotopt.h | 2 +- src/frontend/mame/ui/state.cpp | 2 +- src/frontend/mame/ui/swlist.cpp | 1 + src/frontend/mame/ui/ui.cpp | 2 +- src/frontend/mame/ui/utils.cpp | 5 +- src/lib/util/corefile.cpp | 17 +-- src/lib/util/corefile.h | 6 +- src/lib/util/corestr.cpp | 48 +++--- src/lib/util/corestr.h | 11 +- src/lib/util/hash.cpp | 16 +- src/lib/util/hash.h | 2 +- src/lib/util/options.cpp | 111 ++++++++------ src/lib/util/options.h | 49 +++--- src/lib/util/zippath.cpp | 24 +-- src/lib/util/zippath.h | 1 - src/mame/drivers/esq5505.cpp | 2 +- src/mame/machine/bfm_sc45_helper.cpp | 10 +- src/mame/machine/lynx.cpp | 2 + src/mame/machine/spec_snqk.cpp | 1 + src/osd/mac/macmain.cpp | 3 +- src/osd/modules/diagnostics/diagnostics_win32.cpp | 6 +- src/osd/modules/font/font_osx.cpp | 2 +- src/osd/modules/font/font_sdl.cpp | 8 +- src/osd/modules/lib/osdobj_common.cpp | 2 +- src/osd/modules/lib/osdobj_common.h | 16 +- src/osd/modules/render/bgfx/texturemanager.cpp | 2 +- src/osd/sdl/osdsdl.h | 6 +- src/osd/sdl/sdlmain.cpp | 3 +- src/osd/windows/winmain.cpp | 24 +-- src/tools/chdman.cpp | 16 +- src/tools/imgtool/imgtool.cpp | 2 +- src/tools/imgtool/main.cpp | 4 +- src/tools/imgtool/stream.cpp | 3 +- src/tools/split.cpp | 6 +- 109 files changed, 817 insertions(+), 668 deletions(-) diff --git a/src/devices/bus/gba/gba_slot.cpp b/src/devices/bus/gba/gba_slot.cpp index 7a2b4ee72af..06ec379cf77 100644 --- a/src/devices/bus/gba/gba_slot.cpp +++ b/src/devices/bus/gba/gba_slot.cpp @@ -719,7 +719,11 @@ static inline std::string gba_chip_string( uint32_t chip ) if (chip & GBA_CHIP_FLASH_512) str += "FLASH_512 "; if (chip & GBA_CHIP_SRAM) str += "SRAM "; if (chip & GBA_CHIP_RTC) str += "RTC "; - strtrimspace(str); + if (!str.empty()) + { + assert(str.back() == ' '); + str = str.substr(0, str.length() - 1); + } return str; } diff --git a/src/devices/bus/nes/nes_unif.hxx b/src/devices/bus/nes/nes_unif.hxx index 51843f60c2e..af4839f4ebf 100644 --- a/src/devices/bus/nes/nes_unif.hxx +++ b/src/devices/bus/nes/nes_unif.hxx @@ -11,6 +11,7 @@ ****************************************************************************************/ +#include "corestr.h" /* Set to generate prg & chr files when the cart is loaded */ #define SPLIT_PRG 0 diff --git a/src/devices/bus/ti99/gromport/cartridges.cpp b/src/devices/bus/ti99/gromport/cartridges.cpp index f1d3aeb60a1..bbd8184ea04 100644 --- a/src/devices/bus/ti99/gromport/cartridges.cpp +++ b/src/devices/bus/ti99/gromport/cartridges.cpp @@ -15,6 +15,8 @@ #include "emu.h" #include "cartridges.h" +#include "corestr.h" + #define LOG_WARN (1U<<1) // Warnings #define LOG_CONFIG (1U<<2) // Configuration #define LOG_CHANGE (1U<<3) // Cart change diff --git a/src/devices/cpu/es5510/es5510.cpp b/src/devices/cpu/es5510/es5510.cpp index 81df1799e36..28a2797454f 100644 --- a/src/devices/cpu/es5510/es5510.cpp +++ b/src/devices/cpu/es5510/es5510.cpp @@ -18,6 +18,8 @@ #include "cpu/m68000/m68000.h" #include "debugger.h" +#include "corestr.h" + #include #include diff --git a/src/devices/machine/nscsi_bus.cpp b/src/devices/machine/nscsi_bus.cpp index 60d7e54d2fd..b0e63966e75 100644 --- a/src/devices/machine/nscsi_bus.cpp +++ b/src/devices/machine/nscsi_bus.cpp @@ -128,7 +128,7 @@ void nscsi_bus_device::ctrl_wait(int refid, uint32_t lines, uint32_t mask) void nscsi_bus_device::device_resolve_objects() { for(int i=0; i<16; i++) { - device_t *subdev = subdevice(string_format("%d", i).c_str()); + device_t *subdev = subdevice(string_format("%d", i)); nscsi_device *sdev = subdev ? downcast(*subdev).get_device() : nullptr; if(sdev) { int rid = devcnt++; diff --git a/src/devices/machine/ram.cpp b/src/devices/machine/ram.cpp index 30195810ac2..3f8cfd94d51 100644 --- a/src/devices/machine/ram.cpp +++ b/src/devices/machine/ram.cpp @@ -10,6 +10,8 @@ #include "emu.h" #include "ram.h" + +#include "corestr.h" #include "emuopts.h" #include diff --git a/src/devices/sound/spu.cpp b/src/devices/sound/spu.cpp index 9a8f503cf04..6cfba4fc5bc 100644 --- a/src/devices/sound/spu.cpp +++ b/src/devices/sound/spu.cpp @@ -12,6 +12,7 @@ #include "spu.h" #include "spureverb.h" #include "cpu/psx/psx.h" +#include "corestr.h" // // 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 #include #include @@ -3670,7 +3671,7 @@ void debugger_commands::execute_snap(int ref, const std::vector &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 #include @@ -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 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 @@ -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 @@ -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 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 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 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 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 mem_mask) + [&item = m_devbase.machine().output().find_or_create_item(m_tag, 0)] (offs_t offset, input_t data, std::make_unsigned_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 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 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 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(); @@ -963,6 +968,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) +{ + 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, 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); + device_t &replace_and_remove(std::unique_ptr &&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 m_list; // list of sub-devices we own - mutable std::unordered_map m_tagmap; // map of devices looked up and found by subtag + std::unordered_map> 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 DeviceClass *subdevice(const char *tag) const { return downcast(subdevice(tag)); } - template DeviceClass *siblingdevice(const char *tag) const { return downcast(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 DeviceClass *subdevice(std::string_view tag) const { return downcast(subdevice(tag)); } + template DeviceClass *siblingdevice(std::string_view tag) const { return downcast(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(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(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 +#include #include #include @@ -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 @@ -721,16 +638,6 @@ bool device_image_interface::uses_file_extension(const char *file_extension) con // IMAGE LOADING // *************************************************************************** -//------------------------------------------------- -// 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 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 parents; std::vector 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 &&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 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 +#include 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 @@ -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()); @@ -509,17 +511,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 &&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 - #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 + //************************************************************************** // 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 #include #include 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 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, 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, 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 void notify_all(T &¬ifier) 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(env.device().subdevice(std::string(tag).c_str())); + m_screen = dynamic_cast(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 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_listhashdata()) == 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(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 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 rom_load_manager::open_rom_file(std::initializer_list< } -std::unique_ptr rom_load_manager::open_rom_file(const std::vector &paths, std::vector &tried, bool has_crc, u32 crc, const std::string &name, osd_file::error &filerr) +std::unique_ptr rom_load_manager::open_rom_file(const std::vector &paths, std::vector &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_listname(), explength, util::hash_collection(baserom->hashdata())); LOG("Verify finished\n"); } @@ -1006,7 +1003,7 @@ void rom_load_manager::process_rom_entries(std::initializer_listname() + ".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 > > searchpath, const char *regiontag, const rom_entry *romp, std::function next_parent) +void rom_load_manager::process_disk_entries(std::initializer_list > > searchpath, std::string_view regiontag, const rom_entry *romp, std::function 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 &chd) { return !strcmp(chd->region(), regiontag); }), m_chd_list.end()); + [regiontag] (std::unique_ptr &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_listname() + ".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_listorig_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 parents; std::vector 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 card_bios; + std::map card_bios; for (device_t &device : device_enumerator(machine.config().root_device())) { device_slot_interface const *const slot(dynamic_cast(&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 inline bool ROMENTRY_ISPARAMETER(T const &r) { return template 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 inline u32 ROMREGION_GETLENGTH(T const &r) { return ROMENTRY_UNWRAP(r).get_length(); } template inline u32 ROMREGION_GETFLAGS(T const &r) { return ROMENTRY_UNWRAP(r).get_flags(); } template inline u32 ROMREGION_GETWIDTH(T const &r) { return 8 << ((ROMREGION_GETFLAGS(r) & ROMREGION_WIDTHMASK) >> 8); } @@ -71,7 +70,6 @@ template inline bool ROMREGION_ISDISKDATA(T const &r) { return template inline u32 ROM_GETOFFSET(T const &r) { return ROMENTRY_UNWRAP(r).get_offset(); } template inline u32 ROM_GETLENGTH(T const &r) { return ROMENTRY_UNWRAP(r).get_length(); } template inline u32 ROM_GETFLAGS(T const &r) { return ROMENTRY_UNWRAP(r).get_flags(); } -#define ROM_GETHASHDATA(r) ((r)->hashdata().c_str()) template inline bool ROM_ISOPTIONAL(T const &r) { return (ROM_GETFLAGS(r) & ROM_OPTIONALMASK) == ROM_OPTIONAL; } template inline u32 ROM_GETGROUPSIZE(T const &r) { return ((ROM_GETFLAGS(r) & ROM_GROUPMASK) >> 8) + 1; } template 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 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 &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 open_rom_file(std::initializer_list > > searchpath, const rom_entry *romp, std::vector &tried_file_names, bool from_list); - std::unique_ptr open_rom_file(const std::vector &paths, std::vector &tried, bool has_crc, u32 crc, const std::string &name, osd_file::error &filerr); + std::unique_ptr open_rom_file(const std::vector &paths, std::vector &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 > > 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 > > searchpath, const char *regiontag, const rom_entry *romp, std::function next_parent); - void normalize_flags_for_device(const char *rgntag, u8 &width, endianness_t &endian); + void process_disk_entries(std::initializer_list > > searchpath, std::string_view regiontag, const rom_entry *romp, std::function 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(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 @@ -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 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); } } diff --git a/src/frontend/mame/audit.cpp b/src/frontend/mame/audit.cpp index ce8e1368992..42ddcdad438 100644 --- a/src/frontend/mame/audit.cpp +++ b/src/frontend/mame/audit.cpp @@ -31,7 +31,7 @@ namespace { struct parent_rom { - parent_rom(device_type t, rom_entry const *r) : type(t), name(ROM_GETNAME(r)), hashes(ROM_GETHASHDATA(r)), length(rom_file_size(r)) { } + parent_rom(device_type t, rom_entry const *r) : type(t), name(r->name()), hashes(r->hashdata()), length(rom_file_size(r)) { } std::reference_wrapper > type; std::string name; @@ -74,7 +74,7 @@ public: } } - std::add_pointer_t find_shared_device(device_t ¤t, char const *name, util::hash_collection const &hashes, uint64_t length) const + std::add_pointer_t find_shared_device(device_t ¤t, std::string_view name, util::hash_collection const &hashes, uint64_t length) const { // if we're examining a child device, it will always have a perfect match if (current.owner()) @@ -120,7 +120,7 @@ public: { if (rom_file_size(rom) == record.actual_length()) { - util::hash_collection const hashes(ROM_GETHASHDATA(rom)); + util::hash_collection const hashes(rom->hashdata()); if (hashes == record.actual_hashes()) return std::make_pair(¤t.type(), empty()); else if (hashes.flag(util::hash_collection::FLAG_NO_DUMP) && (rom->name() == record.name())) @@ -228,8 +228,8 @@ media_auditor::summary media_auditor::audit_media(const char *validation) } // look for a matching parent or device ROM - char const *const name(ROM_GETNAME(rom)); - util::hash_collection const hashes(ROM_GETHASHDATA(rom)); + std::string const &name(rom->name()); + util::hash_collection const hashes(rom->hashdata()); bool const dumped(!hashes.flag(util::hash_collection::FLAG_NO_DUMP)); std::add_pointer_t const shared_device(parentroms.find_shared_device(device, name, hashes, rom_file_size(rom))); if (shared_device) @@ -557,7 +557,7 @@ void media_auditor::audit_regions(T do_audit, const rom_entry *region, std::size for (rom_entry const *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { // count the number of files with hashes - util::hash_collection const hashes(ROM_GETHASHDATA(rom)); + util::hash_collection const hashes(rom->hashdata()); if (!hashes.flag(util::hash_collection::FLAG_NO_DUMP) && !ROM_ISOPTIONAL(rom)) required++; @@ -679,14 +679,13 @@ media_auditor::audit_record::audit_record(const rom_entry &media, media_type typ : m_type(type) , m_status(audit_status::UNVERIFIED) , m_substatus(audit_substatus::UNVERIFIED) - , m_name(ROM_GETNAME(&media)) + , m_name(media.name()) , m_explength(rom_file_size(&media)) , m_length(0) - , m_exphashes() + , m_exphashes(media.hashdata()) , m_hashes() , m_shared_device(nullptr) { - m_exphashes.from_internal_string(ROM_GETHASHDATA(&media)); } media_auditor::audit_record::audit_record(const char *name, media_type type) diff --git a/src/frontend/mame/audit.h b/src/frontend/mame/audit.h index d1904820f03..10a32926613 100644 --- a/src/frontend/mame/audit.h +++ b/src/frontend/mame/audit.h @@ -102,7 +102,7 @@ public: media_type type() const { return m_type; } audit_status status() const { return m_status; } audit_substatus substatus() const { return m_substatus; } - const char *name() const { return m_name; } + const std::string &name() const { return m_name; } uint64_t expected_length() const { return m_explength; } uint64_t actual_length() const { return m_length; } const util::hash_collection &expected_hashes() const { return m_exphashes; } @@ -138,7 +138,7 @@ public: media_type m_type; // type of item that was audited audit_status m_status; // status of audit on this item audit_substatus m_substatus; // finer-detail status - const char * m_name; // name of item + std::string m_name; // name of item uint64_t m_explength; // expected length of item uint64_t m_length; // actual length of item util::hash_collection m_exphashes; // expected hash data diff --git a/src/frontend/mame/cheat.cpp b/src/frontend/mame/cheat.cpp index 125a6634dbb..61cda1cf475 100644 --- a/src/frontend/mame/cheat.cpp +++ b/src/frontend/mame/cheat.cpp @@ -79,6 +79,7 @@ #include "ui/ui.h" #include "ui/menu.h" +#include "corestr.h" #include "emuopts.h" #include @@ -951,7 +952,7 @@ void cheat_entry::menu_text(std::string &description, std::string &state, uint32 // some cheat entries are just text for display if (!description.empty()) { - strtrimspace(description); + description = strtrimspace(description); if (description.empty()) description = MENU_SEPARATOR_ITEM; } diff --git a/src/frontend/mame/clifront.cpp b/src/frontend/mame/clifront.cpp index 3d177e7e851..1c2ba0d809c 100644 --- a/src/frontend/mame/clifront.cpp +++ b/src/frontend/mame/clifront.cpp @@ -18,17 +18,18 @@ #include "language.h" #include "luaengine.h" #include "mame.h" +#include "mameopts.h" #include "media_ident.h" #include "pluginopts.h" #include "emuopts.h" -#include "mameopts.h" #include "romload.h" #include "softlist_dev.h" #include "validity.h" #include "sound/samples.h" #include "chd.h" +#include "corestr.h" #include "unzip.h" #include "xmlfile.h" @@ -229,12 +230,12 @@ void cli_frontend::start_execution(mame_machine_manager *manager, const std::vec } // determine the base name of the EXE - std::string exename = core_filename_extract_base(args[0], true); + std::string_view exename = core_filename_extract_base(args[0], true); // if we have a command, execute that if (!m_options.command().empty()) { - execute_commands(exename.c_str()); + execute_commands(exename); return; } @@ -253,10 +254,7 @@ void cli_frontend::start_execution(mame_machine_manager *manager, const std::vec manager->start_luaengine(); if (option_errors.tellp() > 0) - { - std::string option_errors_string = option_errors.str(); - osd_printf_error("Error in command line:\n%s\n", strtrimspace(option_errors_string)); - } + osd_printf_error("Error in command line:\n%s\n", strtrimspace(option_errors.str())); // if we can't find it, give an appropriate error const game_driver *system = mame_options::system(m_options); @@ -285,9 +283,7 @@ int cli_frontend::execute(std::vector &args) // handle exceptions of various types catch (emu_fatalerror &fatal) { - std::string str(fatal.what()); - strtrimspace(str); - osd_printf_error("%s\n", str); + osd_printf_error("%s\n", strtrimspace(fatal.what())); m_result = (fatal.exitcode() != 0) ? fatal.exitcode() : EMU_ERR_FATALERROR; // if a game was specified, wasn't a wildcard, and our error indicates this was the @@ -568,8 +564,7 @@ void cli_frontend::listroms(const std::vector &args) length = rom_file_size(rom); // start with the name - const char *name = ROM_GETNAME(rom); - osd_printf_info("%-32s ", name); + osd_printf_info("%-32s ", rom->name()); // output the length next if (length >= 0) @@ -578,7 +573,7 @@ void cli_frontend::listroms(const std::vector &args) osd_printf_info("%10s", ""); // output the hash data - util::hash_collection hashes(ROM_GETHASHDATA(rom)); + util::hash_collection hashes(rom->hashdata()); if (!hashes.flag(util::hash_collection::FLAG_NO_DUMP)) { if (hashes.flag(util::hash_collection::FLAG_BAD_DUMP)) @@ -1101,7 +1096,7 @@ void cli_frontend::output_single_softlist(std::ostream &out, software_list_devic util::stream_format(out, "\t\t\t%s\n", util::xml::normalize_string(swinfo.publisher().c_str())); for (const feature_list_item &flist : swinfo.other_info()) - util::stream_format(out, "\t\t\t\n", flist.name().c_str(), util::xml::normalize_string(flist.value().c_str())); + util::stream_format(out, "\t\t\t\n", flist.name(), util::xml::normalize_string(flist.value().c_str())); for (const software_part &part : swinfo.parts()) { @@ -1112,7 +1107,7 @@ void cli_frontend::output_single_softlist(std::ostream &out, software_list_devic out << ">\n"; for (const feature_list_item &flist : part.featurelist()) - util::stream_format(out, "\t\t\t\t\n", flist.name().c_str(), util::xml::normalize_string(flist.value().c_str())); + util::stream_format(out, "\t\t\t\t\n", flist.name(), util::xml::normalize_string(flist.value().c_str())); // TODO: display ROM region information for (const rom_entry *region = part.romdata().data(); region; region = rom_next_region(region)) @@ -1120,9 +1115,9 @@ void cli_frontend::output_single_softlist(std::ostream &out, software_list_devic int is_disk = ROMREGION_ISDISKDATA(region); if (!is_disk) - util::stream_format(out, "\t\t\t\t\n", util::xml::normalize_string(ROMREGION_GETTAG(region)), ROMREGION_GETLENGTH(region)); + util::stream_format(out, "\t\t\t\t\n", util::xml::normalize_string(region->name().c_str()), region->get_length()); else - util::stream_format(out, "\t\t\t\t\n", util::xml::normalize_string(ROMREGION_GETTAG(region))); + util::stream_format(out, "\t\t\t\t\n", util::xml::normalize_string(region->name().c_str())); for (const rom_entry *rom = rom_first_file(region); rom && !ROMENTRY_ISREGIONEND(rom); rom++) { @@ -1134,7 +1129,7 @@ void cli_frontend::output_single_softlist(std::ostream &out, software_list_devic util::stream_format(out, "\t\t\t\t\thashdata()); if (!hashes.flag(util::hash_collection::FLAG_NO_DUMP)) util::stream_format(out, " %s", hashes.attribute_string()); else @@ -1607,7 +1602,7 @@ const cli_frontend::info_command_struct *cli_frontend::find_command(const std::s // commands //------------------------------------------------- -void cli_frontend::execute_commands(const char *exename) +void cli_frontend::execute_commands(std::string_view exename) { // help? if (m_options.command() == CLICOMMAND_HELP) @@ -1726,7 +1721,7 @@ void cli_frontend::execute_commands(const char *exename) // output //------------------------------------------------- -void cli_frontend::display_help(const char *exename) +void cli_frontend::display_help(std::string_view exename) { osd_printf_info( "%3$s v%2$s\n" diff --git a/src/frontend/mame/clifront.h b/src/frontend/mame/clifront.h index 8a2ae059b6c..bc0ab3baab8 100644 --- a/src/frontend/mame/clifront.h +++ b/src/frontend/mame/clifront.h @@ -70,8 +70,8 @@ private: // internal helpers template void apply_action(const std::vector &args, T &&drvact, U &&devact); template void apply_device_action(const std::vector &args, T &&action); - void execute_commands(const char *exename); - void display_help(const char *exename); + void execute_commands(std::string_view exename); + void display_help(std::string_view exename); void output_single_softlist(std::ostream &out, software_list_device &swlist); void start_execution(mame_machine_manager *manager, const std::vector &args); static const info_command_struct *find_command(const std::string &s); diff --git a/src/frontend/mame/infoxml.cpp b/src/frontend/mame/infoxml.cpp index 1aeee7b51d6..4c625c5854b 100644 --- a/src/frontend/mame/infoxml.cpp +++ b/src/frontend/mame/infoxml.cpp @@ -23,6 +23,7 @@ #include "softlist_dev.h" #include "speaker.h" +#include "corestr.h" #include "xmlfile.h" #include diff --git a/src/frontend/mame/language.cpp b/src/frontend/mame/language.cpp index 446157e6f19..1cd0d1be65e 100644 --- a/src/frontend/mame/language.cpp +++ b/src/frontend/mame/language.cpp @@ -11,6 +11,8 @@ #include "emu.h" #include "emuopts.h" +#include "corestr.h" + #include #include #include diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp index 0c7b9c046fc..d8ec8c746db 100644 --- a/src/frontend/mame/luaengine.cpp +++ b/src/frontend/mame/luaengine.cpp @@ -26,6 +26,8 @@ #include "softlist.h" #include "uiinput.h" +#include "corestr.h" + #include #include @@ -882,7 +884,7 @@ void lua_engine::initialize() })); file_type.set("read", [](emu_file &file, sol::buffer *buff) { buff->set_len(file.read(buff->get_ptr(), buff->get_len())); return buff; }); file_type.set("write", [](emu_file &file, const std::string &data) { return file.write(data.data(), data.size()); }); - file_type.set("open", static_cast(&emu_file::open)); + file_type.set("open", static_cast(&emu_file::open)); file_type.set("open_next", &emu_file::open_next); file_type.set("seek", sol::overload( [](emu_file &file) { return file.tell(); }, @@ -1375,8 +1377,8 @@ void lua_engine::initialize() device_type["memshare"] = &device_t::memshare; device_type["membank"] = &device_t::membank; device_type["ioport"] = &device_t::ioport; - device_type["subdevice"] = static_cast(&device_t::subdevice); - device_type["siblingdevice"] = static_cast(&device_t::siblingdevice); + device_type["subdevice"] = static_cast(&device_t::subdevice); + device_type["siblingdevice"] = static_cast(&device_t::siblingdevice); device_type["parameter"] = &device_t::parameter; device_type["tag"] = sol::property(&device_t::tag); device_type["basetag"] = sol::property(&device_t::basetag); @@ -1582,9 +1584,9 @@ void lua_engine::initialize() auto image_type = sol().registry().new_usertype("image", "new", sol::no_constructor); image_type["load"] = &device_image_interface::load; - image_type["load_software"] = static_cast(&device_image_interface::load_software); + image_type["load_software"] = static_cast(&device_image_interface::load_software); image_type["unload"] = &device_image_interface::unload; - image_type["create"] = static_cast(&device_image_interface::create); + image_type["create"] = static_cast(&device_image_interface::create); image_type["display"] = &device_image_interface::call_display; image_type["is_readable"] = sol::property(&device_image_interface::is_readable); image_type["is_writeable"] = sol::property(&device_image_interface::is_writeable); @@ -1818,13 +1820,13 @@ void lua_engine::initialize() output_type["set_indexed_value"] = [] (output_manager &o, char const *basename, int index, int value) { - o.set_value(util::string_format("%s%d", basename, index).c_str(), value); + o.set_value(util::string_format("%s%d", basename, index), value); }; output_type["get_value"] = &output_manager::get_value; output_type["get_indexed_value"] = [] (output_manager &o, char const *basename, int index) { - return o.get_value(util::string_format("%s%d", basename, index).c_str()); + return o.get_value(util::string_format("%s%d", basename, index)); }; output_type["name_to_id"] = &output_manager::name_to_id; output_type["id_to_name"] = &output_manager::id_to_name; diff --git a/src/frontend/mame/mame.cpp b/src/frontend/mame/mame.cpp index 919d3583074..1158666ff92 100644 --- a/src/frontend/mame/mame.cpp +++ b/src/frontend/mame/mame.cpp @@ -25,6 +25,7 @@ #include "rendlay.h" #include "validity.h" +#include "corestr.h" #include "xmlfile.h" #include "osdepend.h" diff --git a/src/frontend/mame/mameopts.cpp b/src/frontend/mame/mameopts.cpp index 88ae9951cd9..0e6c28da23d 100644 --- a/src/frontend/mame/mameopts.cpp +++ b/src/frontend/mame/mameopts.cpp @@ -91,7 +91,7 @@ void mame_options::parse_standard_inis(emu_options &options, std::ostream &error } // next parse "source/.ini" - std::string sourcename = core_filename_extract_base(cursystem->type.source(), true).insert(0, "source" PATH_SEPARATOR); + std::string sourcename = std::string(core_filename_extract_base(cursystem->type.source(), true)).insert(0, "source" PATH_SEPARATOR); parse_one_ini(options, sourcename.c_str(), OPTION_PRIORITY_SOURCE_INI, &error_stream); // then parse the grandparent, parent, and system-specific INIs @@ -112,7 +112,7 @@ void mame_options::parse_standard_inis(emu_options &options, std::ostream &error const game_driver *mame_options::system(const emu_options &options) { - int index = driver_list::find(core_filename_extract_base(options.system_name(), true).c_str()); + int index = driver_list::find(std::string(core_filename_extract_base(options.system_name(), true)).c_str()); return (index != -1) ? &driver_list::driver(index) : nullptr; } diff --git a/src/frontend/mame/media_ident.cpp b/src/frontend/mame/media_ident.cpp index 9aeb8765089..b5ae8ef578a 100644 --- a/src/frontend/mame/media_ident.cpp +++ b/src/frontend/mame/media_ident.cpp @@ -47,7 +47,7 @@ void media_identifier::file_info::match( m_matches.emplace_back( util::string_format("%s:%s", list, software.shortname()), std::string(software.longname()), - ROM_GETNAME(&rom), + std::string(rom.name()), hashes.flag(util::hash_collection::FLAG_BAD_DUMP), false); } @@ -366,7 +366,7 @@ void media_identifier::match_hashes(std::vector &info) { for (rom_entry const *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { - util::hash_collection romhashes(ROM_GETHASHDATA(rom)); + util::hash_collection romhashes(rom->hashdata()); if (!romhashes.flag(util::hash_collection::FLAG_NO_DUMP)) { for (file_info &file : info) diff --git a/src/frontend/mame/pluginopts.cpp b/src/frontend/mame/pluginopts.cpp index 2dda2062064..51fa39c2ac9 100644 --- a/src/frontend/mame/pluginopts.cpp +++ b/src/frontend/mame/pluginopts.cpp @@ -165,7 +165,7 @@ void plugin_options::parse_ini_file(util::core_file &inifile) // and reflect these options back for (plugin &p : m_plugins) - p.m_start = opts.bool_value(p.m_name.c_str()); + p.m_start = opts.bool_value(p.m_name); } diff --git a/src/frontend/mame/ui/auditmenu.cpp b/src/frontend/mame/ui/auditmenu.cpp index 0842443b63e..9cadb5b5d97 100644 --- a/src/frontend/mame/ui/auditmenu.cpp +++ b/src/frontend/mame/ui/auditmenu.cpp @@ -14,6 +14,7 @@ #include "ui/ui.h" #include "audit.h" +#include "corestr.h" #include "drivenum.h" #include diff --git a/src/frontend/mame/ui/custui.cpp b/src/frontend/mame/ui/custui.cpp index f8ad831aca2..763daf06b7f 100644 --- a/src/frontend/mame/ui/custui.cpp +++ b/src/frontend/mame/ui/custui.cpp @@ -16,6 +16,7 @@ #include "ui/selector.h" #include "ui/utils.h" +#include "corestr.h" #include "drivenum.h" #include "emuopts.h" #include "osdepend.h" diff --git a/src/frontend/mame/ui/dirmenu.cpp b/src/frontend/mame/ui/dirmenu.cpp index 6a7fa0c1aef..9d6fd462e74 100644 --- a/src/frontend/mame/ui/dirmenu.cpp +++ b/src/frontend/mame/ui/dirmenu.cpp @@ -18,6 +18,8 @@ #include "emuopts.h" #include "mame.h" +#include "corestr.h" + namespace ui { static int ADDING = 1; diff --git a/src/frontend/mame/ui/filesel.cpp b/src/frontend/mame/ui/filesel.cpp index 88d6027339e..b722afab60d 100644 --- a/src/frontend/mame/ui/filesel.cpp +++ b/src/frontend/mame/ui/filesel.cpp @@ -19,6 +19,7 @@ #include "imagedev/floppy.h" +#include "corestr.h" #include "zippath.h" #include diff --git a/src/frontend/mame/ui/imgcntrl.cpp b/src/frontend/mame/ui/imgcntrl.cpp index c0b5c44f1af..f9cdbd33db1 100644 --- a/src/frontend/mame/ui/imgcntrl.cpp +++ b/src/frontend/mame/ui/imgcntrl.cpp @@ -20,6 +20,7 @@ #include "audit.h" #include "drivenum.h" #include "emuopts.h" +#include "image.h" #include "softlist_dev.h" #include "zippath.h" @@ -61,11 +62,18 @@ menu_control_device_image::menu_control_device_image(mame_ui_manager &mui, rende if (m_image.exists()) { m_current_file.assign(m_image.filename()); - util::zippath_parent(m_current_directory, m_current_file); + m_current_directory = util::zippath_parent(m_current_file); } else { m_current_directory = m_image.working_directory(); + + // check to see if we've never initialized the working directory + if (m_current_directory.empty()) + { + m_current_directory = machine().image().setup_working_directory(); + m_image.set_working_directory(m_current_directory); + } } // check to see if the path exists; if not then set to current directory diff --git a/src/frontend/mame/ui/inifile.cpp b/src/frontend/mame/ui/inifile.cpp index 0d0e46b8f0d..0bf8c6548f5 100644 --- a/src/frontend/mame/ui/inifile.cpp +++ b/src/frontend/mame/ui/inifile.cpp @@ -13,6 +13,7 @@ #include "ui/moptions.h" +#include "corestr.h" #include "drivenum.h" #include "softlist_dev.h" diff --git a/src/frontend/mame/ui/menu.cpp b/src/frontend/mame/ui/menu.cpp index 76930eda029..2c0ee801f92 100644 --- a/src/frontend/mame/ui/menu.cpp +++ b/src/frontend/mame/ui/menu.cpp @@ -19,6 +19,7 @@ #include "cheat.h" #include "mame.h" +#include "corestr.h" #include "drivenum.h" #include "rendutil.h" #include "uiinput.h" diff --git a/src/frontend/mame/ui/miscmenu.cpp b/src/frontend/mame/ui/miscmenu.cpp index 1c917e3aefe..5dc40c53ee5 100644 --- a/src/frontend/mame/ui/miscmenu.cpp +++ b/src/frontend/mame/ui/miscmenu.cpp @@ -24,9 +24,10 @@ #include "pluginopts.h" #include "drivenum.h" #include "romload.h" - #include "uiinput.h" +#include "corestr.h" + #include #include #include diff --git a/src/frontend/mame/ui/selector.cpp b/src/frontend/mame/ui/selector.cpp index 56b0038c5c5..24de93987c8 100644 --- a/src/frontend/mame/ui/selector.cpp +++ b/src/frontend/mame/ui/selector.cpp @@ -13,6 +13,8 @@ #include "ui/ui.h" #include "ui/utils.h" + +#include "corestr.h" #include "unicode.h" diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp index b8575428925..1ac1a2f1523 100644 --- a/src/frontend/mame/ui/selgame.cpp +++ b/src/frontend/mame/ui/selgame.cpp @@ -25,6 +25,7 @@ #include "mame.h" #include "audit.h" +#include "corestr.h" #include "drivenum.h" #include "emuopts.h" #include "rendutil.h" @@ -1320,8 +1321,7 @@ bool menu_select_game::load_available_machines() std::unordered_set available; while (file.gets(rbuf, MAX_CHAR_INFO)) { - readbuf = rbuf; - strtrimspace(readbuf); + readbuf = strtrimspace(rbuf); if (readbuf.empty() || ('#' == readbuf[0])) // ignore empty lines and line comments ; diff --git a/src/frontend/mame/ui/selmenu.cpp b/src/frontend/mame/ui/selmenu.cpp index 8d893e8ba22..889a7601f3f 100644 --- a/src/frontend/mame/ui/selmenu.cpp +++ b/src/frontend/mame/ui/selmenu.cpp @@ -25,6 +25,7 @@ #include "mame.h" #include "mameopts.h" +#include "corestr.h" #include "drivenum.h" #include "emuopts.h" #include "rendfont.h" diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp index e59c8f9ee79..347d549daa8 100644 --- a/src/frontend/mame/ui/selsoft.cpp +++ b/src/frontend/mame/ui/selsoft.cpp @@ -17,6 +17,7 @@ #include "ui/selector.h" #include "audit.h" +#include "corestr.h" #include "drivenum.h" #include "emuopts.h" #include "mame.h" diff --git a/src/frontend/mame/ui/slotopt.cpp b/src/frontend/mame/ui/slotopt.cpp index 982a15d7a83..c6da9c7589f 100644 --- a/src/frontend/mame/ui/slotopt.cpp +++ b/src/frontend/mame/ui/slotopt.cpp @@ -85,7 +85,7 @@ device_slot_interface::slot_option const *menu_slot_devices::get_current_option( // set_slot_device //------------------------------------------------- -void menu_slot_devices::set_slot_device(device_slot_interface &slot, const char *val) +void menu_slot_devices::set_slot_device(device_slot_interface &slot, std::string_view val) { // we might change slot options; in the spirit of user friendliness, we should record all current // options @@ -320,7 +320,7 @@ void menu_slot_devices::rotate_slot_device(device_slot_interface &slot, menu_slo throw false; } - set_slot_device(slot, m_current_option_list_iter->c_str()); + set_slot_device(slot, *m_current_option_list_iter); } } // namespace ui diff --git a/src/frontend/mame/ui/slotopt.h b/src/frontend/mame/ui/slotopt.h index ecd44c177fd..ec8c08416cf 100644 --- a/src/frontend/mame/ui/slotopt.h +++ b/src/frontend/mame/ui/slotopt.h @@ -37,7 +37,7 @@ private: virtual void handle() override; device_slot_interface::slot_option const *get_current_option(device_slot_interface &slot) const; - void set_slot_device(device_slot_interface &slot, const char *val); + void set_slot_device(device_slot_interface &slot, std::string_view val); void record_current_options(); bool try_refresh_current_options(); void rotate_slot_device(device_slot_interface &slot, step_t step); diff --git a/src/frontend/mame/ui/state.cpp b/src/frontend/mame/ui/state.cpp index 81c210cced2..806e3535ebc 100644 --- a/src/frontend/mame/ui/state.cpp +++ b/src/frontend/mame/ui/state.cpp @@ -164,7 +164,7 @@ void menu_load_save_state_base::populate(float &customtop, float &custombottom) if (core_filename_ends_with(entry->name, ".sta")) { // get the file name of the entry - std::string file_name = core_filename_extract_base(entry->name, true); + std::string file_name(core_filename_extract_base(entry->name, true)); // try translating it std::string visible_name = get_visible_name(file_name); diff --git a/src/frontend/mame/ui/swlist.cpp b/src/frontend/mame/ui/swlist.cpp index 99ce1e5bc72..c373f9ff73b 100644 --- a/src/frontend/mame/ui/swlist.cpp +++ b/src/frontend/mame/ui/swlist.cpp @@ -14,6 +14,7 @@ #include "ui/swlist.h" #include "ui/utils.h" +#include "corestr.h" #include "softlist_dev.h" diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp index e2ea6745f86..37df0da6b1f 100644 --- a/src/frontend/mame/ui/ui.cpp +++ b/src/frontend/mame/ui/ui.cpp @@ -2308,7 +2308,7 @@ void mame_ui_manager::save_main_option() for (const auto &f_entry : machine().options().entries()) { const char *value = f_entry->value(); - if (value && options.exists(f_entry->name()) && strcmp(value, options.value(f_entry->name().c_str()))) + if (value && options.exists(f_entry->name()) && strcmp(value, options.value(f_entry->name()))) { options.set_value(f_entry->name(), *f_entry->value(), OPTION_PRIORITY_CMDLINE); } diff --git a/src/frontend/mame/ui/utils.cpp b/src/frontend/mame/ui/utils.cpp index 52833a37252..8cb109e955c 100644 --- a/src/frontend/mame/ui/utils.cpp +++ b/src/frontend/mame/ui/utils.cpp @@ -22,6 +22,8 @@ #include "romload.h" #include "softlist.h" +#include "corestr.h" + #include #include #include @@ -1584,8 +1586,7 @@ void software_filter_data::finalise() std::string software_filter_data::extract_region(std::string const &longname) { - std::string fullname(longname); - strmakelower(fullname); + std::string fullname(strmakelower(longname)); std::string::size_type const found(fullname.find('(')); if (found != std::string::npos) { diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp index cbe70bbf5fc..1149035045a 100644 --- a/src/lib/util/corefile.cpp +++ b/src/lib/util/corefile.cpp @@ -1256,7 +1256,7 @@ core_file::core_file() // assumptions about path separators // ------------------------------------------------- -std::string core_filename_extract_base(const std::string &name, bool strip_extension) +std::string_view core_filename_extract_base(std::string_view name, bool strip_extension) { // find the start of the basename auto const start = std::find_if(name.rbegin(), name.rend(), &util::is_directory_separator); @@ -1269,8 +1269,7 @@ std::string core_filename_extract_base(const std::string &name, bool strip_exten ? std::next(chop_position) : name.rbegin(); - // copy the result into an string - return std::string(start.base(), end.base()); + return std::string_view(&*start.base(), end.base() - start.base()); } @@ -1278,13 +1277,13 @@ std::string core_filename_extract_base(const std::string &name, bool strip_exten // core_filename_extract_extension // ------------------------------------------------- -std::string core_filename_extract_extension(const std::string &filename, bool strip_period) +std::string_view core_filename_extract_extension(std::string_view filename, bool strip_period) { auto loc = filename.find_last_of('.'); - std::string result = loc != std::string::npos - ? filename.substr(loc + (strip_period ? 1 : 0)) - : ""; - return result; + if (loc != std::string_view::npos) + return filename.substr(loc + (strip_period ? 1 : 0)); + else + return std::string_view(); } @@ -1293,7 +1292,7 @@ std::string core_filename_extract_extension(const std::string &filename, bool st // filename end with the specified extension? // ------------------------------------------------- -bool core_filename_ends_with(const std::string &filename, const std::string &extension) +bool core_filename_ends_with(std::string_view filename, std::string_view extension) { auto namelen = filename.length(); auto extlen = extension.length(); diff --git a/src/lib/util/corefile.h b/src/lib/util/corefile.h index a558a279324..6aaa8f609e1 100644 --- a/src/lib/util/corefile.h +++ b/src/lib/util/corefile.h @@ -157,13 +157,13 @@ constexpr bool is_directory_separator(char c) /* ----- filename utilities ----- */ // extract the base part of a filename (remove extensions and paths) -std::string core_filename_extract_base(const std::string &name, bool strip_extension = false); +std::string_view core_filename_extract_base(std::string_view name, bool strip_extension = false); // extracts the file extension from a filename -std::string core_filename_extract_extension(const std::string &filename, bool strip_period = false); +std::string_view core_filename_extract_extension(std::string_view filename, bool strip_period = false); // true if the given filename ends with a particular extension -bool core_filename_ends_with(const std::string &filename, const std::string &extension); +bool core_filename_ends_with(std::string_view filename, std::string_view extension); #endif // MAME_LIB_UTIL_COREFILE_H diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp index 1e89015d456..aff55470b13 100644 --- a/src/lib/util/corestr.cpp +++ b/src/lib/util/corestr.cpp @@ -11,6 +11,7 @@ #include "corestr.h" #include +#include #include #include @@ -125,8 +126,6 @@ bool core_iswildstr(const char *sp) std::string helpers -------------------------------------------------*/ -#include - void strdelchr(std::string& str, char chr) { for (size_t i = 0; i < str.length(); i++) @@ -147,10 +146,10 @@ void strreplacechr(std::string& str, char ch, char newch) } } -static std::string &internal_strtrimspace(std::string& str, bool right_only) +static std::string_view internal_strtrimspace(std::string_view str, bool right_only) { // identify the start - std::string::iterator start = str.begin(); + std::string_view::iterator start = str.begin(); if (!right_only) { start = std::find_if( @@ -160,48 +159,49 @@ static std::string &internal_strtrimspace(std::string& str, bool right_only) } // identify the end - std::string::iterator end = std::find_if( + std::string_view::iterator end = std::find_if( str.rbegin(), - std::string::reverse_iterator(start), + std::string_view::reverse_iterator(start), [](char c) { return !isspace(uint8_t(c)); }).base(); // extract the string - str = end > start + return end > start ? str.substr(start - str.begin(), end - start) - : ""; - return str; + : std::string_view(); } -std::string &strtrimspace(std::string& str) +std::string_view strtrimspace(std::string_view str) { return internal_strtrimspace(str, false); } -std::string &strtrimrightspace(std::string& str) +std::string_view strtrimrightspace(std::string_view str) { return internal_strtrimspace(str, true); } -std::string &strmakeupper(std::string& str) +std::string strmakeupper(std::string_view str) { - std::transform(str.begin(), str.end(), str.begin(), ::toupper); - return str; + std::string result; + std::transform(str.begin(), str.end(), std::back_inserter(result), ::toupper); + return result; } /** - * @fn std::string &strmakelower(std::string& str) + * @fn std::string &strmakelower(std::string_view str) * - * @brief Changes the given string to lower case. + * @brief Returns a lower case version of the given string. * * @param [in,out] str The string to make lower case * - * @return A reference to the original std::string having been changed to lower case + * @return A new std::string having been changed to lower case */ -std::string &strmakelower(std::string& str) +std::string strmakelower(std::string_view str) { - std::transform(str.begin(), str.end(), str.begin(), ::tolower); - return str; + std::string result; + std::transform(str.begin(), str.end(), std::back_inserter(result), ::tolower); + return result; } /** @@ -233,7 +233,7 @@ int strreplace(std::string &str, const std::string& search, const std::string& r namespace util { /** - * @fn double edit_distance(std::u32string const &lhs, std::u32string const &rhs) + * @fn double edit_distance(std::u32string_view lhs, std::u32string_view rhs) * * @brief Compares strings and returns prefix-weighted similarity score (smaller is more similar). * @@ -243,7 +243,7 @@ namespace util { * @return Similarity score ranging from 0.0 (totally dissimilar) to 1.0 (identical). */ -double edit_distance(std::u32string const &lhs, std::u32string const &rhs) +double edit_distance(std::u32string_view lhs, std::u32string_view rhs) { // based on Jaro-Winkler distance // TODO: this breaks if the lengths don't fit in a long int, but that's not a big limitation @@ -251,8 +251,8 @@ double edit_distance(std::u32string const &lhs, std::u32string const &rhs) constexpr double PREFIX_WEIGHT(0.1); constexpr double PREFIX_THRESHOLD(0.7); - std::u32string const &longer((lhs.length() >= rhs.length()) ? lhs : rhs); - std::u32string const &shorter((lhs.length() < rhs.length()) ? lhs : rhs); + std::u32string_view const &longer((lhs.length() >= rhs.length()) ? lhs : rhs); + std::u32string_view const &shorter((lhs.length() < rhs.length()) ? lhs : rhs); // find matches long const range((std::max)(long(longer.length() / 2) - 1, 0L)); diff --git a/src/lib/util/corestr.h b/src/lib/util/corestr.h index de294c0665c..81b04eeebaf 100644 --- a/src/lib/util/corestr.h +++ b/src/lib/util/corestr.h @@ -14,6 +14,7 @@ #pragma once #include +#include #include @@ -53,16 +54,16 @@ bool core_iswildstr(const char *sp); void strdelchr(std::string& str, char chr); void strreplacechr(std::string& str, char ch, char newch); -std::string &strtrimspace(std::string& str); -std::string &strtrimrightspace(std::string& str); -std::string &strmakeupper(std::string& str); -std::string &strmakelower(std::string& str); +[[nodiscard]] std::string_view strtrimspace(std::string_view str); +[[nodiscard]] std::string_view strtrimrightspace(std::string_view str); +[[nodiscard]] std::string strmakeupper(std::string_view str); +[[nodiscard]] std::string strmakelower(std::string_view str); int strreplace(std::string &str, const std::string& search, const std::string& replace); namespace util { // based on Jaro-Winkler distance - returns value from 0.0 (totally dissimilar) to 1.0 (identical) -double edit_distance(std::u32string const &lhs, std::u32string const &rhs); +double edit_distance(std::u32string_view lhs, std::u32string_view rhs); } // namespace util diff --git a/src/lib/util/hash.cpp b/src/lib/util/hash.cpp index 5f2fd6f267a..a521e737192 100644 --- a/src/lib/util/hash.cpp +++ b/src/lib/util/hash.cpp @@ -11,7 +11,6 @@ ***************************************************************************/ #include "hash.h" -#include "corestr.h" #include #include @@ -45,7 +44,7 @@ hash_collection::hash_collection() } -hash_collection::hash_collection(const char *string) +hash_collection::hash_collection(std::string_view string) : m_has_crc32(false), m_has_sha1(false), m_creator(nullptr) @@ -237,7 +236,13 @@ std::string hash_collection::macro_string() const buffer.append("NO_DUMP "); if (flag(FLAG_BAD_DUMP)) buffer.append("BAD_DUMP "); - strtrimspace(buffer); + + // remove trailing space + if (!buffer.empty()) + { + assert(buffer.back() == ' '); + buffer = buffer.substr(0, buffer.length() - 1); + } return buffer; } @@ -264,7 +269,10 @@ std::string hash_collection::attribute_string() const buffer.append("status=\"nodump\""); if (flag(FLAG_BAD_DUMP)) buffer.append("status=\"baddump\""); - strtrimspace(buffer); + + // remove trailing space + if (!buffer.empty() && buffer.back() == ' ') + buffer = buffer.substr(0, buffer.length() - 1); return buffer; } diff --git a/src/lib/util/hash.h b/src/lib/util/hash.h index 891f8f3c44b..b13ac5556ae 100644 --- a/src/lib/util/hash.h +++ b/src/lib/util/hash.h @@ -56,7 +56,7 @@ public: // construction/destruction hash_collection(); - hash_collection(const char *string); + hash_collection(std::string_view string); hash_collection(const hash_collection &src); ~hash_collection(); diff --git a/src/lib/util/options.cpp b/src/lib/util/options.cpp index 7aa8817f580..e1674a88fe1 100644 --- a/src/lib/util/options.cpp +++ b/src/lib/util/options.cpp @@ -10,6 +10,7 @@ #include "options.h" +#include "corefile.h" #include "corestr.h" #include "osdcomm.h" @@ -55,17 +56,19 @@ const char *const core_options::s_option_unadorned[MAX_UNADORNED_OPTIONS] = namespace { - void trim_spaces_and_quotes(std::string &data) + std::string_view trim_spaces_and_quotes(std::string_view data) { // trim any whitespace - strtrimspace(data); + data = strtrimspace(data); // trim quotes - if (data.find_first_of('"') == 0 && data.find_last_of('"') == data.length() - 1) + if (data.length() >= 2 && data.front() == '"' && data.back() == '"') { - data.erase(0, 1); - data.erase(data.length() - 1, 1); + data.remove_prefix(1); + data.remove_suffix(1); } + + return data; } }; @@ -451,11 +454,7 @@ void core_options::add_entry(entry::shared_ptr &&entry, const char *after_header for (const std::string &name : entry->names()) { // append the entry - add_to_entry_map(std::string(name), entry); - - // for booleans, add the "-noXYZ" option as well - if (entry->type() == option_type::BOOLEAN) - add_to_entry_map(std::string("no") + name, entry); + add_to_entry_map(name, entry); } // and add the entry to the vector @@ -468,13 +467,13 @@ void core_options::add_entry(entry::shared_ptr &&entry, const char *after_header // map //------------------------------------------------- -void core_options::add_to_entry_map(std::string &&name, entry::shared_ptr &entry) +void core_options::add_to_entry_map(const std::string &name, entry::shared_ptr &entry) { // it is illegal to call this method for something that already exists assert(m_entrymap.find(name) == m_entrymap.end()); // append the entry - m_entrymap.emplace(std::make_pair(name, entry::weak_ptr(entry))); + m_entrymap.emplace(std::make_pair(std::string_view(name), entry::weak_ptr(entry))); } @@ -493,26 +492,39 @@ void core_options::add_entry(const options_entry &opt, bool override_existing) { // first extract any range std::string namestr(opt.name); - int lparen = namestr.find_first_of('(', 0); - int dash = namestr.find_first_of('-', lparen + 1); - int rparen = namestr.find_first_of(')', dash + 1); - if (lparen != -1 && dash != -1 && rparen != -1) + std::string::size_type lparen = namestr.find_first_of('(', 0); + if (lparen != std::string::npos) { - strtrimspace(minimum.assign(namestr.substr(lparen + 1, dash - (lparen + 1)))); - strtrimspace(maximum.assign(namestr.substr(dash + 1, rparen - (dash + 1)))); - namestr.erase(lparen, rparen + 1 - lparen); + std::string::size_type dash = namestr.find_first_of('-', lparen + 1); + if (dash != std::string::npos) + { + std::string::size_type rparen = namestr.find_first_of(')', dash + 1); + if (rparen != std::string::npos) + { + minimum.assign(strtrimspace(std::string_view(&namestr[lparen + 1], dash - (lparen + 1)))); + maximum.assign(strtrimspace(std::string_view(&namestr[dash + 1], rparen - (dash + 1)))); + namestr.erase(lparen, rparen + 1 - lparen); + } + } } // then chop up any semicolon-separated names - size_t semi; + std::string::size_type semi; while ((semi = namestr.find_first_of(';')) != std::string::npos) { names.push_back(namestr.substr(0, semi)); + + // for booleans, add the "-noXYZ" option as well + if (opt.type == option_type::BOOLEAN) + names.push_back(std::string("no") + names.back()); + namestr.erase(0, semi + 1); } // finally add the last item names.push_back(std::move(namestr)); + if (opt.type == option_type::BOOLEAN) + names.push_back(std::string("no") + names.back()); } // we might be called with an existing entry @@ -597,10 +609,12 @@ void core_options::add_entries(const options_entry *entrylist, bool override_exi // of an option //------------------------------------------------- -void core_options::set_default_value(const char *name, const char *defvalue) +void core_options::set_default_value(std::string_view name, std::string &&defvalue) { // update the data and default data - get_entry(name)->set_default_value(defvalue); + auto entry = get_entry(name); + assert(entry != nullptr); + entry->set_default_value(std::move(defvalue)); } @@ -609,10 +623,12 @@ void core_options::set_default_value(const char *name, const char *defvalue) // of an option //------------------------------------------------- -void core_options::set_description(const char *name, const char *description) +void core_options::set_description(std::string_view name, const char *description) { // update the data and default data - get_entry(name)->set_description(description); + auto entry = get_entry(name); + assert(entry != nullptr); + entry->set_description(description); } @@ -677,7 +693,7 @@ void core_options::parse_command_line(const std::vector &args, int continue; // get the data for this argument, special casing booleans - std::string newdata; + std::string_view newdata; if (curentry->type() == option_type::BOOLEAN) { newdata = (strncmp(&curarg[1], "no", 2) == 0) ? "0" : "1"; @@ -696,7 +712,7 @@ void core_options::parse_command_line(const std::vector &args, int } // set the new data - do_set_value(*curentry, std::move(newdata), priority, error_stream, condition); + do_set_value(*curentry, newdata, priority, error_stream, condition); } // did we have any errors that may need to be aggregated? @@ -770,9 +786,7 @@ void core_options::parse_ini_file(util::core_file &inifile, int priority, bool i } // set the new data - std::string data = optiondata; - trim_spaces_and_quotes(data); - do_set_value(*curentry, std::move(data), priority, error_stream, condition); + do_set_value(*curentry, trim_spaces_and_quotes(optiondata), priority, error_stream, condition); } // did we have any errors that may need to be aggregated? @@ -925,7 +939,7 @@ std::string core_options::output_help() const // value - return the raw option value //------------------------------------------------- -const char *core_options::value(const char *option) const noexcept +const char *core_options::value(std::string_view option) const noexcept { auto const entry = get_entry(option); return entry ? entry->value() : nullptr; @@ -936,7 +950,7 @@ const char *core_options::value(const char *option) const noexcept // description - return description of option //------------------------------------------------- -const char *core_options::description(const char *option) const noexcept +const char *core_options::description(std::string_view option) const noexcept { auto const entry = get_entry(option); return entry ? entry->description() : nullptr; @@ -947,7 +961,7 @@ const char *core_options::description(const char *option) const noexcept // value - return the option value as an integer //------------------------------------------------- -int core_options::int_value(const char *option) const +int core_options::int_value(std::string_view option) const { char const *const data = value(option); if (!data) @@ -966,7 +980,7 @@ int core_options::int_value(const char *option) const // value - return the option value as a float //------------------------------------------------- -float core_options::float_value(const char *option) const +float core_options::float_value(std::string_view option) const { char const *const data = value(option); if (!data) @@ -989,22 +1003,29 @@ float core_options::float_value(const char *option) const // set_value - set the raw option value //------------------------------------------------- -void core_options::set_value(const std::string &name, const std::string &value, int priority) +void core_options::set_value(std::string_view name, std::string_view value, int priority) +{ + set_value(name, std::string(value), priority); +} + +void core_options::set_value(std::string_view name, const char *value, int priority) { set_value(name, std::string(value), priority); } -void core_options::set_value(const std::string &name, std::string &&value, int priority) +void core_options::set_value(std::string_view name, std::string &&value, int priority) { - get_entry(name)->set_value(std::move(value), priority); + auto entry = get_entry(name); + assert(entry != nullptr); + entry->set_value(std::move(value), priority); } -void core_options::set_value(const std::string &name, int value, int priority) +void core_options::set_value(std::string_view name, int value, int priority) { set_value(name, util::string_format("%d", value), priority); } -void core_options::set_value(const std::string &name, float value, int priority) +void core_options::set_value(std::string_view name, float value, int priority) { set_value(name, util::string_format("%f", value), priority); } @@ -1037,13 +1058,13 @@ void core_options::remove_entry(core_options::entry &delentry) // do_set_value //------------------------------------------------- -void core_options::do_set_value(entry &curentry, std::string &&data, int priority, std::ostream &error_stream, condition_type &condition) +void core_options::do_set_value(entry &curentry, std::string_view data, int priority, std::ostream &error_stream, condition_type &condition) { // this is called when parsing a command line or an INI - we want to catch the option_exception and write // any exception messages to the error stream try { - curentry.set_value(std::move(data), priority); + curentry.set_value(std::string(data), priority); } catch (options_warning_exception &ex) { @@ -1064,13 +1085,13 @@ void core_options::do_set_value(entry &curentry, std::string &&data, int priorit // get_entry //------------------------------------------------- -core_options::entry::shared_const_ptr core_options::get_entry(const std::string &name) const noexcept +core_options::entry::shared_const_ptr core_options::get_entry(std::string_view name) const noexcept { auto curentry = m_entrymap.find(name); return (curentry != m_entrymap.end()) ? curentry->second.lock() : nullptr; } -core_options::entry::shared_ptr core_options::get_entry(const std::string &name) noexcept +core_options::entry::shared_ptr core_options::get_entry(std::string_view name) noexcept { auto curentry = m_entrymap.find(name); return (curentry != m_entrymap.end()) ? curentry->second.lock() : nullptr; @@ -1081,9 +1102,11 @@ core_options::entry::shared_ptr core_options::get_entry(const std::string &name) // set_value_changed_handler //------------------------------------------------- -void core_options::set_value_changed_handler(const std::string &name, std::function &&handler) +void core_options::set_value_changed_handler(std::string_view name, std::function &&handler) { - get_entry(name)->set_value_changed_handler(std::move(handler)); + auto entry = get_entry(name); + assert(entry != nullptr); + entry->set_value_changed_handler(std::move(handler)); } diff --git a/src/lib/util/options.h b/src/lib/util/options.h index fc742ceb6c9..9b43e771c51 100644 --- a/src/lib/util/options.h +++ b/src/lib/util/options.h @@ -11,14 +11,17 @@ #ifndef MAME_LIB_UTIL_OPTIONS_H #define MAME_LIB_UTIL_OPTIONS_H -#include "corefile.h" +#include "strformat.h" + #include +#include #include +#include #include #include #include -#include #include +#include #include #include @@ -40,6 +43,7 @@ const int OPTION_PRIORITY_MAXIMUM = 255; // maximum priority //************************************************************************** struct options_entry; +namespace util { class core_file; } // exception thrown by core_options when an illegal request is made class options_exception : public std::exception @@ -146,7 +150,7 @@ public: private: void validate(const std::string &value); - std::vector m_names; + const std::vector m_names; int m_priority; core_options::option_type m_type; const char * m_description; @@ -164,10 +168,10 @@ public: // getters const std::string &command() const noexcept { return m_command; } const std::vector &command_arguments() const noexcept { assert(!m_command.empty()); return m_command_arguments; } - entry::shared_const_ptr get_entry(const std::string &name) const noexcept; - entry::shared_ptr get_entry(const std::string &name) noexcept; + entry::shared_const_ptr get_entry(std::string_view name) const noexcept; + entry::shared_ptr get_entry(std::string_view name) noexcept; const std::vector &entries() const noexcept { return m_entries; } - bool exists(const std::string &name) const noexcept { return get_entry(name) != nullptr; } + bool exists(std::string_view name) const noexcept { return get_entry(name) != nullptr; } bool header_exists(const char *description) const noexcept; // configuration @@ -176,10 +180,12 @@ public: void add_entry(std::vector &&names, const char *description, option_type type, std::string &&default_value = "", std::string &&minimum = "", std::string &&maximum = ""); void add_header(const char *description); void add_entries(const options_entry *entrylist, bool override_existing = false); - void set_default_value(const char *name, const char *defvalue); - void set_description(const char *name, const char *description); + void set_default_value(std::string_view name, std::string &&defvalue); + void set_default_value(std::string_view name, std::string_view defvalue) { set_default_value(name, std::string(defvalue)); } + void set_default_value(std::string_view name, const char *defvalue) { set_default_value(name, std::string(defvalue)); } + void set_description(std::string_view name, const char *description); void remove_entry(entry &delentry); - void set_value_changed_handler(const std::string &name, std::function &&handler); + void set_value_changed_handler(std::string_view name, std::function &&handler); void revert(int priority_hi = OPTION_PRIORITY_MAXIMUM, int priority_lo = OPTION_PRIORITY_DEFAULT); // parsing/input @@ -192,17 +198,18 @@ public: std::string output_help() const; // reading - const char *value(const char *option) const noexcept; - const char *description(const char *option) const noexcept; - bool bool_value(const char *option) const { return int_value(option) != 0; } - int int_value(const char *option) const; - float float_value(const char *option) const; + const char *value(std::string_view option) const noexcept; + const char *description(std::string_view option) const noexcept; + bool bool_value(std::string_view option) const { return int_value(option) != 0; } + int int_value(std::string_view option) const; + float float_value(std::string_view option) const; // setting - void set_value(const std::string &name, const std::string &value, int priority); - void set_value(const std::string &name, std::string &&value, int priority); - void set_value(const std::string &name, int value, int priority); - void set_value(const std::string &name, float value, int priority); + void set_value(std::string_view name, std::string_view value, int priority); + void set_value(std::string_view name, const char *value, int priority); + void set_value(std::string_view name, std::string &&value, int priority); + void set_value(std::string_view name, int value, int priority); + void set_value(std::string_view name, float value, int priority); // misc static const char *unadorned(int x = 0) noexcept { return s_option_unadorned[std::min(x, MAX_UNADORNED_OPTIONS - 1)]; } @@ -251,13 +258,13 @@ private: }; // internal helpers - void add_to_entry_map(std::string &&name, entry::shared_ptr &entry); - void do_set_value(entry &curentry, std::string &&data, int priority, std::ostream &error_stream, condition_type &condition); + void add_to_entry_map(const std::string &name, entry::shared_ptr &entry); + void do_set_value(entry &curentry, std::string_view data, int priority, std::ostream &error_stream, condition_type &condition); void throw_options_exception_if_appropriate(condition_type condition, std::ostringstream &error_stream); // internal state std::vector m_entries; // canonical list of entries - std::unordered_map m_entrymap; // map for fast lookup + std::unordered_map m_entrymap; // map for fast lookup std::string m_command; // command found std::vector m_command_arguments; // command arguments static const char *const s_option_unadorned[]; // array of unadorned option "names" diff --git a/src/lib/util/zippath.cpp b/src/lib/util/zippath.cpp index 27e5f123576..01d708bf2e1 100644 --- a/src/lib/util/zippath.cpp +++ b/src/lib/util/zippath.cpp @@ -65,7 +65,7 @@ bool is_root(std::string_view path) // 7-zip file // ------------------------------------------------- -bool is_7z_file(std::string const &path) +bool is_7z_file(std::string_view path) { return core_filename_ends_with(path, ".7z"); } @@ -76,7 +76,7 @@ bool is_7z_file(std::string const &path) // ZIP file // ------------------------------------------------- -bool is_zip_file(std::string const &path) +bool is_zip_file(std::string_view path) { return core_filename_ends_with(path, ".zip"); } @@ -593,7 +593,7 @@ zippath_directory::~zippath_directory() // zippath_parent - retrieves the parent directory // ------------------------------------------------- -std::string &zippath_parent(std::string &dst, std::string_view path) +std::string zippath_parent(std::string_view path) { // skip over trailing path separators std::string_view::size_type pos = path.find_last_not_of(PATH_SEPARATOR); @@ -603,23 +603,9 @@ std::string &zippath_parent(std::string &dst, std::string_view path) pos = (pos > 0) ? pos - 1 : std::string_view::npos; if (pos != std::string_view::npos) - dst = std::string(path, 0, pos + 1); + return std::string(path, 0, pos + 1); else - dst = std::string(); - return dst; -} - - - -// ------------------------------------------------- -// zippath_parent - retrieves the parent directory -// ------------------------------------------------- - -std::string zippath_parent(std::string_view path) -{ - std::string result; - zippath_parent(result, path); - return result; + return std::string(); } diff --git a/src/lib/util/zippath.h b/src/lib/util/zippath.h index 6e0e4623996..1eb92aa1c1d 100644 --- a/src/lib/util/zippath.h +++ b/src/lib/util/zippath.h @@ -53,7 +53,6 @@ public: // ----- path operations ----- // retrieves the parent directory -std::string &zippath_parent(std::string &dst, std::string_view path); std::string zippath_parent(std::string_view path); // combines two paths diff --git a/src/mame/drivers/esq5505.cpp b/src/mame/drivers/esq5505.cpp index eee7fd1fdae..211a082c5bc 100644 --- a/src/mame/drivers/esq5505.cpp +++ b/src/mame/drivers/esq5505.cpp @@ -323,7 +323,7 @@ void esq5505_state::machine_reset() // on VFX, bit 0 is 1 for 'cartridge present'. // on VFX-SD and later, bit 0 is2 1 for floppy present, bit 1 is 1 for cartridge present - if (core_stricmp(machine().system().name, "vfx") == 0) + if (strcmp(machine().system().name, "vfx") == 0) { // todo: handle VFX cart-in when we support cartridges m_duart->ip0_w(ASSERT_LINE); diff --git a/src/mame/machine/bfm_sc45_helper.cpp b/src/mame/machine/bfm_sc45_helper.cpp index a815759bc63..7e735e59dc7 100644 --- a/src/mame/machine/bfm_sc45_helper.cpp +++ b/src/mame/machine/bfm_sc45_helper.cpp @@ -6,6 +6,7 @@ */ #include "emu.h" +#include "corestr.h" //#define sc45helperlog printf #define sc45helperlog machine.logerror @@ -209,8 +210,7 @@ int find_input_strings(running_machine &machine) } - strtrimspace(tempstring); - strmakelower(tempstring); + tempstring = strmakelower(strtrimspace(tempstring)); //if (pos <= 5) @@ -498,8 +498,7 @@ int find_lamp_strings(running_machine &machine) lamps[row][col].lampname = tempstring; lamps[row][col].lamptypename = "matrixlamp"; - strtrimspace(lamps[row][col].lampname); - strmakelower(lamps[row][col].lampname); + lamps[row][col].lampname = strmakelower(strtrimspace(lamps[row][col].lampname)); } else { @@ -895,8 +894,7 @@ int find_reel_strings(running_machine &machine) } - strtrimspace(tempstring); - strmakelower(tempstring); + tempstring = strmakelower(strtrimspace(tempstring)); if (tempstring[0] == '!') { diff --git a/src/mame/machine/lynx.cpp b/src/mame/machine/lynx.cpp index 3f8fa1200a3..161359d5d11 100644 --- a/src/mame/machine/lynx.cpp +++ b/src/mame/machine/lynx.cpp @@ -7,6 +7,8 @@ #include "emu.h" #include "includes/lynx.h" #include "cpu/m6502/m65sc02.h" + +#include "corestr.h" #include "render.h" #define PAD_UP 0x80 diff --git a/src/mame/machine/spec_snqk.cpp b/src/mame/machine/spec_snqk.cpp index f5b4dc5f3c0..e714fc0be5d 100644 --- a/src/mame/machine/spec_snqk.cpp +++ b/src/mame/machine/spec_snqk.cpp @@ -36,6 +36,7 @@ #include "includes/specpls3.h" #include "sound/ay8910.h" #include "machine/spec_snqk.h" +#include "corestr.h" #define EXEC_NA "N/A" diff --git a/src/osd/mac/macmain.cpp b/src/osd/mac/macmain.cpp index 40bcd7d1882..fb7f1f620c3 100644 --- a/src/osd/mac/macmain.cpp +++ b/src/osd/mac/macmain.cpp @@ -17,6 +17,7 @@ #include // MAME headers +#include "corestr.h" #include "osdepend.h" #include "emu.h" #include "emuopts.h" @@ -58,7 +59,7 @@ mac_options::mac_options() std::string ini_path(INI_PATH); add_entries(mac_options::s_option_entries); strreplace(ini_path,"APP_NAME", emulator_info::get_appname_lower()); - set_default_value(MACOPTION_INIPATH, ini_path.c_str()); + set_default_value(MACOPTION_INIPATH, std::move(ini_path)); } //============================================================ diff --git a/src/osd/modules/diagnostics/diagnostics_win32.cpp b/src/osd/modules/diagnostics/diagnostics_win32.cpp index e76f3ca6d70..c132afb4b97 100644 --- a/src/osd/modules/diagnostics/diagnostics_win32.cpp +++ b/src/osd/modules/diagnostics/diagnostics_win32.cpp @@ -9,6 +9,8 @@ #include "emu.h" #include "diagnostics_module.h" +#include "corestr.h" + #if defined(OSD_WINDOWS) || defined(SDLMAME_WIN32) // standard windows headers @@ -529,7 +531,7 @@ bool symbol_manager::parse_sym_line(const char *line, uintptr_t &address, std::s chptr++; // extract the symbol name - strtrimspace(symbol.assign(chptr)); + symbol.assign(strtrimspace(chptr))); return (symbol.length() > 0); } } @@ -569,7 +571,7 @@ bool symbol_manager::parse_map_line(const char *line, uintptr_t &address, std::s chptr++; // extract the symbol name - strtrimspace(symbol.assign(chptr)); + symbol.assign(strtrimspace(chptr)); return (symbol.length() > 0); } #endif diff --git a/src/osd/modules/font/font_osx.cpp b/src/osd/modules/font/font_osx.cpp index 42c61b1fa6d..327c6f1244b 100644 --- a/src/osd/modules/font/font_osx.cpp +++ b/src/osd/modules/font/font_osx.cpp @@ -56,7 +56,7 @@ bool osd_font_osx::open(std::string const &font_path, std::string const &name, i osd_printf_verbose("osd_font_osx::open: name=\"%s\"\n", name); CFStringRef font_name; - if (!strcmp(name.c_str(), "default")) + if (name == "default") { // Arial Unicode MS comes with Mac OS X 10.5 and later and is the only Mac default font with // the Unicode characters used by the vgmplay and aristmk5 layouts. diff --git a/src/osd/modules/font/font_sdl.cpp b/src/osd/modules/font/font_sdl.cpp index 585673a4159..56663bb7df7 100644 --- a/src/osd/modules/font/font_sdl.cpp +++ b/src/osd/modules/font/font_sdl.cpp @@ -89,8 +89,8 @@ bool osd_font_sdl::open(std::string const &font_path, std::string const &_name, { osd_printf_verbose("Searching font %s in -%s path/s\n", family, font_path); //emu_file file(options().font_path(), OPEN_FLAG_READ); - emu_file file(font_path.c_str(), OPEN_FLAG_READ); - if (file.open(family.c_str()) == osd_file::error::NONE) + emu_file file(font_path, OPEN_FLAG_READ); + if (file.open(family) == osd_file::error::NONE) { std::string full_name = file.fullpath(); font = TTF_OpenFont_Magic(full_name, POINT_SIZE, 0); @@ -193,7 +193,7 @@ bool osd_font_sdl::get_bitmap(char32_t chnum, bitmap_argb32 &bitmap, std::int32_ osd_font_sdl::TTF_Font_ptr osd_font_sdl::TTF_OpenFont_Magic(std::string const &name, int fsize, long index) { emu_file file(OPEN_FLAG_READ); - if (file.open(name.c_str()) == osd_file::error::NONE) + if (file.open(name) == osd_file::error::NONE) { unsigned char const ttf_magic[] = { 0x00, 0x01, 0x00, 0x00, 0x00 }; unsigned char const ttc1_magic[] = { 0x74, 0x74, 0x63, 0x66, 0x00, 0x01, 0x00, 0x00 }; @@ -214,7 +214,7 @@ osd_font_sdl::TTF_Font_ptr osd_font_sdl::TTF_OpenFont_Magic(std::string const &n bool osd_font_sdl::BDF_Check_Magic(std::string const &name) { emu_file file(OPEN_FLAG_READ); - if (file.open(name.c_str()) == osd_file::error::NONE) + if (file.open(name) == osd_file::error::NONE) { unsigned char const magic[] = { 'S', 'T', 'A', 'R', 'T', 'F', 'O', 'N', 'T' }; unsigned char buffer[sizeof(magic)]; diff --git a/src/osd/modules/lib/osdobj_common.cpp b/src/osd/modules/lib/osdobj_common.cpp index a04952bcdbc..932beed416b 100644 --- a/src/osd/modules/lib/osdobj_common.cpp +++ b/src/osd/modules/lib/osdobj_common.cpp @@ -678,7 +678,7 @@ void osd_common_t::init_subsystems() m_output = select_module_options(options(), OSD_OUTPUT_PROVIDER); m_output->set_machine(&machine()); - machine().output().set_notifier(nullptr, output_notifier_callback, this); + machine().output().set_global_notifier(output_notifier_callback, this); m_mod_man.init(options()); diff --git a/src/osd/modules/lib/osdobj_common.h b/src/osd/modules/lib/osdobj_common.h index 2df6a91b827..9eeffe7c7b9 100644 --- a/src/osd/modules/lib/osdobj_common.h +++ b/src/osd/modules/lib/osdobj_common.h @@ -129,10 +129,10 @@ public: const char *aspect() const { return value(OSDOPTION_ASPECT); } const char *resolution() const { return value(OSDOPTION_RESOLUTION); } const char *view() const { return value(OSDOPTION_VIEW); } - const char *screen(int index) const { return value(string_format("%s%d", OSDOPTION_SCREEN, index).c_str()); } - const char *aspect(int index) const { return value(string_format("%s%d", OSDOPTION_ASPECT, index).c_str()); } - const char *resolution(int index) const { return value(string_format("%s%d", OSDOPTION_RESOLUTION, index).c_str()); } - const char *view(int index) const { return value(string_format("%s%d", OSDOPTION_VIEW, index).c_str()); } + const char *screen(int index) const { return value(string_format("%s%d", OSDOPTION_SCREEN, index)); } + const char *aspect(int index) const { return value(string_format("%s%d", OSDOPTION_ASPECT, index)); } + const char *resolution(int index) const { return value(string_format("%s%d", OSDOPTION_RESOLUTION, index)); } + const char *view(int index) const { return value(string_format("%s%d", OSDOPTION_VIEW, index)); } // full screen options bool switch_res() const { return bool_value(OSDOPTION_SWITCHRES); } @@ -148,8 +148,8 @@ public: bool gl_pbo() const { return bool_value(OSDOPTION_GL_PBO); } bool gl_glsl() const { return bool_value(OSDOPTION_GL_GLSL); } int glsl_filter() const { return int_value(OSDOPTION_GLSL_FILTER); } - const char *shader_mame(int index) const { return value(string_format("%s%d", OSDOPTION_SHADER_MAME, index).c_str()); } - const char *shader_screen(int index) const { return value(string_format("%s%d", OSDOPTION_SHADER_SCREEN, index).c_str()); } + const char *shader_mame(int index) const { return value(string_format("%s%d", OSDOPTION_SHADER_MAME, index)); } + const char *shader_screen(int index) const { return value(string_format("%s%d", OSDOPTION_SHADER_SCREEN, index)); } // sound options const char *sound() const { return value(OSDOPTION_SOUND); } @@ -157,7 +157,7 @@ public: // CoreAudio specific options const char *audio_output() const { return value(OSDOPTION_AUDIO_OUTPUT); } - const char *audio_effect(int index) const { return value(string_format("%s%d", OSDOPTION_AUDIO_EFFECT, index).c_str()); } + const char *audio_effect(int index) const { return value(string_format("%s%d", OSDOPTION_AUDIO_EFFECT, index)); } // BGFX specific options const char *bgfx_path() const { return value(OSDOPTION_BGFX_PATH); } @@ -274,7 +274,7 @@ private: // FIXME: should be elsewhere osd_module *select_module_options(const core_options &opts, const std::string &opt_name) { - std::string opt_val = opts.exists(opt_name) ? opts.value(opt_name.c_str()) : ""; + std::string opt_val = opts.exists(opt_name) ? opts.value(opt_name) : ""; if (opt_val.compare("auto")==0) opt_val = ""; else if (!m_mod_man.type_has_name(opt_name.c_str(), opt_val.c_str())) diff --git a/src/osd/modules/render/bgfx/texturemanager.cpp b/src/osd/modules/render/bgfx/texturemanager.cpp index d539d1aae46..082662658f6 100644 --- a/src/osd/modules/render/bgfx/texturemanager.cpp +++ b/src/osd/modules/render/bgfx/texturemanager.cpp @@ -58,7 +58,7 @@ bgfx_texture* texture_manager::create_texture(std::string name, bgfx::TextureFor bgfx_texture* texture_manager::create_png_texture(std::string path, std::string file_name, std::string texture_name, uint32_t flags, uint32_t screen) { bitmap_argb32 bitmap; - emu_file file(path.c_str(), OPEN_FLAG_READ); + emu_file file(path, OPEN_FLAG_READ); if (file.open(file_name) == osd_file::error::NONE) { render_load_png(bitmap, file); diff --git a/src/osd/sdl/osdsdl.h b/src/osd/sdl/osdsdl.h index 4cbec2d9d14..126b007d331 100644 --- a/src/osd/sdl/osdsdl.h +++ b/src/osd/sdl/osdsdl.h @@ -96,11 +96,11 @@ public: const char *keymap_file() const { return value(SDLOPTION_KEYMAP_FILE); } // joystick mapping - const char *joy_index(int index) const { return value(string_format("%s%d", SDLOPTION_JOYINDEX, index).c_str()); } + const char *joy_index(int index) const { return value(string_format("%s%d", SDLOPTION_JOYINDEX, index)); } bool sixaxis() const { return bool_value(SDLOPTION_SIXAXIS); } - const char *mouse_index(int index) const { return value(string_format("%s%d", SDLOPTION_MOUSEINDEX, index).c_str()); } - const char *keyboard_index(int index) const { return value(string_format("%s%d", SDLOPTION_KEYBINDEX, index).c_str()); } + const char *mouse_index(int index) const { return value(string_format("%s%d", SDLOPTION_MOUSEINDEX, index)); } + const char *keyboard_index(int index) const { return value(string_format("%s%d", SDLOPTION_KEYBINDEX, index)); } const char *video_driver() const { return value(SDLOPTION_VIDEODRIVER); } const char *render_driver() const { return value(SDLOPTION_RENDERDRIVER); } diff --git a/src/osd/sdl/sdlmain.cpp b/src/osd/sdl/sdlmain.cpp index 5e0b12cef3b..f12e2fcb786 100644 --- a/src/osd/sdl/sdlmain.cpp +++ b/src/osd/sdl/sdlmain.cpp @@ -36,6 +36,7 @@ #include // MAME headers +#include "corestr.h" #include "osdepend.h" #include "emu.h" #include "emuopts.h" @@ -170,7 +171,7 @@ sdl_options::sdl_options() std::string ini_path(INI_PATH); add_entries(sdl_options::s_option_entries); strreplace(ini_path,"APP_NAME", emulator_info::get_appname_lower()); - set_default_value(SDLOPTION_INIPATH, ini_path.c_str()); + set_default_value(SDLOPTION_INIPATH, std::move(ini_path)); } //============================================================ diff --git a/src/osd/windows/winmain.cpp b/src/osd/windows/winmain.cpp index 05888769c0d..c423108a0f0 100644 --- a/src/osd/windows/winmain.cpp +++ b/src/osd/windows/winmain.cpp @@ -450,17 +450,17 @@ windows_options::windows_options() add_entries(s_option_entries); #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) String^ path = ApplicationData::Current->LocalFolder->Path + L"\\"; - set_default_value(OPTION_INIPATH, (osd::text::from_wstring((LPCWSTR)path->Data()) + ";" + ini_path()).c_str()); - set_default_value(OPTION_CFG_DIRECTORY, (osd::text::from_wstring((LPCWSTR)path->Data()) + cfg_directory()).c_str()); - set_default_value(OPTION_NVRAM_DIRECTORY, (osd::text::from_wstring((LPCWSTR)path->Data()) + nvram_directory()).c_str()); - set_default_value(OPTION_INPUT_DIRECTORY, (osd::text::from_wstring((LPCWSTR)path->Data()) + input_directory()).c_str()); - set_default_value(OPTION_STATE_DIRECTORY, (osd::text::from_wstring((LPCWSTR)path->Data()) + state_directory()).c_str()); - set_default_value(OPTION_SNAPSHOT_DIRECTORY, (osd::text::from_wstring((LPCWSTR)path->Data()) + snapshot_directory()).c_str()); - set_default_value(OPTION_DIFF_DIRECTORY, (osd::text::from_wstring((LPCWSTR)path->Data()) + diff_directory()).c_str()); - set_default_value(OPTION_COMMENT_DIRECTORY, (osd::text::from_wstring((LPCWSTR)path->Data()) + comment_directory()).c_str()); - - set_default_value(OPTION_HOMEPATH, osd::text::from_wstring((LPCWSTR)path->Data()).c_str()); - set_default_value(OPTION_MEDIAPATH, (osd::text::from_wstring((LPCWSTR)path->Data()) + media_path()).c_str()); + set_default_value(OPTION_INIPATH, osd::text::from_wstring((LPCWSTR)path->Data()) + ";" + ini_path()); + set_default_value(OPTION_CFG_DIRECTORY, osd::text::from_wstring((LPCWSTR)path->Data()) + cfg_directory()); + set_default_value(OPTION_NVRAM_DIRECTORY, osd::text::from_wstring((LPCWSTR)path->Data()) + nvram_directory()); + set_default_value(OPTION_INPUT_DIRECTORY, osd::text::from_wstring((LPCWSTR)path->Data()) + input_directory()); + set_default_value(OPTION_STATE_DIRECTORY, osd::text::from_wstring((LPCWSTR)path->Data()) + state_directory()); + set_default_value(OPTION_SNAPSHOT_DIRECTORY, osd::text::from_wstring((LPCWSTR)path->Data()) + snapshot_directory()); + set_default_value(OPTION_DIFF_DIRECTORY, osd::text::from_wstring((LPCWSTR)path->Data()) + diff_directory()); + set_default_value(OPTION_COMMENT_DIRECTORY, osd::text::from_wstring((LPCWSTR)path->Data()) + comment_directory()); + + set_default_value(OPTION_HOMEPATH, osd::text::from_wstring((LPCWSTR)path->Data())); + set_default_value(OPTION_MEDIAPATH, osd::text::from_wstring((LPCWSTR)path->Data()) + media_path()); #endif } @@ -568,7 +568,7 @@ void windows_osd_interface::init(running_machine &machine) // notify listeners of screen configuration for (const auto &info : osd_common_t::s_window_list) { - machine.output().set_value(string_format("Orientation(%s)", info->monitor()->devicename()).c_str(), std::static_pointer_cast(info)->m_targetorient); + machine.output().set_value(string_format("Orientation(%s)", info->monitor()->devicename()), std::static_pointer_cast(info)->m_targetorient); } // hook up the debugger log diff --git a/src/tools/chdman.cpp b/src/tools/chdman.cpp index 6bd15339b62..c4cf8302aa3 100644 --- a/src/tools/chdman.cpp +++ b/src/tools/chdman.cpp @@ -1270,7 +1270,7 @@ static void compress_common(chd_file_compressor &chd) // to a CUE file //------------------------------------------------- -void output_track_metadata(int mode, util::core_file &file, int tracknum, const cdrom_track_info &info, const char *filename, uint32_t frameoffs, uint64_t discoffs) +void output_track_metadata(int mode, util::core_file &file, int tracknum, const cdrom_track_info &info, const std::string &filename, uint32_t frameoffs, uint64_t discoffs) { if (mode == MODE_GDI) { @@ -1318,14 +1318,14 @@ void output_track_metadata(int mode, util::core_file &file, int tracknum, const size = 2352; break; } - bool needquote = strchr(filename, ' ') != nullptr; - file.printf("%d %d %d %d %s%s%s %d\n", tracknum+1, frameoffs, mode, size, needquote?"\"":"", filename, needquote?"\"":"", discoffs); + bool needquote = filename.find(' ') != std::string::npos; + file.printf("%d %d %d %d %s%s%s %d\n", tracknum+1, frameoffs, mode, size, needquote?"\"":"", filename.c_str(), needquote?"\"":"", discoffs); } else if (mode == MODE_CUEBIN) { // first track specifies the file if (tracknum == 0) - file.printf("FILE \"%s\" BINARY\n", filename); + file.printf("FILE \"%s\" BINARY\n", filename.c_str()); // determine submode std::string tempstr; @@ -1404,9 +1404,9 @@ void output_track_metadata(int mode, util::core_file &file, int tracknum, const // all tracks but the first one have a file offset if (tracknum > 0) - file.printf("DATAFILE \"%s\" #%d %s // length in bytes: %d\n", filename, uint32_t(discoffs), msf_string_from_frames(info.frames), info.frames * (info.datasize + info.subsize)); + file.printf("DATAFILE \"%s\" #%d %s // length in bytes: %d\n", filename.c_str(), uint32_t(discoffs), msf_string_from_frames(info.frames), info.frames * (info.datasize + info.subsize)); else - file.printf("DATAFILE \"%s\" %s // length in bytes: %d\n", filename, msf_string_from_frames(info.frames), info.frames * (info.datasize + info.subsize)); + file.printf("DATAFILE \"%s\" %s // length in bytes: %d\n", filename.c_str(), msf_string_from_frames(info.frames), info.frames * (info.datasize + info.subsize)); // tracks with pregaps get a START marker too if (info.pregap > 0) @@ -2491,11 +2491,11 @@ static void do_extract_cd(parameters_map ¶ms) const cdrom_track_info &trackinfo = toc->tracks[tracknum]; if (mode == MODE_GDI) { - output_track_metadata(mode, *output_toc_file, tracknum, trackinfo, core_filename_extract_base(trackbin_name).c_str(), discoffs, outputoffs); + output_track_metadata(mode, *output_toc_file, tracknum, trackinfo, std::string(core_filename_extract_base(trackbin_name)), discoffs, outputoffs); } else { - output_track_metadata(mode, *output_toc_file, tracknum, trackinfo, core_filename_extract_base(*output_bin_file_str).c_str(), discoffs, outputoffs); + output_track_metadata(mode, *output_toc_file, tracknum, trackinfo, std::string(core_filename_extract_base(*output_bin_file_str)), discoffs, outputoffs); } // If this is bin/cue output and the CHD contains subdata, warn the user and don't include diff --git a/src/tools/imgtool/imgtool.cpp b/src/tools/imgtool/imgtool.cpp index 2b2e6c62b08..6d14c90a369 100644 --- a/src/tools/imgtool/imgtool.cpp +++ b/src/tools/imgtool/imgtool.cpp @@ -1884,7 +1884,7 @@ imgtoolerr_t imgtool::partition::put_file(const char *newfname, const char *fork if (!newfname) { - basename = core_filename_extract_base(source); + basename = std::string(core_filename_extract_base(source)); newfname = basename.c_str(); } diff --git a/src/tools/imgtool/main.cpp b/src/tools/imgtool/main.cpp index e0ff03cca62..360f015b233 100644 --- a/src/tools/imgtool/main.cpp +++ b/src/tools/imgtool/main.cpp @@ -29,7 +29,7 @@ static void writeusage(std::wostream &output, bool write_word_usage, const struct command *c, char *argv[]) { - std::string cmdname = core_filename_extract_base(argv[0]); + std::string cmdname(core_filename_extract_base(argv[0])); util::stream_format(output, L"%s %s %s %s\n", @@ -873,7 +873,7 @@ int main(int argc, char *argv[]) int result; const struct command *c; const char *sample_format = "coco_jvc_rsdos"; - std::string cmdname = core_filename_extract_base(argv[0]); + std::string cmdname(core_filename_extract_base(argv[0])); #ifdef _WIN32 _setmode(_fileno(stdout), _O_U8TEXT); diff --git a/src/tools/imgtool/stream.cpp b/src/tools/imgtool/stream.cpp index da4cf87f8eb..bb0d95614f3 100644 --- a/src/tools/imgtool/stream.cpp +++ b/src/tools/imgtool/stream.cpp @@ -147,8 +147,7 @@ imgtool::stream::ptr imgtool::stream::open(const std::string &filename, int read char c; // maybe we are just a ZIP? - std::string ext = core_filename_extract_extension(filename); - if (!core_stricmp(ext.c_str(), ".zip")) + if (core_filename_ends_with(filename, ".zip")) return open_zip(filename, nullptr, read_or_write); util::core_file::ptr f = nullptr; diff --git a/src/tools/split.cpp b/src/tools/split.cpp index c3f4489f225..f8a8eb79234 100644 --- a/src/tools/split.cpp +++ b/src/tools/split.cpp @@ -236,8 +236,7 @@ static int join_file(const char *filename, const char *outname, int write_output fprintf(stderr, "Fatal error: corrupt or incomplete split file at line:\n%s\n", buffer); goto cleanup; } - outfilename.assign(buffer + 10); - strtrimspace(outfilename); + outfilename.assign(strtrimspace(buffer + 10)); // compute the base path basepath.assign(filename); @@ -295,8 +294,7 @@ static int join_file(const char *filename, const char *outname, int write_output goto cleanup; } expectedhash.assign(buffer + 5, SHA1_DIGEST_SIZE * 2); - infilename.assign(buffer + 5 + SHA1_DIGEST_SIZE * 2 + 6); - strtrimspace(infilename); + infilename.assign(strtrimspace(buffer + 5 + SHA1_DIGEST_SIZE * 2 + 6)); printf(" Reading file '%s'...", infilename.c_str()); -- cgit v1.2.3