From 91605d3f4df9b9fb1490c276053ff274fb728816 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 3 Dec 2015 18:17:25 +0100 Subject: clang-modernize part 1 (nw) --- src/emu/ui/filemngr.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/emu/ui/filemngr.cpp') diff --git a/src/emu/ui/filemngr.cpp b/src/emu/ui/filemngr.cpp index 6bc789299d9..6af12895186 100644 --- a/src/emu/ui/filemngr.cpp +++ b/src/emu/ui/filemngr.cpp @@ -28,7 +28,7 @@ // ctor //------------------------------------------------- -ui_menu_file_manager::ui_menu_file_manager(running_machine &machine, render_container *container, const char *warnings) : ui_menu(machine, container), selected_device(NULL) +ui_menu_file_manager::ui_menu_file_manager(running_machine &machine, render_container *container, const char *warnings) : ui_menu(machine, container), selected_device(nullptr) { // This warning string is used when accessing from the force_file_manager call, i.e. // when the file manager is loaded top front in the case of mandatory image devices @@ -59,9 +59,9 @@ void ui_menu_file_manager::custom_render(void *selectedref, float top, float bot const char *path; // access the path - path = selected_device ? selected_device->filename() : NULL; + path = selected_device ? selected_device->filename() : nullptr; extra_text_render(container, top, bottom, - origx1, origy1, origx2, origy2, NULL, path); + origx1, origy1, origx2, origy2, nullptr, path); } @@ -71,20 +71,20 @@ void ui_menu_file_manager::fill_image_line(device_image_interface *img, std::str strprintf(instance,"%s (%s)", img->instance_name(), img->brief_instance_name()); // get the base name - if (img->basename() != NULL) + if (img->basename() != nullptr) { filename.assign(img->basename()); // if the image has been loaded through softlist, also show the loaded part - if (img->part_entry() != NULL) + if (img->part_entry() != nullptr) { const software_part *tmp = img->part_entry(); - if (tmp->name() != NULL) + if (tmp->name() != nullptr) { filename.append(" ("); filename.append(tmp->name()); // also check if this part has a specific part_id (e.g. "Map Disc", "Bonus Disc", etc.), and in case display it - if (img->get_feature("part_id") != NULL) + if (img->get_feature("part_id") != nullptr) { filename.append(": "); filename.append(img->get_feature("part_id")); @@ -108,14 +108,14 @@ void ui_menu_file_manager::populate() if (!m_warnings.empty()) { - item_append(m_warnings.c_str(), NULL, MENU_FLAG_DISABLE, NULL); - item_append("", NULL, MENU_FLAG_DISABLE, NULL); + item_append(m_warnings.c_str(), nullptr, MENU_FLAG_DISABLE, nullptr); + item_append("", nullptr, MENU_FLAG_DISABLE, nullptr); } // cycle through all devices for this system device_iterator iter(machine().root_device()); tagmap_t devtags; - for (device_t *dev = iter.first(); dev != NULL; dev = iter.next()) + for (device_t *dev = iter.first(); dev != nullptr; dev = iter.next()) { bool tag_appended = false; if (devtags.add(dev->tag(), 1, FALSE) == TMERR_DUPLICATE) @@ -127,7 +127,7 @@ void ui_menu_file_manager::populate() { // if so, cycle through all its image interfaces image_interface_iterator subiterator(*dev); - for (device_image_interface *scan = subiterator.first(); scan != NULL; scan = subiterator.next()) + for (device_image_interface *scan = subiterator.first(); scan != nullptr; scan = subiterator.next()) { // if it is a children device, and not something further down the device tree, we want it in the menu! if (strcmp(scan->device().owner()->tag(), dev->tag()) == 0) @@ -139,9 +139,9 @@ void ui_menu_file_manager::populate() if (first_entry) first_entry = false; else - item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL); + item_append(MENU_SEPARATOR_ITEM, nullptr, 0, nullptr); strprintf(buffer, "[root%s]", dev->tag()); - item_append(buffer.c_str(), NULL, 0, NULL); + item_append(buffer.c_str(), nullptr, 0, nullptr); tag_appended = true; } // finally, append the image interface to the menu @@ -151,8 +151,8 @@ void ui_menu_file_manager::populate() } } } - item_append(MENU_SEPARATOR_ITEM, NULL, 0, NULL); - item_append("Reset", NULL, 0, (void *)1); + item_append(MENU_SEPARATOR_ITEM, nullptr, 0, nullptr); + item_append("Reset", nullptr, 0, (void *)1); custombottom = machine().ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER; } @@ -166,7 +166,7 @@ void ui_menu_file_manager::handle() { // process the menu const ui_menu_event *event = process(0); - if (event != NULL && event->itemref != NULL && event->iptkey == IPT_UI_SELECT) + if (event != nullptr && event->itemref != nullptr && event->iptkey == IPT_UI_SELECT) { if ((FPTR)event->itemref == 1) { @@ -176,7 +176,7 @@ void ui_menu_file_manager::handle() else { selected_device = (device_image_interface *) event->itemref; - if (selected_device != NULL) + if (selected_device != nullptr) { m_curr_selected = TRUE; ui_menu::stack_push(selected_device->get_selection_menu(machine(), container)); -- cgit v1.2.3-70-g09d2 From 3414b0166e77c5353373d655e3def0251571722d Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 9 Dec 2015 21:14:13 +0100 Subject: tagmap_t to std::unordered_map or std::unordered_set where applicable (nw) --- src/emu/clifront.cpp | 32 ++- src/emu/clifront.h | 2 - src/emu/device.cpp | 6 +- src/emu/device.h | 6 +- src/emu/emu.h | 2 + src/emu/info.cpp | 14 +- src/emu/parameters.cpp | 5 +- src/emu/parameters.h | 2 +- src/emu/softlist.cpp | 10 +- src/emu/ui/devopt.cpp | 12 +- src/emu/ui/filemngr.cpp | 6 +- src/emu/ui/ui.cpp | 12 +- src/emu/validity.cpp | 48 ++--- src/emu/validity.h | 12 +- src/lib/util/options.cpp | 75 ++++--- src/lib/util/options.h | 4 +- src/osd/modules/lib/osdobj_common.h | 1 - src/tools/chdman.cpp | 395 ++++++++++++++++++------------------ 18 files changed, 322 insertions(+), 322 deletions(-) (limited to 'src/emu/ui/filemngr.cpp') diff --git a/src/emu/clifront.cpp b/src/emu/clifront.cpp index 8df0df626b3..60d75272f82 100644 --- a/src/emu/clifront.cpp +++ b/src/emu/clifront.cpp @@ -821,14 +821,14 @@ void cli_frontend::verifyroms(const char *gamename) if (!matched || strchr(gamename, '*') || strchr(gamename, '?')) { driver_enumerator dummy_drivlist(m_options); - int_map device_map; + std::unordered_set device_map; while (dummy_drivlist.next()) { machine_config &config = dummy_drivlist.config(); device_iterator iter(config.root_device()); for (device_t *dev = iter.first(); dev != nullptr; dev = iter.next()) { - if (dev->owner() != nullptr && (*(dev->shortname()) != 0) && dev->rom_region() != nullptr && (device_map.add(dev->shortname(), 0, false) != TMERR_DUPLICATE)) { + if (dev->owner() != nullptr && (*(dev->shortname()) != 0) && dev->rom_region() != nullptr && (device_map.insert(dev->shortname()).second)) { if (core_strwildcmp(gamename, dev->shortname()) == 0) { matched++; @@ -891,7 +891,7 @@ void cli_frontend::verifyroms(const char *gamename) if (!device->configured()) device->config_complete(); - if (device_map.add(dev->shortname(), 0, false) != TMERR_DUPLICATE) { + if (device_map.insert(dev->shortname()).second) { if (core_strwildcmp(gamename, dev->shortname()) == 0) { matched++; @@ -1250,7 +1250,7 @@ void cli_frontend::output_single_softlist(FILE *out, software_list_device &swlis void cli_frontend::listsoftware(const char *gamename) { FILE *out = stdout; - int_map list_map; + std::unordered_set list_map; bool isfirst = true; // determine which drivers to output; return an error if none found @@ -1262,7 +1262,7 @@ void cli_frontend::listsoftware(const char *gamename) { software_list_device_iterator iter(drivlist.config().root_device()); for (software_list_device *swlistdev = iter.first(); swlistdev != nullptr; swlistdev = iter.next()) - if (list_map.add(swlistdev->list_name(), 0, false) != TMERR_DUPLICATE) + if (list_map.insert(swlistdev->list_name()).second) if (swlistdev->first_software_info() != nullptr) { if (isfirst) { fprintf(out, SOFTLIST_XML_BEGIN); isfirst = false; } @@ -1283,7 +1283,7 @@ void cli_frontend::listsoftware(const char *gamename) -------------------------------------------------*/ void cli_frontend::verifysoftware(const char *gamename) { - int_map list_map; + std::unordered_set list_map; int correct = 0; int incorrect = 0; @@ -1306,7 +1306,7 @@ void cli_frontend::verifysoftware(const char *gamename) software_list_device_iterator iter(drivlist.config().root_device()); for (software_list_device *swlistdev = iter.first(); swlistdev != nullptr; swlistdev = iter.next()) if (swlistdev->list_type() == SOFTWARE_LIST_ORIGINAL_SYSTEM) - if (list_map.add(swlistdev->list_name(), 0, false) != TMERR_DUPLICATE) + if (list_map.insert(swlistdev->list_name()).second) if (swlistdev->first_software_info() != nullptr) { nrlists++; @@ -1385,7 +1385,7 @@ void cli_frontend::verifysoftware(const char *gamename) void cli_frontend::getsoftlist(const char *gamename) { FILE *out = stdout; - int_map list_map; + std::unordered_set list_map; bool isfirst = TRUE; driver_enumerator drivlist(m_options); @@ -1393,7 +1393,7 @@ void cli_frontend::getsoftlist(const char *gamename) { software_list_device_iterator iter(drivlist.config().root_device()); for (software_list_device *swlistdev = iter.first(); swlistdev != nullptr; swlistdev = iter.next()) - if (core_strwildcmp(gamename, swlistdev->list_name()) == 0 && list_map.add(swlistdev->list_name(), 0, false) != TMERR_DUPLICATE) + if (core_strwildcmp(gamename, swlistdev->list_name()) == 0 && list_map.insert(swlistdev->list_name()).second) if (swlistdev->first_software_info() != nullptr) { if (isfirst) { fprintf( out, SOFTLIST_XML_BEGIN); isfirst = FALSE; } @@ -1413,7 +1413,7 @@ void cli_frontend::getsoftlist(const char *gamename) -------------------------------------------------*/ void cli_frontend::verifysoftlist(const char *gamename) { - int_map list_map; + std::unordered_set list_map; int correct = 0; int incorrect = 0; int notfound = 0; @@ -1426,7 +1426,7 @@ void cli_frontend::verifysoftlist(const char *gamename) { software_list_device_iterator iter(drivlist.config().root_device()); for (software_list_device *swlistdev = iter.first(); swlistdev != nullptr; swlistdev = iter.next()) - if (core_strwildcmp(gamename, swlistdev->list_name()) == 0 && list_map.add(swlistdev->list_name(), 0, false) != TMERR_DUPLICATE) + if (core_strwildcmp(gamename, swlistdev->list_name()) == 0 && list_map.insert(swlistdev->list_name()).second) if (swlistdev->first_software_info() != nullptr) { matched++; @@ -1880,13 +1880,11 @@ void media_identifier::identify_data(const char *name, const UINT8 *data, int le // of drivers by hash //------------------------------------------------- -typedef tagmap_t slname_map; - int media_identifier::find_by_hash(const hash_collection &hashes, int length) { int found = 0; - slname_map listnames; - slname_map shortnames; + std::unordered_set listnames; + std::unordered_set shortnames; // iterate over drivers m_drivlist.reset(); @@ -1896,7 +1894,7 @@ int media_identifier::find_by_hash(const hash_collection &hashes, int length) device_iterator deviter(m_drivlist.config().root_device()); for (device_t *device = deviter.first(); device != nullptr; device = deviter.next()) { - if (shortnames.add(device->shortname(), 0, FALSE) != TMERR_DUPLICATE) + if (shortnames.insert(device->shortname()).second) { for (const rom_entry *region = rom_first_region(*device); region != nullptr; region = rom_next_region(region)) for (const rom_entry *rom = rom_first_file(region); rom != nullptr; rom = rom_next_file(rom)) @@ -1920,7 +1918,7 @@ int media_identifier::find_by_hash(const hash_collection &hashes, int length) software_list_device_iterator iter(m_drivlist.config().root_device()); for (software_list_device *swlistdev = iter.first(); swlistdev != nullptr; swlistdev = iter.next()) { - if (listnames.add(swlistdev->list_name(), 0, FALSE) != TMERR_DUPLICATE) + if (listnames.insert(swlistdev->list_name()).second) { for (software_info *swinfo = swlistdev->first_software_info(); swinfo != nullptr; swinfo = swinfo->next()) for (software_part *part = swinfo->first_part(); part != nullptr; part = part->next()) diff --git a/src/emu/clifront.h b/src/emu/clifront.h index 59d35d8993c..b5613f94b76 100644 --- a/src/emu/clifront.h +++ b/src/emu/clifront.h @@ -27,8 +27,6 @@ class osd_interface; // cli_frontend handles command-line processing and emulator execution class cli_frontend { - typedef tagmap_t int_map; - public: // construction/destruction cli_frontend(cli_options &options, osd_interface &osd); diff --git a/src/emu/device.cpp b/src/emu/device.cpp index b29466d8875..8400d87ddbd 100644 --- a/src/emu/device.cpp +++ b/src/emu/device.cpp @@ -670,7 +670,7 @@ device_t *device_t::subdevice_slow(const char *tag) const // if we got a match, add to the fast map if (curdevice != nullptr) - m_device_map.add(tag, curdevice); + m_device_map.insert(std::make_pair(tag, curdevice)); return curdevice; } @@ -760,7 +760,7 @@ device_t *device_t::replace_subdevice(device_t &old, device_type type, const cha // iterate over all devices and remove any references to the old device device_iterator iter(mconfig().root_device()); for (device_t *scan = iter.first(); scan != nullptr; scan = iter.next()) - scan->m_device_map.reset(); //remove(&old); + scan->m_device_map.clear(); //remove(&old); // create a new device, and substitute it for the old one device_t *device = (*type)(mconfig(), tag, this, clock); @@ -783,7 +783,7 @@ void device_t::remove_subdevice(device_t &device) // iterate over all devices and remove any references device_iterator iter(mconfig().root_device()); for (device_t *scan = iter.first(); scan != nullptr; scan = iter.next()) - scan->m_device_map.reset(); //remove(&device); + scan->m_device_map.clear(); //remove(&device); // remove from our list m_subdevice_list.remove(device); diff --git a/src/emu/device.h b/src/emu/device.h index 69e54150bfd..fec1654c72d 100644 --- a/src/emu/device.h +++ b/src/emu/device.h @@ -252,7 +252,7 @@ protected: device_t * m_owner; // device that owns us device_t * m_next; // next device by the same owner (of any type/class) simple_list m_subdevice_list; // list of sub-devices we own - mutable tagmap_t m_device_map; // map of device names looked up and found + mutable std::unordered_map m_device_map; // map of device names looked up and found // device interfaces device_interface * m_interface_list; // head of interface list @@ -598,8 +598,8 @@ inline device_t *device_t::subdevice(const char *tag) const return const_cast(this); // do a quick lookup and return that if possible - device_t *quick = m_device_map.find(tag); - return (quick != nullptr) ? quick : subdevice_slow(tag); + auto quick = m_device_map.find(tag); + return (quick != m_device_map.end()) ? quick->second : subdevice_slow(tag); } diff --git a/src/emu/emu.h b/src/emu/emu.h index 522e37b6230..24de3559ab2 100644 --- a/src/emu/emu.h +++ b/src/emu/emu.h @@ -24,6 +24,8 @@ #include #include #include +#include +#include // core emulator headers -- must be first #include "emucore.h" diff --git a/src/emu/info.cpp b/src/emu/info.cpp index fdf5e1c9a5c..f09fba8fe94 100644 --- a/src/emu/info.cpp +++ b/src/emu/info.cpp @@ -383,12 +383,10 @@ void info_xml_creator::output_one_device(device_t &device, const char *devtag) // directly to a driver as device or sub-device) //------------------------------------------------- -typedef tagmap_t slot_map; - void info_xml_creator::output_devices() { m_drivlist.reset(); - slot_map shortnames; + std::unordered_set shortnames; while (m_drivlist.next()) { @@ -398,7 +396,7 @@ void info_xml_creator::output_devices() { if (device->owner() != nullptr && device->shortname()!= nullptr && strlen(device->shortname())!=0) { - if (shortnames.add(device->shortname(), 0, FALSE) != TMERR_DUPLICATE) + if (shortnames.insert(device->shortname()).second) output_one_device(*device, device->tag()); } } @@ -419,7 +417,7 @@ void info_xml_creator::output_devices() if (!device->configured()) device->config_complete(); - if (shortnames.add(dev->shortname(), 0, FALSE) != TMERR_DUPLICATE) + if (shortnames.insert(dev->shortname()).second) output_one_device(*dev, temptag.c_str()); // also, check for subdevices with ROMs (a few devices are missed otherwise, e.g. MPU401) @@ -428,7 +426,7 @@ void info_xml_creator::output_devices() { if (device->owner() == dev && device->shortname()!= nullptr && strlen(device->shortname())!=0) { - if (shortnames.add(device->shortname(), 0, FALSE) != TMERR_DUPLICATE) + if (shortnames.insert(device->shortname()).second) output_one_device(*device, device->tag()); } } @@ -618,11 +616,11 @@ void info_xml_creator::output_sample(device_t &device) for (samples_device *samples = sampiter.first(); samples != nullptr; samples = sampiter.next()) { samples_iterator iter(*samples); - tagmap_t already_printed; + std::unordered_set already_printed; for (const char *samplename = iter.first(); samplename != nullptr; samplename = iter.next()) { // filter out duplicates - if (already_printed.add(samplename, 1) == TMERR_DUPLICATE) + if (already_printed.insert(samplename).second) continue; // output the sample name diff --git a/src/emu/parameters.cpp b/src/emu/parameters.cpp index cdc32b6e468..b0d74cc6a6a 100644 --- a/src/emu/parameters.cpp +++ b/src/emu/parameters.cpp @@ -17,10 +17,11 @@ parameters_manager::parameters_manager(running_machine &machine) std::string parameters_manager::lookup(std::string tag) const { - return m_parameters.find(tag.c_str()); + auto search = m_parameters.find(tag); + return (search!=m_parameters.end()) ? search->second : nullptr; } void parameters_manager::add(std::string tag, std::string value) { - m_parameters.add(tag.c_str(), value); + m_parameters.insert(std::make_pair(tag, value)); } diff --git a/src/emu/parameters.h b/src/emu/parameters.h index f24b4055053..23bdd010357 100644 --- a/src/emu/parameters.h +++ b/src/emu/parameters.h @@ -42,7 +42,7 @@ public: private: // internal state running_machine & m_machine; // reference to owning machine - tagmap_t m_parameters; + std::unordered_map m_parameters; }; #endif // __INPTPORT_H__ */ diff --git a/src/emu/softlist.cpp b/src/emu/softlist.cpp index 1e1fd1718f8..2a5ceaccdcc 100644 --- a/src/emu/softlist.cpp +++ b/src/emu/softlist.cpp @@ -22,7 +22,7 @@ // TYPE DEFINITIONS //************************************************************************** -typedef tagmap_t softlist_map; +typedef std::unordered_map softlist_map; // ======================> softlist_parser @@ -567,15 +567,15 @@ void software_list_device::internal_validity_check(validity_checker &valid) // Second, since the xml is fine, run additional checks: // check for duplicate names - if (names.add(swinfo->shortname(), swinfo, false) == TMERR_DUPLICATE) + if (!names.insert(std::make_pair(swinfo->shortname(), swinfo)).second) { - software_info *match = names.find(swinfo->shortname()); + software_info *match = names.find(swinfo->shortname())->second; osd_printf_error("%s: %s is a duplicate name (%s)\n", filename(), swinfo->shortname(), match->shortname()); } // check for duplicate descriptions std::string longname = std::string(swinfo->longname()); - if (descriptions.add(strmakelower(longname).c_str(), swinfo, false) == TMERR_DUPLICATE) + if (!descriptions.insert(std::make_pair(strmakelower(longname), swinfo)).second) osd_printf_error("%s: %s is a duplicate description (%s)\n", filename(), swinfo->longname(), swinfo->shortname()); bool is_clone = false; @@ -619,7 +619,7 @@ void software_list_device::internal_validity_check(validity_checker &valid) if (part->romdata() == nullptr) osd_printf_error("%s: %s has a part (%s) with no data\n", filename(), swinfo->shortname(), part->name()); - if (part_names.add(part->name(), swinfo, false) == TMERR_DUPLICATE) + if (!part_names.insert(std::make_pair(part->name(), swinfo)).second) osd_printf_error("%s: %s has a part (%s) whose name is duplicate\n", filename(), swinfo->shortname(), part->name()); for (const rom_entry *data = part->romdata(); data->_name != nullptr; data++) diff --git a/src/emu/ui/devopt.cpp b/src/emu/ui/devopt.cpp index 40ee5429e6a..3d217e92025 100644 --- a/src/emu/ui/devopt.cpp +++ b/src/emu/ui/devopt.cpp @@ -58,10 +58,10 @@ void ui_menu_device_config::populate() if (execiter.count() > 0) { str.append("* CPU:\n"); - tagmap_t exectags; + std::unordered_set exectags; for (device_execute_interface *exec = execiter.first(); exec != nullptr; exec = execiter.next()) { - if (exectags.add(exec->device().tag(), 1, FALSE) == TMERR_DUPLICATE) + if (!exectags.insert(exec->device().tag()).second) continue; // get cpu specific clock that takes internal multiplier/dividers into account @@ -74,7 +74,7 @@ void ui_menu_device_config::populate() for (device_execute_interface *scan = execinneriter.first(); scan != nullptr; scan = execinneriter.next()) { if (exec->device().type() == scan->device().type() && strcmp(name, scan->device().name()) == 0 && exec->device().clock() == scan->device().clock()) - if (exectags.add(scan->device().tag(), 1, FALSE) != TMERR_DUPLICATE) + if (exectags.insert(scan->device().tag()).second) count++; } @@ -121,10 +121,10 @@ void ui_menu_device_config::populate() if (snditer.count() > 0) { str.append("* Sound:\n"); - tagmap_t soundtags; + std::unordered_set soundtags; for (device_sound_interface *sound = snditer.first(); sound != nullptr; sound = snditer.next()) { - if (soundtags.add(sound->device().tag(), 1, FALSE) == TMERR_DUPLICATE) + if (!soundtags.insert(sound->device().tag()).second) continue; // count how many identical sound chips we have @@ -133,7 +133,7 @@ void ui_menu_device_config::populate() for (device_sound_interface *scan = sndinneriter.first(); scan != nullptr; scan = sndinneriter.next()) { if (sound->device().type() == scan->device().type() && sound->device().clock() == scan->device().clock()) - if (soundtags.add(scan->device().tag(), 1, FALSE) != TMERR_DUPLICATE) + if (soundtags.insert(scan->device().tag()).second) count++; } // if more than one, prepend a #x in front of the CPU name diff --git a/src/emu/ui/filemngr.cpp b/src/emu/ui/filemngr.cpp index 6af12895186..ce94f437120 100644 --- a/src/emu/ui/filemngr.cpp +++ b/src/emu/ui/filemngr.cpp @@ -114,11 +114,11 @@ void ui_menu_file_manager::populate() // cycle through all devices for this system device_iterator iter(machine().root_device()); - tagmap_t devtags; + std::unordered_set devtags; for (device_t *dev = iter.first(); dev != nullptr; dev = iter.next()) { bool tag_appended = false; - if (devtags.add(dev->tag(), 1, FALSE) == TMERR_DUPLICATE) + if (!devtags.insert(dev->tag()).second) continue; // check whether it owns an image interface @@ -131,7 +131,7 @@ void ui_menu_file_manager::populate() { // if it is a children device, and not something further down the device tree, we want it in the menu! if (strcmp(scan->device().owner()->tag(), dev->tag()) == 0) - if (devtags.add(scan->device().tag(), 1, FALSE) != TMERR_DUPLICATE) + if (devtags.insert(scan->device().tag()).second) { // check whether we already had some devices with the same owner: if not, output the owner tag! if (!tag_appended) diff --git a/src/emu/ui/ui.cpp b/src/emu/ui/ui.cpp index 1558f7a74d9..02522bc896a 100644 --- a/src/emu/ui/ui.cpp +++ b/src/emu/ui/ui.cpp @@ -1158,10 +1158,10 @@ std::string &ui_manager::game_info_astring(std::string &str) // loop over all CPUs execute_interface_iterator execiter(machine().root_device()); - tagmap_t exectags; + std::unordered_set exectags; for (device_execute_interface *exec = execiter.first(); exec != nullptr; exec = execiter.next()) { - if (exectags.add(exec->device().tag(), 1, FALSE) == TMERR_DUPLICATE) + if (!exectags.insert(exec->device().tag()).second) continue; // get cpu specific clock that takes internal multiplier/dividers into account int clock = exec->device().clock(); @@ -1173,7 +1173,7 @@ std::string &ui_manager::game_info_astring(std::string &str) for (device_execute_interface *scan = execinneriter.first(); scan != nullptr; scan = execinneriter.next()) { if (exec->device().type() == scan->device().type() && strcmp(name, scan->device().name()) == 0 && exec->device().clock() == scan->device().clock()) - if (exectags.add(scan->device().tag(), 1, FALSE) != TMERR_DUPLICATE) + if (exectags.insert(scan->device().tag()).second) count++; } @@ -1191,11 +1191,11 @@ std::string &ui_manager::game_info_astring(std::string &str) // loop over all sound chips sound_interface_iterator snditer(machine().root_device()); - tagmap_t soundtags; + std::unordered_set soundtags; bool found_sound = false; for (device_sound_interface *sound = snditer.first(); sound != nullptr; sound = snditer.next()) { - if (soundtags.add(sound->device().tag(), 1, FALSE) == TMERR_DUPLICATE) + if (!soundtags.insert(sound->device().tag()).second) continue; // append the Sound: string @@ -1209,7 +1209,7 @@ std::string &ui_manager::game_info_astring(std::string &str) for (device_sound_interface *scan = sndinneriter.first(); scan != nullptr; scan = sndinneriter.next()) { if (sound->device().type() == scan->device().type() && sound->device().clock() == scan->device().clock()) - if (soundtags.add(scan->device().tag(), 1, FALSE) != TMERR_DUPLICATE) + if (soundtags.insert(scan->device().tag()).second) count++; } // if more than one, prepend a #x in front of the CPU name diff --git a/src/emu/validity.cpp b/src/emu/validity.cpp index 78404d121ce..345b47d010c 100644 --- a/src/emu/validity.cpp +++ b/src/emu/validity.cpp @@ -55,10 +55,10 @@ inline const char *validity_checker::ioport_string_from_index(UINT32 index) inline int validity_checker::get_defstr_index(const char *string, bool suppress_error) { // check for strings that should be DEF_STR - int strindex = m_defstr_map.find(string); - if (!suppress_error && strindex != 0 && string != ioport_string_from_index(strindex)) + auto strindex = m_defstr_map.find(string); + if (!suppress_error && strindex != m_defstr_map.end() && string != ioport_string_from_index(strindex->second)) osd_printf_error("Must use DEF_STR( %s )\n", string); - return strindex; + return (strindex != m_defstr_map.end()) ? strindex->second : 0; } @@ -135,7 +135,7 @@ validity_checker::validity_checker(emu_options &options) { const char *string = ioport_string_from_index(strnum); if (string != nullptr) - m_defstr_map.add(string, strnum, false); + m_defstr_map.insert(std::make_pair(string, strnum)); } } @@ -234,16 +234,16 @@ void validity_checker::validate_begin() osd_output::push(this); // reset all our maps - m_names_map.reset(); - m_descriptions_map.reset(); - m_roms_map.reset(); - m_defstr_map.reset(); - m_region_map.reset(); + m_names_map.clear(); + m_descriptions_map.clear(); + m_roms_map.clear(); + m_defstr_map.clear(); + m_region_map.clear(); // reset internal state m_errors = 0; m_warnings = 0; - m_already_checked.reset(); + m_already_checked.clear(); } @@ -270,7 +270,7 @@ void validity_checker::validate_one(const game_driver &driver) m_current_config = nullptr; m_current_device = nullptr; m_current_ioport = nullptr; - m_region_map.reset(); + m_region_map.clear(); // reset error/warning state int start_errors = m_errors; @@ -531,16 +531,16 @@ void validity_checker::validate_driver() { // check for duplicate names std::string tempstr; - if (m_names_map.add(m_current_driver->name, m_current_driver, false) == TMERR_DUPLICATE) + if (!m_names_map.insert(std::make_pair(m_current_driver->name, m_current_driver)).second) { - const game_driver *match = m_names_map.find(m_current_driver->name); + const game_driver *match = m_names_map.find(m_current_driver->name)->second; osd_printf_error("Driver name is a duplicate of %s(%s)\n", core_filename_extract_base(tempstr, match->source_file).c_str(), match->name); } // check for duplicate descriptions - if (m_descriptions_map.add(m_current_driver->description, m_current_driver, false) == TMERR_DUPLICATE) + if (!m_descriptions_map.insert(std::make_pair(m_current_driver->description, m_current_driver)).second) { - const game_driver *match = m_descriptions_map.find(m_current_driver->description); + const game_driver *match = m_descriptions_map.find(m_current_driver->description)->second; osd_printf_error("Driver description is a duplicate of %s(%s)\n", core_filename_extract_base(tempstr, match->source_file).c_str(), match->name); } @@ -654,7 +654,7 @@ void validity_checker::validate_roms() // attempt to add it to the map, reporting duplicates as errors current_length = ROMREGION_GETLENGTH(romp); - if (m_region_map.add(fulltag.c_str(), current_length, false) == TMERR_DUPLICATE) + if (!m_region_map.insert(std::make_pair(fulltag, current_length)).second) osd_printf_error("Multiple ROM_REGIONs with the same tag '%s' defined\n", fulltag.c_str()); } @@ -855,11 +855,11 @@ void validity_checker::validate_dip_settings(ioport_field &field) // stored within an ioport field or setting //------------------------------------------------- -void validity_checker::validate_condition(ioport_condition &condition, device_t &device, int_map &port_map) +void validity_checker::validate_condition(ioport_condition &condition, device_t &device, std::unordered_set &port_map) { // resolve the tag // then find a matching port - if (port_map.find(device.subtag(condition.tag()).c_str()) == 0) + if (port_map.find(device.subtag(condition.tag())) == port_map.end()) osd_printf_error("Condition referencing non-existent ioport tag '%s'\n", condition.tag()); } @@ -870,7 +870,7 @@ void validity_checker::validate_condition(ioport_condition &condition, device_t void validity_checker::validate_inputs() { - int_map port_map; + std::unordered_set port_map; // iterate over devices device_iterator iter(m_current_config->root_device()); @@ -894,7 +894,7 @@ void validity_checker::validate_inputs() // do a first pass over ports to add their names and find duplicates for (ioport_port *port = portlist.first(); port != nullptr; port = port->next()) - if (port_map.add(port->tag(), 1, false) == TMERR_DUPLICATE) + if (!port_map.insert(port->tag()).second) osd_printf_error("Multiple I/O ports with the same tag '%s' defined\n", port->tag()); // iterate over ports @@ -971,7 +971,7 @@ void validity_checker::validate_inputs() void validity_checker::validate_devices() { - int_map device_map; + std::unordered_set device_map; device_iterator iter_find(m_current_config->root_device()); for (const device_t *device = iter_find.first(); device != nullptr; device = iter_find.next()) @@ -990,7 +990,7 @@ void validity_checker::validate_devices() validate_tag(device->basetag()); // look for duplicates - if (device_map.add(device->tag(), 0, false) == TMERR_DUPLICATE) + if (!device_map.insert(device->tag()).second) osd_printf_error("Multiple devices with the same tag '%s' defined\n", device->tag()); // all devices must have a shortname @@ -1009,7 +1009,7 @@ void validity_checker::validate_devices() } // if device is slot cart device, we must have a shortname - int_map slot_device_map; + std::unordered_set slot_device_map; slot_interface_iterator slotiter(m_current_config->root_device()); for (const device_slot_interface *slot = slotiter.first(); slot != nullptr; slot = slotiter.next()) { @@ -1026,7 +1026,7 @@ void validity_checker::validate_devices() device->config_complete(); if (strcmp(dev->shortname(), "") == 0) { - if (slot_device_map.add(dev->name(), 0, false) != TMERR_DUPLICATE) + if (slot_device_map.insert(dev->name()).second) osd_printf_error("Device '%s' is slot cart device but does not have short name defined\n",dev->name()); } diff --git a/src/emu/validity.h b/src/emu/validity.h index 7581d454241..fa38bb20f93 100644 --- a/src/emu/validity.h +++ b/src/emu/validity.h @@ -29,8 +29,8 @@ class machine_config; class validity_checker : public osd_output { // internal map types - typedef tagmap_t game_driver_map; - typedef tagmap_t int_map; + typedef std::unordered_map game_driver_map; + typedef std::unordered_map int_map; public: validity_checker(emu_options &options); @@ -47,10 +47,10 @@ public: // helpers for devices void validate_tag(const char *tag); - int region_length(const char *tag) { return m_region_map.find(tag); } + int region_length(const char *tag) { return m_region_map.find(tag)->second; } // generic registry of already-checked stuff - bool already_checked(const char *string) { return (m_already_checked.add(string, 1, false) == TMERR_DUPLICATE); } + bool already_checked(const char *string) { return m_already_checked.insert(string).second; } // osd_output interface @@ -74,7 +74,7 @@ private: void validate_roms(); void validate_analog_input_field(ioport_field &field); void validate_dip_settings(ioport_field &field); - void validate_condition(ioport_condition &condition, device_t &device, int_map &port_map); + void validate_condition(ioport_condition &condition, device_t &device, std::unordered_set &port_map); void validate_inputs(); void validate_devices(); @@ -103,7 +103,7 @@ private: const device_t * m_current_device; const char * m_current_ioport; int_map m_region_map; - tagmap_t m_already_checked; + std::unordered_set m_already_checked; }; diff --git a/src/lib/util/options.cpp b/src/lib/util/options.cpp index 0a8ace7d9f3..f1229359d16 100644 --- a/src/lib/util/options.cpp +++ b/src/lib/util/options.cpp @@ -259,9 +259,10 @@ void core_options::add_entry(const char *name, const char *description, UINT32 f if (newentry->name() != nullptr) { // see if we match an existing entry - entry *existing = m_entrymap.find(newentry->name()); - if (existing != nullptr) + auto checkentry = m_entrymap.find(newentry->name()); + if (checkentry != m_entrymap.end()) { + entry *existing = checkentry->second; // if we're overriding existing entries, then remove the old one if (override_existing) m_entrylist.remove(*existing); @@ -302,12 +303,12 @@ void core_options::add_entries(const options_entry *entrylist, bool override_exi void core_options::set_default_value(const char *name, const char *defvalue) { // find the entry and bail if we can't - entry *curentry = m_entrymap.find(name); - if (curentry == nullptr) + auto curentry = m_entrymap.find(name); + if (curentry == m_entrymap.end()) return; // update the data and default data - curentry->set_default_value(defvalue); + curentry->second->set_default_value(defvalue); } @@ -319,12 +320,12 @@ void core_options::set_default_value(const char *name, const char *defvalue) void core_options::set_description(const char *name, const char *description) { // find the entry and bail if we can't - entry *curentry = m_entrymap.find(name); - if (curentry == nullptr) + auto curentry = m_entrymap.find(name); + if (curentry == m_entrymap.end()) return; // update the data and default data - curentry->set_description(description); + curentry->second->set_description(description); } @@ -350,8 +351,8 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, std:: const char *optionname = is_unadorned ? core_options::unadorned(unadorned_index++) : &curarg[1]; // find our entry; if not found, indicate invalid option - entry *curentry = m_entrymap.find(optionname); - if (curentry == nullptr) + auto curentry = m_entrymap.find(optionname); + if (curentry == m_entrymap.end()) { strcatprintf(error_string, "Error: unknown option: %s\n", curarg); retval = false; @@ -360,7 +361,7 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, std:: } // process commands first - if (curentry->type() == OPTION_COMMAND) + if (curentry->second->type() == OPTION_COMMAND) { // can only have one command if (!m_command.empty()) @@ -368,13 +369,13 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, std:: strcatprintf(error_string,"Error: multiple commands specified -%s and %s\n", m_command.c_str(), curarg); return false; } - m_command = curentry->name(); + m_command = curentry->second->name(); continue; } // get the data for this argument, special casing booleans const char *newdata; - if (curentry->type() == OPTION_BOOLEAN) + if (curentry->second->type() == OPTION_BOOLEAN) newdata = (strncmp(&curarg[1], "no", 2) == 0) ? "0" : "1"; else if (is_unadorned) newdata = curarg; @@ -387,7 +388,7 @@ bool core_options::parse_command_line(int argc, char **argv, int priority, std:: } // set the new data - validate_and_set_data(*curentry, newdata, priority, error_string); + validate_and_set_data(*curentry->second, newdata, priority, error_string); } return retval; } @@ -443,8 +444,8 @@ bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_p *temp = 0; // find our entry - entry *curentry = m_entrymap.find(optionname); - if (curentry == nullptr) + auto curentry = m_entrymap.find(optionname); + if (curentry == m_entrymap.end()) { if (priority >= ignore_priority) strcatprintf(error_string, "Warning: unknown option in INI: %s\n", optionname); @@ -452,7 +453,7 @@ bool core_options::parse_ini_file(core_file &inifile, int priority, int ignore_p } // set the new data - validate_and_set_data(*curentry, optiondata, priority, error_string); + validate_and_set_data(*curentry->second, optiondata, priority, error_string); } return true; } @@ -567,8 +568,8 @@ const char *core_options::output_help(std::string &buffer) const char *core_options::value(const char *name) const { - entry *curentry = m_entrymap.find(name); - return (curentry != nullptr) ? curentry->value() : ""; + auto curentry = m_entrymap.find(name); + return (curentry != m_entrymap.end()) ? curentry->second->value() : ""; } @@ -578,8 +579,8 @@ const char *core_options::value(const char *name) const const char *core_options::description(const char *name) const { - entry *curentry = m_entrymap.find(name); - return (curentry != nullptr) ? curentry->description() : ""; + auto curentry = m_entrymap.find(name); + return (curentry != m_entrymap.end()) ? curentry->second->description() : ""; } @@ -589,8 +590,8 @@ const char *core_options::description(const char *name) const int core_options::priority(const char *name) const { - entry *curentry = m_entrymap.find(name); - return (curentry != nullptr) ? curentry->priority() : 0; + auto curentry = m_entrymap.find(name); + return (curentry != m_entrymap.end()) ? curentry->second->priority() : 0; } @@ -600,8 +601,8 @@ int core_options::priority(const char *name) const UINT32 core_options::seqid(const char *name) const { - entry *curentry = m_entrymap.find(name); - return (curentry != nullptr) ? curentry->seqid() : 0; + auto curentry = m_entrymap.find(name); + return (curentry != m_entrymap.end()) ? curentry->second->seqid() : 0; } //------------------------------------------------- @@ -610,8 +611,7 @@ UINT32 core_options::seqid(const char *name) const bool core_options::exists(const char *name) const { - entry *curentry = m_entrymap.find(name); - return (curentry != nullptr); + return (m_entrymap.find(name) != m_entrymap.end()); } //------------------------------------------------- @@ -621,15 +621,15 @@ bool core_options::exists(const char *name) const bool core_options::set_value(const char *name, const char *value, int priority, std::string &error_string) { // find the entry first - entry *curentry = m_entrymap.find(name); - if (curentry == nullptr) + auto curentry = m_entrymap.find(name); + if (curentry == m_entrymap.end()) { strcatprintf(error_string, "Attempted to set unknown option %s\n", name); return false; } // validate and set the item normally - return validate_and_set_data(*curentry, value, priority, error_string); + return validate_and_set_data(*curentry->second, value, priority, error_string); } bool core_options::set_value(const char *name, int value, int priority, std::string &error_string) @@ -650,12 +650,12 @@ bool core_options::set_value(const char *name, float value, int priority, std::s void core_options::set_flag(const char *name, UINT32 mask, UINT32 flag) { // find the entry first - entry *curentry = m_entrymap.find(name); - if ( curentry == nullptr ) + auto curentry = m_entrymap.find(name); + if ( curentry == m_entrymap.end()) { return; } - curentry->set_flag(mask, flag); + curentry->second->set_flag(mask, flag); } @@ -667,7 +667,7 @@ void core_options::set_flag(const char *name, UINT32 mask, UINT32 flag) void core_options::reset() { m_entrylist.reset(); - m_entrymap.reset(); + m_entrymap.clear(); } @@ -684,11 +684,10 @@ void core_options::append_entry(core_options::entry &newentry) for (int name = 0; name < ARRAY_LENGTH(newentry.m_name); name++) if (newentry.name(name) != nullptr) { - m_entrymap.add(newentry.name(name), &newentry); - + m_entrymap.insert(std::make_pair(newentry.name(name), &newentry)); // for boolean options add a "no" variant as well if (newentry.type() == OPTION_BOOLEAN) - m_entrymap.add(std::string("no").append(newentry.name(name)).c_str(), &newentry); + m_entrymap.insert(std::make_pair(std::string("no").append(newentry.name(name)), &newentry)); } } @@ -703,7 +702,7 @@ void core_options::remove_entry(core_options::entry &delentry) // remove all names from the map for (int name = 0; name < ARRAY_LENGTH(delentry.m_name); name++) if (!delentry.m_name[name].empty()) - m_entrymap.remove(delentry.m_name[name].c_str()); + m_entrymap.erase(m_entrymap.find(delentry.m_name[name])); // remove the entry from the list m_entrylist.remove(delentry); diff --git a/src/lib/util/options.h b/src/lib/util/options.h index a03e8217abf..f193d4a4976 100644 --- a/src/lib/util/options.h +++ b/src/lib/util/options.h @@ -12,7 +12,7 @@ #define __OPTIONS_H__ #include "corefile.h" -#include "tagmap.h" +#include @@ -178,7 +178,7 @@ private: // internal state simple_list m_entrylist; // head of list of entries - tagmap_t m_entrymap; // map for fast lookup + std::unordered_map m_entrymap; // map for fast lookup std::string m_command; // command found static const char *const s_option_unadorned[]; // array of unadorned option "names" }; diff --git a/src/osd/modules/lib/osdobj_common.h b/src/osd/modules/lib/osdobj_common.h index 3e56996f9ec..d1aca5f4e43 100644 --- a/src/osd/modules/lib/osdobj_common.h +++ b/src/osd/modules/lib/osdobj_common.h @@ -267,7 +267,6 @@ protected: debug_module* m_debugger; midi_module* m_midi; private: - //tagmap_t m_video_options; std::vector m_video_names; }; diff --git a/src/tools/chdman.cpp b/src/tools/chdman.cpp index 91e40c51b5b..88a629b97dd 100644 --- a/src/tools/chdman.cpp +++ b/src/tools/chdman.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -96,7 +97,7 @@ const int MODE_GDI = 2; // FUNCTION PROTOTYPES //************************************************************************** -typedef tagmap_t parameters_t; +typedef std::unordered_map parameters_t; static void report_error(int error, const char *format, ...) ATTR_PRINTF(2,3); static void do_info(parameters_t ¶ms); @@ -940,21 +941,21 @@ static void guess_chs(std::string *filename, UINT64 filesize, int sectorsize, UI static void parse_input_chd_parameters(const parameters_t ¶ms, chd_file &input_chd, chd_file &input_parent_chd, bool writeable = false) { // process input parent file - std::string *input_chd_parent_str = params.find(OPTION_INPUT_PARENT); - if (input_chd_parent_str != nullptr) + auto input_chd_parent_str = params.find(OPTION_INPUT_PARENT); + if (input_chd_parent_str != params.end()) { - chd_error err = input_parent_chd.open(input_chd_parent_str->c_str()); + chd_error err = input_parent_chd.open(input_chd_parent_str->second->c_str()); if (err != CHDERR_NONE) - report_error(1, "Error opening parent CHD file (%s): %s", input_chd_parent_str->c_str(), chd_file::error_string(err)); + report_error(1, "Error opening parent CHD file (%s): %s", input_chd_parent_str->second->c_str(), chd_file::error_string(err)); } // process input file - std::string *input_chd_str = params.find(OPTION_INPUT); - if (input_chd_str != nullptr) + auto input_chd_str = params.find(OPTION_INPUT); + if (input_chd_str != params.end()) { - chd_error err = input_chd.open(input_chd_str->c_str(), writeable, input_parent_chd.opened() ? &input_parent_chd : nullptr); + chd_error err = input_chd.open(input_chd_str->second->c_str(), writeable, input_parent_chd.opened() ? &input_parent_chd : nullptr); if (err != CHDERR_NONE) - report_error(1, "Error opening CHD file (%s): %s", input_chd_str->c_str(), chd_file::error_string(err)); + report_error(1, "Error opening CHD file (%s): %s", input_chd_str->second->c_str(), chd_file::error_string(err)); } } @@ -971,29 +972,29 @@ static void parse_input_start_end(const parameters_t ¶ms, UINT64 logical_siz input_end = logical_size; // process input start - std::string *input_start_byte_str = params.find(OPTION_INPUT_START_BYTE); - std::string *input_start_hunk_str = params.find(OPTION_INPUT_START_HUNK); - std::string *input_start_frame_str = params.find(OPTION_INPUT_START_FRAME); - if (input_start_byte_str != nullptr) - input_start = parse_number(input_start_byte_str->c_str()); - if (input_start_hunk_str != nullptr) - input_start = parse_number(input_start_hunk_str->c_str()) * hunkbytes; - if (input_start_frame_str != nullptr) - input_start = parse_number(input_start_frame_str->c_str()) * framebytes; + auto input_start_byte_str = params.find(OPTION_INPUT_START_BYTE); + auto input_start_hunk_str = params.find(OPTION_INPUT_START_HUNK); + auto input_start_frame_str = params.find(OPTION_INPUT_START_FRAME); + if (input_start_byte_str != params.end()) + input_start = parse_number(input_start_byte_str->second->c_str()); + if (input_start_hunk_str != params.end()) + input_start = parse_number(input_start_hunk_str->second->c_str()) * hunkbytes; + if (input_start_frame_str != params.end()) + input_start = parse_number(input_start_frame_str->second->c_str()) * framebytes; if (input_start >= input_end) report_error(1, "Input start offset greater than input file size"); // process input length - std::string *input_length_bytes_str = params.find(OPTION_INPUT_LENGTH_BYTES); - std::string *input_length_hunks_str = params.find(OPTION_INPUT_LENGTH_HUNKS); - std::string *input_length_frames_str = params.find(OPTION_INPUT_LENGTH_FRAMES); + auto input_length_bytes_str = params.find(OPTION_INPUT_LENGTH_BYTES); + auto input_length_hunks_str = params.find(OPTION_INPUT_LENGTH_HUNKS); + auto input_length_frames_str = params.find(OPTION_INPUT_LENGTH_FRAMES); UINT64 input_length = input_end; - if (input_length_bytes_str != nullptr) - input_length = parse_number(input_length_bytes_str->c_str()); - if (input_length_hunks_str != nullptr) - input_length = parse_number(input_length_hunks_str->c_str()) * hunkbytes; - if (input_length_frames_str != nullptr) - input_length = parse_number(input_length_frames_str->c_str()) * framebytes; + if (input_length_bytes_str != params.end()) + input_length = parse_number(input_length_bytes_str->second->c_str()); + if (input_length_hunks_str != params.end()) + input_length = parse_number(input_length_hunks_str->second->c_str()) * hunkbytes; + if (input_length_frames_str != params.end()) + input_length = parse_number(input_length_frames_str->second->c_str()) * framebytes; if (input_start + input_length < input_end) input_end = input_start + input_length; } @@ -1007,7 +1008,7 @@ static void parse_input_start_end(const parameters_t ¶ms, UINT64 logical_siz static void check_existing_output_file(const parameters_t ¶ms, const char *filename) { - if (params.find(OPTION_OUTPUT_FORCE) == nullptr) + if (params.find(OPTION_OUTPUT_FORCE) == params.end()) { core_file *file; file_error filerr = core_fopen(filename, OPEN_FLAG_READ, &file); @@ -1028,19 +1029,19 @@ static void check_existing_output_file(const parameters_t ¶ms, const char *f static std::string *parse_output_chd_parameters(const parameters_t ¶ms, chd_file &output_parent_chd) { // process output parent file - std::string *output_chd_parent_str = params.find(OPTION_OUTPUT_PARENT); - if (output_chd_parent_str != nullptr) + auto output_chd_parent_str = params.find(OPTION_OUTPUT_PARENT); + if (output_chd_parent_str != params.end()) { - chd_error err = output_parent_chd.open(output_chd_parent_str->c_str()); + chd_error err = output_parent_chd.open(output_chd_parent_str->second->c_str()); if (err != CHDERR_NONE) - report_error(1, "Error opening parent CHD file (%s): %s", output_chd_parent_str->c_str(), chd_file::error_string(err)); + report_error(1, "Error opening parent CHD file (%s): %s", output_chd_parent_str->second->c_str(), chd_file::error_string(err)); } // process output file - std::string *output_chd_str = params.find(OPTION_OUTPUT); - if (output_chd_str != nullptr) - check_existing_output_file(params, output_chd_str->c_str()); - return output_chd_str; + auto output_chd_str = params.find(OPTION_OUTPUT); + if (output_chd_str != params.end()) + check_existing_output_file(params, output_chd_str->second->c_str()); + return (output_chd_str != params.end()) ? output_chd_str->second : nullptr; } @@ -1051,10 +1052,10 @@ static std::string *parse_output_chd_parameters(const parameters_t ¶ms, chd_ static void parse_hunk_size(const parameters_t ¶ms, UINT32 required_granularity, UINT32 &hunk_size) { - std::string *hunk_size_str = params.find(OPTION_HUNK_SIZE); - if (hunk_size_str != nullptr) + auto hunk_size_str = params.find(OPTION_HUNK_SIZE); + if (hunk_size_str != params.end()) { - hunk_size = parse_number(hunk_size_str->c_str()); + hunk_size = parse_number(hunk_size_str->second->c_str()); if (hunk_size < 16 || hunk_size > 1024 * 1024) report_error(1, "Invalid hunk size"); if (hunk_size % required_granularity != 0) @@ -1071,12 +1072,12 @@ static void parse_hunk_size(const parameters_t ¶ms, UINT32 required_granular static void parse_compression(const parameters_t ¶ms, chd_codec_type compression[4]) { // see if anything was specified - std::string *compression_str = params.find(OPTION_COMPRESSION); - if (compression_str == nullptr) + auto compression_str = params.find(OPTION_COMPRESSION); + if (compression_str == params.end()) return; // special case: 'none' - if (compression_str->compare("none")==0) + if (compression_str->second->compare("none")==0) { compression[0] = compression[1] = compression[2] = compression[3] = CHD_CODEC_NONE; return; @@ -1084,9 +1085,9 @@ static void parse_compression(const parameters_t ¶ms, chd_codec_type compres // iterate through compressors int index = 0; - for (int start = 0, end = compression_str->find_first_of(','); index < 4; start = end + 1, end = compression_str->find_first_of(',', end + 1)) + for (int start = 0, end = compression_str->second->find_first_of(','); index < 4; start = end + 1, end = compression_str->second->find_first_of(',', end + 1)) { - std::string name(*compression_str, start, (end == -1) ? -1 : end - start); + std::string name(*compression_str->second, start, (end == -1) ? -1 : end - start); if (name.length() != 4) report_error(1, "Invalid compressor '%s' specified", name.c_str()); chd_codec_type type = CHD_MAKE_TAG(name[0], name[1], name[2], name[3]); @@ -1111,11 +1112,11 @@ static void parse_compression(const parameters_t ¶ms, chd_codec_type compres static void parse_numprocessors(const parameters_t ¶ms) { - std::string *numprocessors_str = params.find(OPTION_NUMPROCESSORS); - if (numprocessors_str == nullptr) + auto numprocessors_str = params.find(OPTION_NUMPROCESSORS); + if (numprocessors_str == params.end()) return; - int count = atoi(numprocessors_str->c_str()); + int count = atoi(numprocessors_str->second->c_str()); if (count > 0) { extern int osd_num_processors; @@ -1348,7 +1349,7 @@ static void do_info(parameters_t ¶ms) // print filename and version std::string tempstr; - printf("Input file: %s\n", params.find(OPTION_INPUT)->c_str()); + printf("Input file: %s\n", params.find(OPTION_INPUT)->second->c_str()); printf("File Version: %d\n", input_chd.version()); if (input_chd.version() < 3) report_error(1, "Unsupported version (%d); use an older chdman to upgrade to version 3 or later", input_chd.version()); @@ -1421,7 +1422,7 @@ static void do_info(parameters_t ¶ms) } // print compression stats if verbose - if (params.find(OPTION_VERBOSE) != nullptr) + if (params.find(OPTION_VERBOSE) != params.end()) { UINT32 compression_types[10] = { 0 }; for (UINT32 hunknum = 0; hunknum < input_chd.hunk_count(); hunknum++) @@ -1512,7 +1513,7 @@ static void do_verify(parameters_t ¶ms) UINT32 bytes_to_read = MIN((UINT32)buffer.size(), input_chd.logical_bytes() - offset); chd_error err = input_chd.read_bytes(offset, &buffer[0], bytes_to_read); if (err != CHDERR_NONE) - report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->c_str(), chd_file::error_string(err)); + report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err)); // add to the checksum rawsha1.append(&buffer[0], bytes_to_read); @@ -1528,7 +1529,7 @@ static void do_verify(parameters_t ¶ms) fprintf(stderr, " actual SHA1 = %s\n", computed_sha1.as_string(tempstr)); // fix it if requested; this also fixes the overall one so we don't need to do any more - if (params.find(OPTION_FIX) != nullptr) + if (params.find(OPTION_FIX) != params.end()) { input_chd.set_raw_sha1(computed_sha1); printf("SHA-1 updated to correct value in input CHD\n"); @@ -1551,7 +1552,7 @@ static void do_verify(parameters_t ¶ms) fprintf(stderr, " actual SHA1 = %s\n", computed_overall_sha1.as_string(tempstr)); // fix it if requested - if (params.find(OPTION_FIX) != nullptr) + if (params.find(OPTION_FIX) != params.end()) { input_chd.set_raw_sha1(computed_sha1); printf("SHA-1 updated to correct value in input CHD\n"); @@ -1571,12 +1572,12 @@ static void do_create_raw(parameters_t ¶ms) { // process input file core_file *input_file = nullptr; - std::string *input_file_str = params.find(OPTION_INPUT); - if (input_file_str != nullptr) + auto input_file_str = params.find(OPTION_INPUT); + if (input_file_str != params.end()) { - file_error filerr = core_fopen(input_file_str->c_str(), OPEN_FLAG_READ, &input_file); + file_error filerr = core_fopen(input_file_str->second->c_str(), OPEN_FLAG_READ, &input_file); if (filerr != FILERR_NONE) - report_error(1, "Unable to open file (%s)", input_file_str->c_str()); + report_error(1, "Unable to open file (%s)", input_file_str->second->c_str()); } // process output CHD @@ -1589,10 +1590,10 @@ static void do_create_raw(parameters_t ¶ms) // process unit size UINT32 unit_size = output_parent.opened() ? output_parent.unit_bytes() : 0; - std::string *unit_size_str = params.find(OPTION_UNIT_SIZE); - if (unit_size_str != nullptr) + auto unit_size_str = params.find(OPTION_UNIT_SIZE); + if (unit_size_str != params.end()) { - unit_size = parse_number(unit_size_str->c_str()); + unit_size = parse_number(unit_size_str->second->c_str()); if (hunk_size % unit_size != 0) report_error(1, "Unit size is not an even divisor of the hunk size"); } @@ -1614,8 +1615,8 @@ static void do_create_raw(parameters_t ¶ms) std::string tempstr; printf("Output CHD: %s\n", output_chd_str->c_str()); if (output_parent.opened()) - printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str()); - printf("Input file: %s\n", input_file_str->c_str()); + printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str()); + printf("Input file: %s\n", input_file_str->second->c_str()); if (input_start != 0 || input_end != core_fsize(input_file)) { printf("Input start: %s\n", big_int_string(tempstr, input_start)); @@ -1651,9 +1652,9 @@ static void do_create_raw(parameters_t ¶ms) { delete chd; // delete the output file - std::string *output_chd_str = params.find(OPTION_OUTPUT); - if (output_chd_str != nullptr) - osd_rmfile(output_chd_str->c_str()); + auto output_chd_str = params.find(OPTION_OUTPUT); + if (output_chd_str != params.end()) + osd_rmfile(output_chd_str->second->c_str()); throw; } } @@ -1668,12 +1669,12 @@ static void do_create_hd(parameters_t ¶ms) { // process input file core_file *input_file = nullptr; - std::string *input_file_str = params.find(OPTION_INPUT); - if (input_file_str != nullptr) + auto input_file_str = params.find(OPTION_INPUT); + if (input_file_str != params.end()) { - file_error filerr = core_fopen(input_file_str->c_str(), OPEN_FLAG_READ, &input_file); + file_error filerr = core_fopen(input_file_str->second->c_str(), OPEN_FLAG_READ, &input_file); if (filerr != FILERR_NONE) - report_error(1, "Unable to open file (%s)", input_file_str->c_str()); + report_error(1, "Unable to open file (%s)", input_file_str->second->c_str()); } // process output CHD @@ -1682,12 +1683,12 @@ static void do_create_hd(parameters_t ¶ms) // process sectorsize UINT32 sector_size = output_parent.opened() ? output_parent.unit_bytes() : IDE_SECTOR_SIZE; - std::string *sectorsize_str = params.find(OPTION_SECTOR_SIZE); - if (sectorsize_str != nullptr) + auto sectorsize_str = params.find(OPTION_SECTOR_SIZE); + if (sectorsize_str != params.end()) { if (output_parent.opened()) report_error(1, "Sector size does not apply when creating a diff from the parent"); - sector_size = parse_number(sectorsize_str->c_str()); + sector_size = parse_number(sectorsize_str->second->c_str()); } // process hunk size (needs to know sector_size) @@ -1705,10 +1706,10 @@ static void do_create_hd(parameters_t ¶ms) } else { - std::string *size_str = params.find(OPTION_SIZE); - if (size_str != nullptr) + auto size_str = params.find(OPTION_SIZE); + if (size_str != params.end()) { - if (sscanf(size_str->c_str(), "%" I64FMT"d", &filesize) != 1) + if (sscanf(size_str->second->c_str(), "%" I64FMT"d", &filesize) != 1) report_error(1, "Invalid size string"); } } @@ -1729,12 +1730,12 @@ static void do_create_hd(parameters_t ¶ms) UINT32 cylinders = 0; UINT32 heads = 0; UINT32 sectors = 0; - std::string *chs_str = params.find(OPTION_CHS); - if (chs_str != nullptr) + auto chs_str = params.find(OPTION_CHS); + if (chs_str != params.end()) { if (output_parent.opened()) report_error(1, "CHS does not apply when creating a diff from the parent"); - if (sscanf(chs_str->c_str(), "%d,%d,%d", &cylinders, &heads, §ors) != 3) + if (sscanf(chs_str->second->c_str(), "%d,%d,%d", &cylinders, &heads, §ors) != 3) report_error(1, "Invalid CHS string; must be of the form ,,"); } @@ -1742,17 +1743,17 @@ static void do_create_hd(parameters_t ¶ms) dynamic_buffer identdata; if (output_parent.opened()) output_parent.read_metadata(HARD_DISK_IDENT_METADATA_TAG, 0, identdata); - std::string *ident_str = params.find(OPTION_IDENT); - if (ident_str != nullptr) + auto ident_str = params.find(OPTION_IDENT); + if (ident_str != params.end()) { // load the file - file_error filerr = core_fload(ident_str->c_str(), identdata); + file_error filerr = core_fload(ident_str->second->c_str(), identdata); if (filerr != FILERR_NONE) - report_error(1, "Error reading ident file (%s)", ident_str->c_str()); + report_error(1, "Error reading ident file (%s)", ident_str->second->c_str()); // must be at least 14 bytes; extract CHS data from there if (identdata.size() < 14) - report_error(1, "Ident file '%s' is invalid (too short)", ident_str->c_str()); + report_error(1, "Ident file '%s' is invalid (too short)", ident_str->second->c_str()); cylinders = (identdata[3] << 8) | identdata[2]; heads = (identdata[7] << 8) | identdata[6]; sectors = (identdata[13] << 8) | identdata[12]; @@ -1777,7 +1778,7 @@ static void do_create_hd(parameters_t ¶ms) { if (input_file == nullptr && filesize == 0) report_error(1, "Blank hard drives must specify either a length or a set of CHS values"); - guess_chs(input_file_str, filesize, sector_size, cylinders, heads, sectors, sector_size); + guess_chs((input_file_str != params.end()) ? input_file_str->second : nullptr, filesize, sector_size, cylinders, heads, sectors, sector_size); } UINT32 totalsectors = cylinders * heads * sectors; @@ -1785,10 +1786,10 @@ static void do_create_hd(parameters_t ¶ms) std::string tempstr; printf("Output CHD: %s\n", output_chd_str->c_str()); if (output_parent.opened()) - printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str()); + printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str()); if (input_file != nullptr) { - printf("Input file: %s\n", input_file_str->c_str()); + printf("Input file: %s\n", input_file_str->second->c_str()); if (input_start != 0 || input_end != core_fsize(input_file)) { printf("Input start: %s\n", big_int_string(tempstr, input_start)); @@ -1841,9 +1842,9 @@ static void do_create_hd(parameters_t ¶ms) { delete chd; // delete the output file - std::string *output_chd_str = params.find(OPTION_OUTPUT); - if (output_chd_str != nullptr) - osd_rmfile(output_chd_str->c_str()); + auto output_chd_str = params.find(OPTION_OUTPUT); + if (output_chd_str != params.end()) + osd_rmfile(output_chd_str->second->c_str()); throw; } } @@ -1859,12 +1860,12 @@ static void do_create_cd(parameters_t ¶ms) // process input file chdcd_track_input_info track_info; cdrom_toc toc = { 0 }; - std::string *input_file_str = params.find(OPTION_INPUT); - if (input_file_str != nullptr) + auto input_file_str = params.find(OPTION_INPUT); + if (input_file_str != params.end()) { - chd_error err = chdcd_parse_toc(input_file_str->c_str(), toc, track_info); + chd_error err = chdcd_parse_toc(input_file_str->second->c_str(), toc, track_info); if (err != CHDERR_NONE) - report_error(1, "Error parsing input file (%s: %s)\n", input_file_str->c_str(), chd_file::error_string(err)); + report_error(1, "Error parsing input file (%s: %s)\n", input_file_str->second->c_str(), chd_file::error_string(err)); } // process output CHD @@ -1899,8 +1900,8 @@ static void do_create_cd(parameters_t ¶ms) std::string tempstr; printf("Output CHD: %s\n", output_chd_str->c_str()); if (output_parent.opened()) - printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str()); - printf("Input file: %s\n", input_file_str->c_str()); + printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str()); + printf("Input file: %s\n", input_file_str->second->c_str()); printf("Input tracks: %d\n", toc.numtrks); printf("Input length: %s\n", msf_string_from_frames(tempstr, origtotalsectors)); printf("Compression: %s\n", compression_string(tempstr, compression)); @@ -1933,9 +1934,9 @@ static void do_create_cd(parameters_t ¶ms) { delete chd; // delete the output file - std::string *output_chd_str = params.find(OPTION_OUTPUT); - if (output_chd_str != nullptr) - osd_rmfile(output_chd_str->c_str()); + auto output_chd_str = params.find(OPTION_OUTPUT); + if (output_chd_str != params.end()) + osd_rmfile(output_chd_str->second->c_str()); throw; } } @@ -1950,12 +1951,12 @@ static void do_create_ld(parameters_t ¶ms) { // process input file avi_file *input_file = nullptr; - std::string *input_file_str = params.find(OPTION_INPUT); - if (input_file_str != nullptr) + auto input_file_str = params.find(OPTION_INPUT); + if (input_file_str != params.end()) { - avi_error avierr = avi_open(input_file_str->c_str(), &input_file); + avi_error avierr = avi_open(input_file_str->second->c_str(), &input_file); if (avierr != AVIERR_NONE) - report_error(1, "Error opening AVI file (%s): %s\n", input_file_str->c_str(), avi_error_string(avierr)); + report_error(1, "Error opening AVI file (%s): %s\n", input_file_str->second->c_str(), avi_error_string(avierr)); } const avi_movie_info *aviinfo = avi_get_movie_info(input_file); @@ -2009,8 +2010,8 @@ static void do_create_ld(parameters_t ¶ms) std::string tempstr; printf("Output CHD: %s\n", output_chd_str->c_str()); if (output_parent.opened()) - printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str()); - printf("Input file: %s\n", input_file_str->c_str()); + printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str()); + printf("Input file: %s\n", input_file_str->second->c_str()); if (input_start != 0 && input_end != aviinfo->video_numsamples) printf("Input start: %s\n", big_int_string(tempstr, input_start)); printf("Input length: %s (%02d:%02d:%02d)\n", big_int_string(tempstr, input_end - input_start), @@ -2061,9 +2062,9 @@ static void do_create_ld(parameters_t ¶ms) { delete chd; // delete the output file - std::string *output_chd_str = params.find(OPTION_OUTPUT); - if (output_chd_str != nullptr) - osd_rmfile(output_chd_str->c_str()); + auto output_chd_str = params.find(OPTION_OUTPUT); + if (output_chd_str != params.end()) + osd_rmfile(output_chd_str->second->c_str()); throw; } } @@ -2122,8 +2123,8 @@ static void do_copy(parameters_t ¶ms) std::string tempstr; printf("Output CHD: %s\n", output_chd_str->c_str()); if (output_parent.opened()) - printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str()); - printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str()); + printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str()); + printf("Input CHD: %s\n", params.find(OPTION_INPUT)->second->c_str()); if (input_start != 0 || input_end != input_chd.logical_bytes()) { printf("Input start: %s\n", big_int_string(tempstr, input_start)); @@ -2197,9 +2198,9 @@ static void do_copy(parameters_t ¶ms) { delete chd; // delete the output file - std::string *output_chd_str = params.find(OPTION_OUTPUT); - if (output_chd_str != nullptr) - osd_rmfile(output_chd_str->c_str()); + auto output_chd_str = params.find(OPTION_OUTPUT); + if (output_chd_str != params.end()) + osd_rmfile(output_chd_str->second->c_str()); throw; } } @@ -2223,14 +2224,14 @@ static void do_extract_raw(parameters_t ¶ms) parse_input_start_end(params, input_chd.logical_bytes(), input_chd.hunk_bytes(), input_chd.hunk_bytes(), input_start, input_end); // verify output file doesn't exist - std::string *output_file_str = params.find(OPTION_OUTPUT); - if (output_file_str != nullptr) - check_existing_output_file(params, output_file_str->c_str()); + auto output_file_str = params.find(OPTION_OUTPUT); + if (output_file_str != params.end()) + check_existing_output_file(params, output_file_str->second->c_str()); // print some info std::string tempstr; - printf("Output File: %s\n", output_file_str->c_str()); - printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str()); + printf("Output File: %s\n", output_file_str->second->c_str()); + printf("Input CHD: %s\n", params.find(OPTION_INPUT)->second->c_str()); if (input_start != 0 || input_end != input_chd.logical_bytes()) { printf("Input start: %s\n", big_int_string(tempstr, input_start)); @@ -2242,9 +2243,9 @@ static void do_extract_raw(parameters_t ¶ms) try { // process output file - file_error filerr = core_fopen(output_file_str->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file); + file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file); if (filerr != FILERR_NONE) - report_error(1, "Unable to open file (%s)", output_file_str->c_str()); + report_error(1, "Unable to open file (%s)", output_file_str->second->c_str()); // copy all data dynamic_buffer buffer((TEMP_BUFFER_SIZE / input_chd.hunk_bytes()) * input_chd.hunk_bytes()); @@ -2256,12 +2257,12 @@ static void do_extract_raw(parameters_t ¶ms) UINT32 bytes_to_read = MIN((UINT32)buffer.size(), input_end - offset); chd_error err = input_chd.read_bytes(offset, &buffer[0], bytes_to_read); if (err != CHDERR_NONE) - report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->c_str(), chd_file::error_string(err)); + report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err)); // write to the output UINT32 count = core_fwrite(output_file, &buffer[0], bytes_to_read); if (count != bytes_to_read) - report_error(1, "Error writing to file; check disk space (%s)", output_file_str->c_str()); + report_error(1, "Error writing to file; check disk space (%s)", output_file_str->second->c_str()); // advance offset += bytes_to_read; @@ -2277,7 +2278,7 @@ static void do_extract_raw(parameters_t ¶ms) if (output_file != nullptr) { core_fclose(output_file); - osd_rmfile(output_file_str->c_str()); + osd_rmfile(output_file_str->second->c_str()); } throw; } @@ -2303,28 +2304,32 @@ static void do_extract_cd(parameters_t ¶ms) const cdrom_toc *toc = cdrom_get_toc(cdrom); // verify output file doesn't exist - std::string *output_file_str = params.find(OPTION_OUTPUT); - if (output_file_str != nullptr) - check_existing_output_file(params, output_file_str->c_str()); + auto output_file_str = params.find(OPTION_OUTPUT); + if (output_file_str != params.end()) + check_existing_output_file(params, output_file_str->second->c_str()); // verify output BIN file doesn't exist - std::string *output_bin_file_str = params.find(OPTION_OUTPUT_BIN); - std::string default_name(*output_file_str); + auto output_bin_file_fnd = params.find(OPTION_OUTPUT_BIN); + std::string default_name(*output_file_str->second); int chop = default_name.find_last_of('.'); if (chop != -1) default_name.substr(0, chop); char basename[128]; strncpy(basename, default_name.c_str(), 127); default_name.append(".bin"); - if (output_bin_file_str == nullptr) + std::string *output_bin_file_str; + if (output_bin_file_fnd == params.end()) output_bin_file_str = &default_name; + else + output_bin_file_str = output_bin_file_fnd->second; + check_existing_output_file(params, output_bin_file_str->c_str()); // print some info std::string tempstr; - printf("Output TOC: %s\n", output_file_str->c_str()); + printf("Output TOC: %s\n", output_file_str->second->c_str()); printf("Output Data: %s\n", output_bin_file_str->c_str()); - printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str()); + printf("Input CHD: %s\n", params.find(OPTION_INPUT)->second->c_str()); // catch errors so we can close & delete the output file core_file *output_bin_file = nullptr; @@ -2333,19 +2338,19 @@ static void do_extract_cd(parameters_t ¶ms) { int mode = MODE_NORMAL; - if (output_file_str->find(".cue") != -1) + if (output_file_str->second->find(".cue") != -1) { mode = MODE_CUEBIN; } - else if (output_file_str->find(".gdi") != -1) + else if (output_file_str->second->find(".gdi") != -1) { mode = MODE_GDI; } // process output file - file_error filerr = core_fopen(output_file_str->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &output_toc_file); + file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &output_toc_file); if (filerr != FILERR_NONE) - report_error(1, "Unable to open file (%s)", output_file_str->c_str()); + report_error(1, "Unable to open file (%s)", output_file_str->second->c_str()); // process output BIN file if (mode != MODE_GDI) @@ -2457,7 +2462,7 @@ static void do_extract_cd(parameters_t ¶ms) core_fseek(output_bin_file, outputoffs, SEEK_SET); UINT32 byteswritten = core_fwrite(output_bin_file, &buffer[0], bufferoffs); if (byteswritten != bufferoffs) - report_error(1, "Error writing frame %d to file (%s): %s\n", frame, output_file_str->c_str(), chd_file::error_string(CHDERR_WRITE_ERROR)); + report_error(1, "Error writing frame %d to file (%s): %s\n", frame, output_file_str->second->c_str(), chd_file::error_string(CHDERR_WRITE_ERROR)); outputoffs += bufferoffs; bufferoffs = 0; } @@ -2479,7 +2484,7 @@ static void do_extract_cd(parameters_t ¶ms) if (output_toc_file != nullptr) core_fclose(output_toc_file); osd_rmfile(output_bin_file_str->c_str()); - osd_rmfile(output_file_str->c_str()); + osd_rmfile(output_file_str->second->c_str()); throw; } } @@ -2550,14 +2555,14 @@ static void do_extract_ld(parameters_t ¶ms) info.audio_samplerate = rate; // verify output file doesn't exist - std::string *output_file_str = params.find(OPTION_OUTPUT); - if (output_file_str != nullptr) - check_existing_output_file(params, output_file_str->c_str()); + auto output_file_str = params.find(OPTION_OUTPUT); + if (output_file_str != params.end()) + check_existing_output_file(params, output_file_str->second->c_str()); // print some info std::string tempstr; - printf("Output File: %s\n", output_file_str->c_str()); - printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str()); + printf("Output File: %s\n", output_file_str->second->c_str()); + printf("Input CHD: %s\n", params.find(OPTION_INPUT)->second->c_str()); if (input_start != 0 || input_end != input_chd.hunk_count()) { printf("Input start: %s\n", big_int_string(tempstr, input_start)); @@ -2569,9 +2574,9 @@ static void do_extract_ld(parameters_t ¶ms) try { // process output file - avi_error avierr = avi_create(output_file_str->c_str(), &info, &output_file); + avi_error avierr = avi_create(output_file_str->second->c_str(), &info, &output_file); if (avierr != AVIERR_NONE) - report_error(1, "Unable to open file (%s)", output_file_str->c_str()); + report_error(1, "Unable to open file (%s)", output_file_str->second->c_str()); // create the codec configuration avhuff_decompress_config avconfig; @@ -2581,7 +2586,7 @@ static void do_extract_ld(parameters_t ¶ms) avconfig.actsamples = &actsamples; for (int chnum = 0; chnum < ARRAY_LENGTH(audio_data); chnum++) { - audio_data[chnum].resize(max_samples_per_frame); + audio_data[chnum].resize(MAX(1,max_samples_per_frame)); avconfig.audio[chnum] = &audio_data[chnum][0]; } @@ -2600,7 +2605,7 @@ static void do_extract_ld(parameters_t ¶ms) if (err != CHDERR_NONE) { UINT64 filepos = core_ftell(input_chd); - report_error(1, "Error reading hunk %" I64FMT "d at offset %" I64FMT "d from CHD file (%s): %s\n", framenum, filepos, params.find(OPTION_INPUT)->c_str(), chd_file::error_string(err)); + report_error(1, "Error reading hunk %" I64FMT "d at offset %" I64FMT "d from CHD file (%s): %s\n", framenum, filepos, params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err)); } // write audio @@ -2608,7 +2613,7 @@ static void do_extract_ld(parameters_t ¶ms) { avi_error avierr = avi_append_sound_samples(output_file, chnum, avconfig.audio[chnum], actsamples, 0); if (avierr != AVIERR_NONE) - report_error(1, "Error writing samples for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->c_str(), avi_error_string(avierr)); + report_error(1, "Error writing samples for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_error_string(avierr)); } // write video @@ -2616,7 +2621,7 @@ static void do_extract_ld(parameters_t ¶ms) { avi_error avierr = avi_append_video_frame(output_file, fullbitmap); if (avierr != AVIERR_NONE) - report_error(1, "Error writing video for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->c_str(), avi_error_string(avierr)); + report_error(1, "Error writing video for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_error_string(avierr)); } } @@ -2629,7 +2634,7 @@ static void do_extract_ld(parameters_t ¶ms) // delete the output file if (output_file != nullptr) avi_close(output_file); - osd_rmfile(output_file_str->c_str()); + osd_rmfile(output_file_str->second->c_str()); throw; } } @@ -2649,63 +2654,63 @@ static void do_add_metadata(parameters_t ¶ms) // process tag chd_metadata_tag tag = CHD_MAKE_TAG('?','?','?','?'); - std::string *tag_str = params.find(OPTION_TAG); - if (tag_str != nullptr) + auto tag_str = params.find(OPTION_TAG); + if (tag_str != params.end()) { - tag_str->append(" "); - tag = CHD_MAKE_TAG((*tag_str)[0], (*tag_str)[1], (*tag_str)[2], (*tag_str)[3]); + tag_str->second->append(" "); + tag = CHD_MAKE_TAG((*tag_str->second)[0], (*tag_str->second)[1], (*tag_str->second)[2], (*tag_str->second)[3]); } // process index UINT32 index = 0; - std::string *index_str = params.find(OPTION_INDEX); - if (index_str != nullptr) - index = atoi(index_str->c_str()); + auto index_str = params.find(OPTION_INDEX); + if (index_str != params.end()) + index = atoi(index_str->second->c_str()); // process text input - std::string *text_str = params.find(OPTION_VALUE_TEXT); + auto text_str = params.find(OPTION_VALUE_TEXT); std::string text; - if (text_str != nullptr) + if (text_str != params.end()) { - text = *text_str; + text = *text_str->second; if (text[0] == '"' && text[text.length() - 1] == '"') text.substr(1, text.length() - 2); } // process file input - std::string *file_str = params.find(OPTION_VALUE_FILE); + auto file_str = params.find(OPTION_VALUE_FILE); dynamic_buffer file; - if (file_str != nullptr) + if (file_str != params.end()) { - file_error filerr = core_fload(file_str->c_str(), file); + file_error filerr = core_fload(file_str->second->c_str(), file); if (filerr != FILERR_NONE) - report_error(1, "Error reading metadata file (%s)", file_str->c_str()); + report_error(1, "Error reading metadata file (%s)", file_str->second->c_str()); } // make sure we have one or the other - if (text_str == nullptr && file_str == nullptr) + if (text_str == params.end() && file_str == params.end()) report_error(1, "Error: missing either --valuetext/-vt or --valuefile/-vf parameters"); - if (text_str != nullptr && file_str != nullptr) + if (text_str != params.end() && file_str != params.end()) report_error(1, "Error: both --valuetext/-vt or --valuefile/-vf parameters specified; only one permitted"); // process no checksum UINT8 flags = CHD_MDFLAGS_CHECKSUM; - if (params.find(OPTION_NO_CHECKSUM) != nullptr) + if (params.find(OPTION_NO_CHECKSUM) != params.end()) flags &= ~CHD_MDFLAGS_CHECKSUM; // print some info std::string tempstr; - printf("Input file: %s\n", params.find(OPTION_INPUT)->c_str()); + printf("Input file: %s\n", params.find(OPTION_INPUT)->second->c_str()); printf("Tag: %c%c%c%c\n", (tag >> 24) & 0xff, (tag >> 16) & 0xff, (tag >> 8) & 0xff, tag & 0xff); printf("Index: %d\n", index); - if (text_str != nullptr) + if (text_str != params.end()) printf("Text: %s\n", text.c_str()); else - printf("Data: %s (%d bytes)\n", file_str->c_str(), int(file.size())); + printf("Data: %s (%d bytes)\n", file_str->second->c_str(), int(file.size())); // write the metadata chd_error err; - if (text_str != nullptr) + if (text_str != params.end()) err = input_chd.write_metadata(tag, index, text, flags); else err = input_chd.write_metadata(tag, index, &file[0], flags); @@ -2729,22 +2734,22 @@ static void do_del_metadata(parameters_t ¶ms) // process tag chd_metadata_tag tag = CHD_MAKE_TAG('?','?','?','?'); - std::string *tag_str = params.find(OPTION_TAG); - if (tag_str != nullptr) + auto tag_str = params.find(OPTION_TAG); + if (tag_str != params.end()) { - tag_str->append(" "); - tag = CHD_MAKE_TAG((*tag_str)[0], (*tag_str)[1], (*tag_str)[2], (*tag_str)[3]); + tag_str->second->append(" "); + tag = CHD_MAKE_TAG((*tag_str->second)[0], (*tag_str->second)[1], (*tag_str->second)[2], (*tag_str->second)[3]); } // process index UINT32 index = 0; - std::string *index_str = params.find(OPTION_INDEX); - if (index_str != nullptr) - index = atoi(index_str->c_str()); + auto index_str = params.find(OPTION_INDEX); + if (index_str != params.end()) + index = atoi(index_str->second->c_str()); // print some info std::string tempstr; - printf("Input file: %s\n", params.find(OPTION_INPUT)->c_str()); + printf("Input file: %s\n", params.find(OPTION_INPUT)->second->c_str()); printf("Tag: %c%c%c%c\n", (tag >> 24) & 0xff, (tag >> 16) & 0xff, (tag >> 8) & 0xff, tag & 0xff); printf("Index: %d\n", index); @@ -2769,24 +2774,24 @@ static void do_dump_metadata(parameters_t ¶ms) parse_input_chd_parameters(params, input_chd, input_parent_chd); // verify output file doesn't exist - std::string *output_file_str = params.find(OPTION_OUTPUT); - if (output_file_str != nullptr) - check_existing_output_file(params, output_file_str->c_str()); + auto output_file_str = params.find(OPTION_OUTPUT); + if (output_file_str != params.end()) + check_existing_output_file(params, output_file_str->second->c_str()); // process tag chd_metadata_tag tag = CHD_MAKE_TAG('?','?','?','?'); - std::string *tag_str = params.find(OPTION_TAG); - if (tag_str != nullptr) + auto tag_str = params.find(OPTION_TAG); + if (tag_str != params.end()) { - tag_str->append(" "); - tag = CHD_MAKE_TAG((*tag_str)[0], (*tag_str)[1], (*tag_str)[2], (*tag_str)[3]); + tag_str->second->append(" "); + tag = CHD_MAKE_TAG((*tag_str->second)[0], (*tag_str->second)[1], (*tag_str->second)[2], (*tag_str->second)[3]); } // process index UINT32 index = 0; - std::string *index_str = params.find(OPTION_INDEX); - if (index_str != nullptr) - index = atoi(index_str->c_str()); + auto index_str = params.find(OPTION_INDEX); + if (index_str != params.end()) + index = atoi(index_str->second->c_str()); // write the metadata dynamic_buffer buffer; @@ -2799,21 +2804,21 @@ static void do_dump_metadata(parameters_t ¶ms) try { // create the file - if (output_file_str != nullptr) + if (output_file_str != params.end()) { - file_error filerr = core_fopen(output_file_str->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file); + file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file); if (filerr != FILERR_NONE) - report_error(1, "Unable to open file (%s)", output_file_str->c_str()); + report_error(1, "Unable to open file (%s)", output_file_str->second->c_str()); // output the metadata UINT32 count = core_fwrite(output_file, &buffer[0], buffer.size()); if (count != buffer.size()) - report_error(1, "Error writing file (%s)", output_file_str->c_str()); + report_error(1, "Error writing file (%s)", output_file_str->second->c_str()); core_fclose(output_file); // provide some feedback std::string tempstr; - printf("File (%s) written, %s bytes\n", output_file_str->c_str(), big_int_string(tempstr, buffer.size())); + printf("File (%s) written, %s bytes\n", output_file_str->second->c_str(), big_int_string(tempstr, buffer.size())); } // flush to stdout @@ -2828,7 +2833,7 @@ static void do_dump_metadata(parameters_t ¶ms) // delete the output file if (output_file != nullptr) core_fclose(output_file); - osd_rmfile(output_file_str->c_str()); + osd_rmfile(output_file_str->second->c_str()); throw; } } @@ -2868,7 +2873,7 @@ int CLIB_DECL main(int argc, char *argv[]) return print_help(argv[0], desc); // otherwise, verify the parameters - tagmap_t parameters; + parameters_t parameters; while (argnum < argc) { // should be an option name @@ -2909,7 +2914,7 @@ int CLIB_DECL main(int argc, char *argv[]) } // add to the map - if (parameters.add(odesc.name, new std::string(param)) == TMERR_DUPLICATE) + if (!parameters.insert(std::make_pair(odesc.name, new std::string(param))).second) return print_help(argv[0], desc, "Multiple parameters of the same type specified"); break; } @@ -2926,7 +2931,7 @@ int CLIB_DECL main(int argc, char *argv[]) const char *validname = desc.valid_options[valid]; if (validname == nullptr) break; - if (*validname == REQUIRED[0] && parameters.find(++validname) == nullptr) + if (*validname == REQUIRED[0] && parameters.find(++validname) == parameters.end()) return print_help(argv[0], desc, "Required parameters missing"); } -- cgit v1.2.3-70-g09d2