From 8e169de1cdfe353a6360f7679e0f033f968a164b Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Tue, 19 Jul 2016 22:17:12 -0400 Subject: [PATCH 1/3] Using std::string more pervasively in softlist.cpp --- src/emu/softlist.cpp | 42 +++++++++++++++---------------- src/emu/softlist.h | 60 +++++++++++++++++++++----------------------- 2 files changed, 48 insertions(+), 54 deletions(-) diff --git a/src/emu/softlist.cpp b/src/emu/softlist.cpp index b4dba456a4a..1b771667d81 100644 --- a/src/emu/softlist.cpp +++ b/src/emu/softlist.cpp @@ -102,15 +102,12 @@ const device_type SOFTWARE_LIST = &device_creator; // software_part - constructor //------------------------------------------------- -software_part::software_part(software_info &info, const char *name, const char *interface) +software_part::software_part(software_info &info, const std::string &name, const std::string &interface) : m_next(nullptr), m_info(info), m_name(name), m_interface(interface) { - // ensure strings we are passed are in the string pool - assert(info.list().string_pool_contains(name)); - assert(info.list().string_pool_contains(interface)); } @@ -190,7 +187,7 @@ software_compatibility software_part::is_compatible(const software_list_device & bool software_part::matches_interface(const char *interface_list) const { // if we have no interface, then we match by default - if (m_interface == nullptr) + if (m_interface.empty()) return true; // copy the comma-delimited interface list and ensure it ends with a final comma @@ -239,7 +236,7 @@ device_image_interface *software_part::find_mountable_image(const machine_config // software_info - constructor //------------------------------------------------- -software_info::software_info(software_list_device &list, const char *name, const char *parent, const char *supported) +software_info::software_info(software_list_device &list, const std::string &name, const std::string &parent, const char *supported) : m_next(nullptr), m_list(list), m_supported(SOFTWARE_SUPPORTED_YES), @@ -249,10 +246,6 @@ software_info::software_info(software_list_device &list, const char *name, const m_year(nullptr), m_publisher(nullptr) { - // ensure strings we are passed are in the string pool - assert(list.string_pool_contains(name)); - assert(list.string_pool_contains(parent)); - // handle the supported flag if provided if (supported != nullptr) { @@ -426,7 +419,6 @@ void software_list_device::release() m_description = nullptr; m_errors.clear(); m_infolist.reset(); - m_stringpool.reset(); } @@ -801,10 +793,16 @@ void softlist_parser::add_rom_entry(const char *name, const char *hashdata, UINT if (elem._name != nullptr && strcmp(elem._name, name) == 0) parse_error("Duplicated dataarea %s in software %s", name, infoname()); + // get our own copy of these strings (ideally rom_entry would use std::string) + m_current_part->m_romdata_strings.emplace_back(name); + name = m_current_part->m_romdata_strings.back().c_str(); + m_current_part->m_romdata_strings.emplace_back(hashdata); + hashdata = m_current_part->m_romdata_strings.back().c_str(); + // create the new entry and append it rom_entry entry; - entry._name = m_list.add_string(name); - entry._hashdata = m_list.add_string(hashdata); + entry._name = name; + entry._hashdata = hashdata; entry._offset = offset; entry._length = length; entry._flags = flags; @@ -924,7 +922,7 @@ void softlist_parser::parse_root_start(const char *tagname, const char **attribu parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); if (attrvalues[1] != nullptr) - m_list.m_description = m_list.add_string(attrvalues[1]); + m_list.m_description = attrvalues[1]; } else unknown_tag(tagname); @@ -946,7 +944,7 @@ void softlist_parser::parse_main_start(const char *tagname, const char **attribu parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); if (attrvalues[0] != nullptr) - m_current_info = &m_list.m_infolist.append(*global_alloc(software_info(m_list, m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1]), attrvalues[2]))); + m_current_info = &m_list.m_infolist.append(*global_alloc(software_info(m_list, attrvalues[0], attrvalues[1], attrvalues[2]))); else parse_error("No name defined for item"); } @@ -989,7 +987,7 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); if (attrvalues[0] != nullptr && attrvalues[1] != nullptr) - m_current_info->m_other_info.append(*global_alloc(feature_list_item(m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1])))); + m_current_info->m_other_info.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1]))); else parse_error("Incomplete other_info definition"); } @@ -1002,7 +1000,7 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); if (attrvalues[0] != nullptr && attrvalues[1] != nullptr) - m_current_info->m_shared_info.append(*global_alloc(feature_list_item(m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1])))); + m_current_info->m_shared_info.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1]))); else parse_error("Incomplete sharedfeat definition"); } @@ -1015,7 +1013,7 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); if (attrvalues[0] != nullptr && attrvalues[1] != nullptr && strcmp(attrvalues[0], "") != 0 && strcmp(attrvalues[1], "") != 0) - m_current_part = &m_current_info->m_partdata.append(*global_alloc(software_part(*m_current_info, m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1])))); + m_current_part = &m_current_info->m_partdata.append(*global_alloc(software_part(*m_current_info, attrvalues[0], attrvalues[1]))); else parse_error("Incomplete part definition"); } @@ -1102,7 +1100,7 @@ void softlist_parser::parse_part_start(const char *tagname, const char **attribu parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); if (attrvalues[0] != nullptr) - m_current_part->m_featurelist.append(*global_alloc(feature_list_item(m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1])))); + m_current_part->m_featurelist.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1]))); else parse_error("Incomplete feature definition"); } @@ -1247,15 +1245,15 @@ void softlist_parser::parse_soft_end(const char *tagname) // if (strcmp(tagname, "description") == 0) - m_current_info->m_longname = m_list.add_string(m_data_accum.c_str()); + m_current_info->m_longname = m_data_accum; // else if (strcmp(tagname, "year") == 0) - m_current_info->m_year = m_list.add_string(m_data_accum.c_str()); + m_current_info->m_year = m_data_accum; // else if (strcmp(tagname, "publisher") == 0) - m_current_info->m_publisher = m_list.add_string(m_data_accum.c_str()); + m_current_info->m_publisher = m_data_accum; // else if (strcmp(tagname, "part") == 0) diff --git a/src/emu/softlist.h b/src/emu/softlist.h index c5082e16903..a06c69b2b62 100644 --- a/src/emu/softlist.h +++ b/src/emu/softlist.h @@ -82,21 +82,21 @@ class feature_list_item public: // construction/destruction - feature_list_item(const char *name = nullptr, const char *value = nullptr) + feature_list_item(const std::string &name, const std::string &value) : m_next(nullptr), m_name(name), m_value(value) { } // getters feature_list_item *next() const { return m_next; } - const char *name() const { return m_name; } - const char *value() const { return m_value; } + const char *name() const { return m_name.c_str(); } + const char *value() const { return m_value.c_str(); } private: // internal state feature_list_item * m_next; - const char * m_name; - const char * m_value; + std::string m_name; + std::string m_value; }; @@ -110,13 +110,13 @@ class software_part public: // construction/destruction - software_part(software_info &info, const char *name = nullptr, const char *interface = nullptr); + software_part(software_info &info, const std::string &name, const std::string &interface); // getters software_part *next() const { return m_next; } software_info &info() const { return m_info; } - const char *name() const { return m_name; } - const char *interface() const { return m_interface; } + const char *name() const { return m_name.c_str(); } + const char *interface() const { return m_interface.c_str(); } const simple_list &featurelist() const { return m_featurelist; } const rom_entry *romdata(unsigned int index = 0) const { return (index < m_romdata.size()) ? &m_romdata[index] : nullptr; } @@ -128,12 +128,13 @@ public: private: // internal state - software_part * m_next; - software_info & m_info; - const char * m_name; - const char * m_interface; - simple_list m_featurelist; - std::vector m_romdata; + software_part * m_next; + software_info & m_info; + std::string m_name; + std::string m_interface; + simple_list m_featurelist; + std::vector m_romdata; + std::vector m_romdata_strings; }; @@ -147,16 +148,16 @@ class software_info public: // construction/destruction - software_info(software_list_device &list, const char *name, const char *parent, const char *supported); + software_info(software_list_device &list, const std::string &name, const std::string &parent, const char *supported); // getters software_info *next() const { return m_next; } software_list_device &list() const { return m_list; } - const char *shortname() const { return m_shortname; } - const char *longname() const { return m_longname; } - const char *parentname() const { return m_parentname; } - const char *year() const { return m_year; } - const char *publisher() const { return m_publisher; } + const char *shortname() const { return m_shortname.c_str(); } + const char *longname() const { return m_longname.c_str(); } + const char *parentname() const { return m_parentname.c_str(); } + const char *year() const { return m_year.c_str(); } + const char *publisher() const { return m_publisher.c_str(); } const simple_list &other_info() const { return m_other_info; } const simple_list &shared_info() const { return m_shared_info; } UINT32 supported() const { return m_supported; } @@ -172,11 +173,11 @@ private: software_info * m_next; software_list_device & m_list; UINT32 m_supported; - const char * m_shortname; - const char * m_longname; - const char * m_parentname; - const char * m_year; // Copyright year on title screen, actual release dates can be tracked in external resources - const char * m_publisher; + std::string m_shortname; + std::string m_longname; + std::string m_parentname; + std::string m_year; // Copyright year on title screen, actual release dates can be tracked in external resources + std::string m_publisher; simple_list m_other_info; // Here we store info like developer, serial #, etc. which belong to the software entry as a whole simple_list m_shared_info; // Here we store info like TV standard compatibility, or add-on requirements, etc. which get inherited // by each part of this software entry (after loading these are stored in partdata->featurelist) @@ -206,7 +207,7 @@ public: const char *filename() { return m_file.filename(); } // getters that may trigger a parse - const char *description() { if (!m_parsed) parse(); return m_description; } + const char *description() { if (!m_parsed) parse(); return m_description.c_str(); } bool valid() { if (!m_parsed) parse(); return m_infolist.count() > 0; } const char *errors_string() { if (!m_parsed) parse(); return m_errors.c_str(); } const simple_list &get_info() { if (!m_parsed) parse(); return m_infolist; } @@ -216,10 +217,6 @@ public: void find_approx_matches(const char *name, int matches, const software_info **list, const char *interface); void release(); - // string pool helpers - const char *add_string(const char *string) { return m_stringpool.add(string); } - bool string_pool_contains(const char *string) { return m_stringpool.contains(string); } - // static helpers static software_list_device *find_by_name(const machine_config &mconfig, const char *name); static void display_matches(const machine_config &config, const char *interface, const char *name); @@ -241,10 +238,9 @@ protected: // internal state bool m_parsed; emu_file m_file; - const char * m_description; + std::string m_description; std::string m_errors; simple_list m_infolist; - const_string_pool m_stringpool; }; From c86ab9dbace9fe1bd78f9baa488af8d17d7fe6f5 Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Wed, 20 Jul 2016 09:44:27 -0400 Subject: [PATCH 2/3] Exposed several strings as std::string on softlist objects, and fixed a few bugs --- src/emu/diimage.cpp | 7 +- src/emu/romload.cpp | 3 +- src/emu/softlist.cpp | 178 ++++++++++++++---------------- src/emu/softlist.h | 22 ++-- src/frontend/mame/audit.cpp | 2 +- src/frontend/mame/clifront.cpp | 24 ++-- src/frontend/mame/ui/datmenu.cpp | 6 +- src/frontend/mame/ui/filemngr.cpp | 2 +- src/frontend/mame/ui/imgcntrl.cpp | 2 +- src/frontend/mame/ui/inifile.cpp | 12 +- src/frontend/mame/ui/selsoft.cpp | 16 +-- 11 files changed, 132 insertions(+), 142 deletions(-) diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp index e3314bcaaf5..5d603d29fda 100644 --- a/src/emu/diimage.cpp +++ b/src/emu/diimage.cpp @@ -867,8 +867,7 @@ bool device_image_interface::load_software(software_list_device &swlist, const c while (swinfo != nullptr) { locationtag.append(swinfo->shortname()).append(breakstr); - const char *parentname = swinfo->parentname(); - swinfo = (parentname != nullptr) ? swlist.find(parentname) : nullptr; + swinfo = !swinfo->parentname().empty() ? swlist.find(swinfo->parentname().c_str()) : nullptr; } // strip the final '%' locationtag.erase(locationtag.length() - 1, 1); @@ -1008,7 +1007,7 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int if ( m_software_info_ptr ) { // sanitize - if (m_software_info_ptr->longname() == nullptr || m_software_info_ptr->publisher() == nullptr || m_software_info_ptr->year() == nullptr) + if (m_software_info_ptr->longname().empty() || m_software_info_ptr->publisher().empty() || m_software_info_ptr->year().empty()) fatalerror("Each entry in an XML list must have all of the following fields: description, publisher, year!\n"); // store @@ -1352,7 +1351,7 @@ bool device_image_interface::load_software_part(const char *path, const software // Load the software part software_list_device &swlist = swpart->info().list(); - bool result = call_softlist_load(swlist, swpart->info().shortname(), swpart->romdata()); + bool result = call_softlist_load(swlist, swpart->info().shortname().c_str(), swpart->romdata()); // Tell the world which part we actually loaded std::string full_sw_name = string_format("%s:%s:%s", swlist.list_name(), swpart->info().shortname(), swpart->name()); diff --git a/src/emu/romload.cpp b/src/emu/romload.cpp index deb3ad6d8aa..91a8f9bd77d 100644 --- a/src/emu/romload.cpp +++ b/src/emu/romload.cpp @@ -1299,8 +1299,7 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list while (swinfo != nullptr) { locationtag.append(swinfo->shortname()).append(breakstr); - const char *parentname = swinfo->parentname(); - swinfo = (parentname != nullptr) ? swlist.find(parentname) : nullptr; + swinfo = !swinfo->parentname().empty() ? swlist.find(swinfo->parentname().c_str()) : nullptr; } // strip the final '%' locationtag.erase(locationtag.length() - 1, 1); diff --git a/src/emu/softlist.cpp b/src/emu/softlist.cpp index 1b771667d81..8e46d654d0e 100644 --- a/src/emu/softlist.cpp +++ b/src/emu/softlist.cpp @@ -44,7 +44,7 @@ private: // internal parsing helpers const char *filename() const { return m_list.filename(); } - const char *infoname() const { return (m_current_info != nullptr) ? m_current_info->shortname() : "???"; } + const char *infoname() const { return (m_current_info != nullptr) ? m_current_info->shortname().c_str() : "???"; } int line() const { return XML_GetCurrentLineNumber(m_parser); } int column() const { return XML_GetCurrentColumnNumber(m_parser); } const char *parser_error() const { return XML_ErrorString(XML_GetErrorCode(m_parser)); } @@ -55,7 +55,7 @@ private: void unknown_attribute(const char *attrname) { parse_error("Unknown attribute: %s", attrname); } // internal helpers - void parse_attributes(const char **attributes, int numattrs, const char *attrlist[], const char *outlist[]); + std::vector parse_attributes(const char **attributes, int numattrs, const char *attrlist[]); void add_rom_entry(const char *name, const char *hashdata, UINT32 offset, UINT32 length, UINT32 flags); // expat callbacks @@ -122,8 +122,8 @@ const char *software_part::feature(const char *feature_name) const // scan the feature list for an entry matching feature_name and return the value for (const feature_list_item &feature : m_featurelist) - if (strcmp(feature.name(), feature_name) == 0) - return feature.value(); + if (strcmp(feature.name().c_str(), feature_name) == 0) + return feature.value().c_str(); return nullptr; } @@ -241,10 +241,7 @@ software_info::software_info(software_list_device &list, const std::string &name m_list(list), m_supported(SOFTWARE_SUPPORTED_YES), m_shortname(name), - m_longname(nullptr), - m_parentname(parent), - m_year(nullptr), - m_publisher(nullptr) + m_parentname(parent) { // handle the supported flag if provided if (supported != nullptr) @@ -272,7 +269,7 @@ const software_part *software_info::find_part(const char *partname, const char * // look for the part by name and match against the interface if provided for (const software_part &part : m_partdata) - if (partname != nullptr && strcmp(partname, part.name()) == 0) + if (partname != nullptr && strcmp(partname, part.name().c_str()) == 0) { if (interface == nullptr || part.matches_interface(interface)) return ∂ @@ -318,7 +315,7 @@ software_list_device::software_list_device(const machine_config &mconfig, const m_filter(nullptr), m_parsed(false), m_file(mconfig.options().hash_path(), OPEN_FLAG_READ), - m_description(nullptr) + m_description("") { } @@ -383,8 +380,8 @@ void software_list_device::find_approx_matches(const char *name, int matches, co if ((interface == nullptr || part->matches_interface(interface)) && part->is_compatible(*this) == SOFTWARE_IS_COMPATIBLE) { // pick the best match between driver name and description - int longpenalty = driver_list::penalty_compare(name, swinfo.longname()); - int shortpenalty = driver_list::penalty_compare(name, swinfo.shortname()); + int longpenalty = driver_list::penalty_compare(name, swinfo.longname().c_str()); + int shortpenalty = driver_list::penalty_compare(name, swinfo.shortname().c_str()); int curpenalty = MIN(longpenalty, shortpenalty); // insert into the sorted table of matches @@ -416,7 +413,7 @@ void software_list_device::release() { osd_printf_verbose("Resetting %s\n", m_file.filename()); m_parsed = false; - m_description = nullptr; + m_description.clear(); m_errors.clear(); m_infolist.reset(); } @@ -470,7 +467,7 @@ void software_list_device::display_matches(const machine_config &config, const c // print them out for (auto & matche : matches) if (matche != nullptr) - osd_printf_error("%-18s%s\n", matche->shortname(), matche->longname()); + osd_printf_error("%-18s%s\n", matche->shortname().c_str(), matche->longname().c_str()); osd_printf_error("\n"); } @@ -494,7 +491,7 @@ const software_info *software_list_device::find(const char *look_for, const soft // find a match (will cause a parse if needed when calling get_info) for (prev = (prev != nullptr) ? prev->next() : get_info().first(); prev != nullptr; prev = prev->next()) - if ((iswild && core_strwildcmp(look_for, prev->shortname()) == 0) || core_stricmp(look_for, prev->shortname()) == 0) + if ((iswild && core_strwildcmp(look_for, prev->shortname().c_str()) == 0) || core_stricmp(look_for, prev->shortname().c_str()) == 0) break; return prev; @@ -576,30 +573,30 @@ void software_list_device::internal_validity_check(validity_checker &valid) // Now check if the xml data is valid: // Did we lost any description? - if (swinfo.longname() == nullptr) + if (swinfo.longname().empty()) { - osd_printf_error("%s: %s has no description\n", filename(), swinfo.shortname()); + osd_printf_error("%s: %s has no description\n", filename(), swinfo.shortname().c_str()); break; } // Did we lost any year? - if (swinfo.year() == nullptr) + if (swinfo.year().empty()) { - osd_printf_error("%s: %s has no year\n", filename(), swinfo.shortname()); + osd_printf_error("%s: %s has no year\n", filename(), swinfo.shortname().c_str()); break; } // Did we lost any publisher? - if (swinfo.publisher() == nullptr) + if (swinfo.publisher().empty()) { - osd_printf_error("%s: %s has no publisher\n", filename(), swinfo.shortname()); + osd_printf_error("%s: %s has no publisher\n", filename(), swinfo.shortname().c_str()); break; } // Did we lost the software parts? if (swinfo.parts().empty()) { - osd_printf_error("%s: %s has no part\n", filename(), swinfo.shortname()); + osd_printf_error("%s: %s has no part\n", filename(), swinfo.shortname().c_str()); break; } @@ -609,57 +606,57 @@ void software_list_device::internal_validity_check(validity_checker &valid) if (!names.insert(std::make_pair(swinfo.shortname(), &swinfo)).second) { software_info *match = names.find(swinfo.shortname())->second; - osd_printf_error("%s: %s is a duplicate name (%s)\n", filename(), swinfo.shortname(), match->shortname()); + osd_printf_error("%s: %s is a duplicate name (%s)\n", filename(), swinfo.shortname().c_str(), match->shortname().c_str()); } // check for duplicate descriptions std::string longname = std::string(swinfo.longname()); 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()); + osd_printf_error("%s: %s is a duplicate description (%s)\n", filename(), swinfo.longname().c_str(), swinfo.shortname().c_str()); bool is_clone = false; - if (swinfo.parentname() != nullptr) + if (swinfo.parentname().empty()) { is_clone = true; - if (strcmp(swinfo.parentname(), swinfo.shortname()) == 0) + if (swinfo.parentname() == swinfo.shortname()) { - osd_printf_error("%s: %s is set as a clone of itself\n", filename(), swinfo.shortname()); + osd_printf_error("%s: %s is set as a clone of itself\n", filename(), swinfo.shortname().c_str()); break; } // make sure the parent exists - const software_info *swinfo2 = find(swinfo.parentname()); + const software_info *swinfo2 = find(swinfo.parentname().c_str()); if (swinfo2 == nullptr) - osd_printf_error("%s: parent '%s' software for '%s' not found\n", filename(), swinfo.parentname(), swinfo.shortname()); - else if (swinfo2->parentname() != nullptr) - osd_printf_error("%s: %s is a clone of a clone\n", filename(), swinfo.shortname()); + osd_printf_error("%s: parent '%s' software for '%s' not found\n", filename(), swinfo.parentname().c_str(), swinfo.shortname().c_str()); + else if (swinfo2->parentname().empty()) + osd_printf_error("%s: %s is a clone of a clone\n", filename(), swinfo.shortname().c_str()); } // make sure the driver name is 8 chars or less - if ((is_clone && strlen(swinfo.shortname()) > NAME_LEN_CLONE) || (!is_clone && strlen(swinfo.shortname()) > NAME_LEN_PARENT)) - osd_printf_error("%s: %s %s driver name must be %d characters or less\n", filename(), swinfo.shortname(), + if ((is_clone && swinfo.shortname().length() > NAME_LEN_CLONE) || (!is_clone && swinfo.shortname().length() > NAME_LEN_PARENT)) + osd_printf_error("%s: %s %s driver name must be %d characters or less\n", filename(), swinfo.shortname().c_str(), is_clone ? "clone" : "parent", is_clone ? NAME_LEN_CLONE : NAME_LEN_PARENT); // make sure the year is only digits, '?' or '+' - for (const char *s = swinfo.year(); *s != 0; s++) + for (const char *s = swinfo.year().c_str(); *s != 0; s++) if (!isdigit((UINT8)*s) && *s != '?' && *s != '+') { - osd_printf_error("%s: %s has an invalid year '%s'\n", filename(), swinfo.shortname(), swinfo.year()); + osd_printf_error("%s: %s has an invalid year '%s'\n", filename(), swinfo.shortname().c_str(), swinfo.year().c_str()); break; } softlist_map part_names; for (software_part &part : swinfo.parts()) { - if (part.interface() == nullptr) - osd_printf_error("%s: %s has a part (%s) without interface\n", filename(), swinfo.shortname(), part.name()); + if (part.interface().empty()) + osd_printf_error("%s: %s has a part (%s) without interface\n", filename(), swinfo.shortname().c_str(), part.name().c_str()); if (part.romdata() == nullptr) - osd_printf_error("%s: %s has a part (%s) with no data\n", filename(), swinfo.shortname(), part.name()); + osd_printf_error("%s: %s has a part (%s) with no data\n", filename(), swinfo.shortname().c_str(), part.name().c_str()); 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()); + osd_printf_error("%s: %s has a part (%s) whose name is duplicate\n", filename(), swinfo.shortname().c_str(), part.name().c_str()); for (const rom_entry *data = part.romdata(); data->_name != nullptr; data++) if (data->_hashdata != nullptr) @@ -667,7 +664,7 @@ void software_list_device::internal_validity_check(validity_checker &valid) // make sure the hash is valid hash_collection hashes; if (!hashes.from_internal_string(data->_hashdata)) - osd_printf_error("%s: %s has rom '%s' with an invalid hash string '%s'\n", filename(), swinfo.shortname(), data->_name, data->_hashdata); + osd_printf_error("%s: %s has rom '%s' with an invalid hash string '%s'\n", filename(), swinfo.shortname().c_str(), data->_name, data->_hashdata); } } } @@ -750,8 +747,10 @@ inline void softlist_parser::parse_error(Format &&fmt, Params &&... args) // attributes into a list of strings //------------------------------------------------- -void softlist_parser::parse_attributes(const char **attributes, int numattrs, const char *attrlist[], const char *outlist[]) +std::vector softlist_parser::parse_attributes(const char **attributes, int numattrs, const char *attrlist[]) { + std::vector outlist(numattrs); + // iterate over attribute/value pairs for( ; attributes[0]; attributes += 2) { @@ -770,6 +769,8 @@ void softlist_parser::parse_attributes(const char **attributes, int numattrs, co if (index == numattrs) unknown_attribute(attributes[0]); } + + return outlist; } @@ -793,16 +794,10 @@ void softlist_parser::add_rom_entry(const char *name, const char *hashdata, UINT if (elem._name != nullptr && strcmp(elem._name, name) == 0) parse_error("Duplicated dataarea %s in software %s", name, infoname()); - // get our own copy of these strings (ideally rom_entry would use std::string) - m_current_part->m_romdata_strings.emplace_back(name); - name = m_current_part->m_romdata_strings.back().c_str(); - m_current_part->m_romdata_strings.emplace_back(hashdata); - hashdata = m_current_part->m_romdata_strings.back().c_str(); - // create the new entry and append it rom_entry entry; - entry._name = name; - entry._hashdata = hashdata; + entry._name = m_list.add_string(name); + entry._hashdata = m_list.add_string(hashdata); entry._offset = offset; entry._length = length; entry._flags = flags; @@ -918,10 +913,9 @@ void softlist_parser::parse_root_start(const char *tagname, const char **attribu if (strcmp(tagname, "softwarelist") == 0) { static const char *attrnames[] = { "name", "description" }; - const char *attrvalues[ARRAY_LENGTH(attrnames)] = { nullptr }; - parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); - if (attrvalues[1] != nullptr) + if (!attrvalues[1].empty()) m_list.m_description = attrvalues[1]; } else @@ -940,11 +934,10 @@ void softlist_parser::parse_main_start(const char *tagname, const char **attribu if (strcmp(tagname, "software") == 0) { static const char *attrnames[] = { "name", "cloneof", "supported" }; - const char *attrvalues[ARRAY_LENGTH(attrnames)] = { nullptr }; - parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); - if (attrvalues[0] != nullptr) - m_current_info = &m_list.m_infolist.append(*global_alloc(software_info(m_list, attrvalues[0], attrvalues[1], attrvalues[2]))); + if (!attrvalues[0].empty()) + m_current_info = &m_list.m_infolist.append(*global_alloc(software_info(m_list, attrvalues[0], attrvalues[1], attrvalues[2].c_str()))); else parse_error("No name defined for item"); } @@ -983,10 +976,9 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu else if (strcmp(tagname, "info") == 0) { static const char *attrnames[] = { "name", "value" }; - const char *attrvalues[ARRAY_LENGTH(attrnames)] = { nullptr }; - parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); - if (attrvalues[0] != nullptr && attrvalues[1] != nullptr) + if (!attrvalues[0].empty() && !attrvalues[1].empty()) m_current_info->m_other_info.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1]))); else parse_error("Incomplete other_info definition"); @@ -996,10 +988,9 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu else if (strcmp(tagname, "sharedfeat") == 0) { static const char *attrnames[] = { "name", "value" }; - const char *attrvalues[ARRAY_LENGTH(attrnames)] = { nullptr }; - parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); - if (attrvalues[0] != nullptr && attrvalues[1] != nullptr) + if (!attrvalues[0].empty() && !attrvalues[1].empty()) m_current_info->m_shared_info.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1]))); else parse_error("Incomplete sharedfeat definition"); @@ -1009,10 +1000,9 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu else if (strcmp(tagname, "part" ) == 0) { static const char *attrnames[] = { "name", "interface" }; - const char *attrvalues[ARRAY_LENGTH(attrnames)] = { nullptr }; - parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); - if (attrvalues[0] != nullptr && attrvalues[1] != nullptr && strcmp(attrvalues[0], "") != 0 && strcmp(attrvalues[1], "") != 0) + if (!attrvalues[0].empty() && !attrvalues[1].empty()) m_current_part = &m_current_info->m_partdata.append(*global_alloc(software_part(*m_current_info, attrvalues[0], attrvalues[1]))); else parse_error("Incomplete part definition"); @@ -1040,14 +1030,13 @@ void softlist_parser::parse_part_start(const char *tagname, const char **attribu if (strcmp(tagname, "dataarea") == 0) { static const char *attrnames[] = { "name", "size", "width", "endianness" }; - const char *attrvalues[ARRAY_LENGTH(attrnames)] = { nullptr }; - parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); - if (attrvalues[0] != nullptr && attrvalues[1] != nullptr && strcmp(attrvalues[0], "") != 0 && strcmp(attrvalues[1], "") != 0) + if (!attrvalues[0].empty() && !attrvalues[1].empty()) { // handle region attributes - const char *width = attrvalues[2]; - const char *endianness = attrvalues[3]; + const char *width = attrvalues[2].c_str(); + const char *endianness = attrvalues[3].c_str(); UINT32 regionflags = ROMENTRYTYPE_REGION; if (width != nullptr) @@ -1073,7 +1062,7 @@ void softlist_parser::parse_part_start(const char *tagname, const char **attribu parse_error("Invalid dataarea endianness"); } - add_rom_entry(attrvalues[0], nullptr, 0, strtol(attrvalues[1], nullptr, 0), regionflags); + add_rom_entry(attrvalues[0].c_str(), nullptr, 0, strtol(attrvalues[1].c_str(), nullptr, 0), regionflags); } else parse_error("Incomplete dataarea definition"); @@ -1083,11 +1072,10 @@ void softlist_parser::parse_part_start(const char *tagname, const char **attribu else if (strcmp(tagname, "diskarea") == 0) { static const char *attrnames[] = { "name" }; - const char *attrvalues[ARRAY_LENGTH(attrnames)] = { nullptr }; - parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); - if (attrvalues[0] != nullptr) - add_rom_entry(attrvalues[0], nullptr, 0, 1, ROMENTRYTYPE_REGION | ROMREGION_DATATYPEDISK); + if (!attrvalues[0].empty()) + add_rom_entry(attrvalues[0].c_str(), nullptr, 0, 1, ROMENTRYTYPE_REGION | ROMREGION_DATATYPEDISK); else parse_error("Incomplete diskarea definition"); } @@ -1096,10 +1084,9 @@ void softlist_parser::parse_part_start(const char *tagname, const char **attribu else if (strcmp(tagname, "feature") == 0) { static const char *attrnames[] = { "name", "value" }; - const char *attrvalues[ARRAY_LENGTH(attrnames)] = { nullptr }; - parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); - if (attrvalues[0] != nullptr) + if (!attrvalues[0].empty()) m_current_part->m_featurelist.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1]))); else parse_error("Incomplete feature definition"); @@ -1131,17 +1118,16 @@ void softlist_parser::parse_data_start(const char *tagname, const char **attribu if (strcmp(tagname, "rom") == 0) { static const char *attrnames[] = { "name", "size", "crc", "sha1", "offset", "value", "status", "loadflag" }; - const char *attrvalues[ARRAY_LENGTH(attrnames)] = { nullptr }; - parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); - const char *name = attrvalues[0]; - const char *sizestr = attrvalues[1]; - const char *crc = attrvalues[2]; - const char *sha1 = attrvalues[3]; - const char *offsetstr = attrvalues[4]; - const char *value = attrvalues[5]; - const char *status = attrvalues[6]; - const char *loadflag = attrvalues[7]; + const char *name = attrvalues[0].c_str(); + const char *sizestr = attrvalues[1].c_str(); + const char *crc = attrvalues[2].c_str(); + const char *sha1 = attrvalues[3].c_str(); + const char *offsetstr = attrvalues[4].c_str(); + const char *value = attrvalues[5].c_str(); + const char *status = attrvalues[6].c_str(); + const char *loadflag = attrvalues[7].c_str(); if (sizestr != nullptr && offsetstr != nullptr) { UINT32 length = strtol(sizestr, nullptr, 0); @@ -1154,7 +1140,10 @@ void softlist_parser::parse_data_start(const char *tagname, const char **attribu else if (loadflag != nullptr && strcmp(loadflag, "continue") == 0) add_rom_entry(nullptr, nullptr, offset, length, ROMENTRYTYPE_CONTINUE | ROM_INHERITFLAGS); else if (loadflag != nullptr && strcmp(loadflag, "fill") == 0) - add_rom_entry(nullptr, (const char *)(FPTR)(strtol(value, nullptr, 0) & 0xff), offset, length, ROMENTRYTYPE_FILL); + { + auto fill_string = string_format("%02X", strtol(value, nullptr, 0) & 0xff); + add_rom_entry(nullptr, fill_string.c_str(), offset, length, ROMENTRYTYPE_FILL); + } else if (name != nullptr) { bool baddump = (status != nullptr && strcmp(status, "baddump") == 0); @@ -1206,13 +1195,12 @@ void softlist_parser::parse_data_start(const char *tagname, const char **attribu else if (strcmp(tagname, "disk") == 0) { static const char *attrnames[] = { "name", "sha1", "status", "writeable" }; - const char *attrvalues[ARRAY_LENGTH(attrnames)] = { nullptr }; - parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues); + auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); - const char *name = attrvalues[0]; - const char *sha1 = attrvalues[1]; - const char *status = attrvalues[2]; - const char *writeablestr = attrvalues[3]; + const char *name = attrvalues[0].c_str(); + const char *sha1 = attrvalues[1].c_str(); + const char *status = attrvalues[2].c_str(); + const char *writeablestr = attrvalues[3].c_str(); if (name != nullptr && sha1 != nullptr) { bool baddump = (status != nullptr && strcmp(status, "baddump") == 0); diff --git a/src/emu/softlist.h b/src/emu/softlist.h index a06c69b2b62..698dcff74d4 100644 --- a/src/emu/softlist.h +++ b/src/emu/softlist.h @@ -89,8 +89,8 @@ public: // getters feature_list_item *next() const { return m_next; } - const char *name() const { return m_name.c_str(); } - const char *value() const { return m_value.c_str(); } + const std::string &name() const { return m_name; } + const std::string &value() const { return m_value; } private: // internal state @@ -115,8 +115,8 @@ public: // getters software_part *next() const { return m_next; } software_info &info() const { return m_info; } - const char *name() const { return m_name.c_str(); } - const char *interface() const { return m_interface.c_str(); } + const std::string &name() const { return m_name; } + const std::string &interface() const { return m_interface; } const simple_list &featurelist() const { return m_featurelist; } const rom_entry *romdata(unsigned int index = 0) const { return (index < m_romdata.size()) ? &m_romdata[index] : nullptr; } @@ -153,11 +153,11 @@ public: // getters software_info *next() const { return m_next; } software_list_device &list() const { return m_list; } - const char *shortname() const { return m_shortname.c_str(); } - const char *longname() const { return m_longname.c_str(); } - const char *parentname() const { return m_parentname.c_str(); } - const char *year() const { return m_year.c_str(); } - const char *publisher() const { return m_publisher.c_str(); } + const std::string &shortname() const { return m_shortname; } + const std::string &longname() const { return m_longname; } + const std::string &parentname() const { return m_parentname; } + const std::string &year() const { return m_year; } + const std::string &publisher() const { return m_publisher; } const simple_list &other_info() const { return m_other_info; } const simple_list &shared_info() const { return m_shared_info; } UINT32 supported() const { return m_supported; } @@ -217,6 +217,9 @@ public: void find_approx_matches(const char *name, int matches, const software_info **list, const char *interface); void release(); + // string pool helpers + const char *add_string(const char *string) { return m_stringpool.add(string); } + // static helpers static software_list_device *find_by_name(const machine_config &mconfig, const char *name); static void display_matches(const machine_config &config, const char *interface, const char *name); @@ -241,6 +244,7 @@ protected: std::string m_description; std::string m_errors; simple_list m_infolist; + const_string_pool m_stringpool; }; diff --git a/src/frontend/mame/audit.cpp b/src/frontend/mame/audit.cpp index fb1199812e7..b551ed4d666 100644 --- a/src/frontend/mame/audit.cpp +++ b/src/frontend/mame/audit.cpp @@ -159,7 +159,7 @@ media_auditor::summary media_auditor::audit_software(const char *list_name, cons std::string combinedpath(util::string_format("%s;%s%s%s", swinfo->shortname(), list_name, PATH_SEPARATOR, swinfo->shortname())); std::string locationtag(util::string_format("%s%%%s%%", list_name, swinfo->shortname())); - if (swinfo->parentname() != nullptr) + if (!swinfo->parentname().empty()) { locationtag.append(swinfo->parentname()); combinedpath.append(util::string_format(";%s;%s%s%s", swinfo->parentname(), list_name, PATH_SEPARATOR, swinfo->parentname())); diff --git a/src/frontend/mame/clifront.cpp b/src/frontend/mame/clifront.cpp index 059748b2cfc..06834d3c2c2 100644 --- a/src/frontend/mame/clifront.cpp +++ b/src/frontend/mame/clifront.cpp @@ -385,7 +385,7 @@ int media_identifier::find_by_hash(const hash_collection &hashes, int length) // output information about the match if (found) osd_printf_info(" "); - osd_printf_info("= %s%-20s %s:%s %s\n", baddump ? "(BAD) " : "", ROM_GETNAME(rom), swlistdev.list_name(), swinfo.shortname(), swinfo.longname()); + osd_printf_info("= %s%-20s %s:%s %s\n", baddump ? "(BAD) " : "", ROM_GETNAME(rom), swlistdev.list_name(), swinfo.shortname().c_str(), swinfo.longname().c_str()); found++; } } @@ -1390,31 +1390,31 @@ void cli_frontend::output_single_softlist(FILE *out, software_list_device &swlis fprintf(out, "\t\n", swlistdev.list_name(), xml_normalize_string(swlistdev.description())); for (software_info &swinfo : swlistdev.get_info()) { - fprintf(out, "\t\t\n" ); - fprintf(out, "\t\t\t%s\n", xml_normalize_string(swinfo.longname())); - fprintf(out, "\t\t\t%s\n", xml_normalize_string(swinfo.year())); - fprintf(out, "\t\t\t%s\n", xml_normalize_string(swinfo.publisher())); + fprintf(out, "\t\t\t%s\n", xml_normalize_string(swinfo.longname().c_str())); + fprintf(out, "\t\t\t%s\n", xml_normalize_string(swinfo.year().c_str())); + fprintf(out, "\t\t\t%s\n", xml_normalize_string(swinfo.publisher().c_str())); for (feature_list_item &flist : swinfo.other_info()) - fprintf( out, "\t\t\t\n", flist.name(), xml_normalize_string( flist.value() ) ); + fprintf( out, "\t\t\t\n", flist.name().c_str(), xml_normalize_string( flist.value().c_str()) ); for (software_part &part : swinfo.parts()) { - fprintf(out, "\t\t\t\n"); for (feature_list_item &flist : part.featurelist()) - fprintf(out, "\t\t\t\t\n", flist.name(), xml_normalize_string(flist.value())); + fprintf(out, "\t\t\t\t\n", flist.name().c_str(), xml_normalize_string(flist.value().c_str())); /* TODO: display rom region information */ for (const rom_entry *region = part.romdata(); region; region = rom_next_region(region)) diff --git a/src/frontend/mame/ui/datmenu.cpp b/src/frontend/mame/ui/datmenu.cpp index c4d7b809266..427f3187661 100644 --- a/src/frontend/mame/ui/datmenu.cpp +++ b/src/frontend/mame/ui/datmenu.cpp @@ -40,9 +40,9 @@ menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container if (image.filename()) { m_list = strensure(image.software_list_name()); - m_short = strensure(image.software_entry()->shortname()); - m_long = strensure(image.software_entry()->longname()); - m_parent = strensure(image.software_entry()->parentname()); + m_short = image.software_entry()->shortname(); + m_long = image.software_entry()->longname(); + m_parent = image.software_entry()->parentname(); } } diff --git a/src/frontend/mame/ui/filemngr.cpp b/src/frontend/mame/ui/filemngr.cpp index 38e7faa0d78..87fa7ff0a60 100644 --- a/src/frontend/mame/ui/filemngr.cpp +++ b/src/frontend/mame/ui/filemngr.cpp @@ -81,7 +81,7 @@ void menu_file_manager::fill_image_line(device_image_interface *img, std::string if (img->part_entry() != nullptr) { const software_part *tmp = img->part_entry(); - if (tmp->name() != nullptr) + if (!tmp->name().empty()) { filename.append(" ("); filename.append(tmp->name()); diff --git a/src/frontend/mame/ui/imgcntrl.cpp b/src/frontend/mame/ui/imgcntrl.cpp index 227d520044d..806d6c682ec 100644 --- a/src/frontend/mame/ui/imgcntrl.cpp +++ b/src/frontend/mame/ui/imgcntrl.cpp @@ -192,7 +192,7 @@ void menu_control_device_image::handle() case START_OTHER_PART: m_submenu_result.swparts = menu_software_parts::result::INVALID; - menu::stack_push(ui(), container(), m_swi, m_swp->interface(), &m_swp, true, m_submenu_result.swparts); + menu::stack_push(ui(), container(), m_swi, m_swp->interface().c_str(), &m_swp, true, m_submenu_result.swparts); m_state = SELECT_OTHER_PART; break; diff --git a/src/frontend/mame/ui/inifile.cpp b/src/frontend/mame/ui/inifile.cpp index f0f6adbfc38..531604465b4 100644 --- a/src/frontend/mame/ui/inifile.cpp +++ b/src/frontend/mame/ui/inifile.cpp @@ -194,20 +194,20 @@ void favorite_manager::add_favorite_game() auto swinfo = image.software_entry(); auto part = image.part_entry(); ui_software_info tmpmatches; - tmpmatches.shortname = strensure(swinfo->shortname()); + tmpmatches.shortname = swinfo->shortname(); tmpmatches.longname = strensure(image.longname()); - tmpmatches.parentname = strensure(swinfo->parentname()); + tmpmatches.parentname = swinfo->parentname(); tmpmatches.year = strensure(image.year()); tmpmatches.publisher = strensure(image.manufacturer()); tmpmatches.supported = image.supported(); - tmpmatches.part = strensure(part->name()); + tmpmatches.part = part->name(); tmpmatches.driver = &machine().system(); tmpmatches.listname = strensure(image.software_list_name()); - tmpmatches.interface = strensure(part->interface()); + tmpmatches.interface = part->interface(); tmpmatches.instance = strensure(image.instance_name()); tmpmatches.startempty = 0; tmpmatches.parentlongname.clear(); - if (swinfo->parentname()) + if (!swinfo->parentname().empty()) { auto swlist = software_list_device::find_by_name(machine().config(), image.software_list_name()); for (software_info &c_swinfo : swlist->get_info()) @@ -223,7 +223,7 @@ void favorite_manager::add_favorite_game() tmpmatches.usage.clear(); for (feature_list_item &flist : swinfo->other_info()) - if (!strcmp(flist.name(), "usage")) + if (!strcmp(flist.name().c_str(), "usage")) tmpmatches.usage = flist.value(); tmpmatches.devicetype = strensure(image.image_type_name()); diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp index 1b6468579ab..11a1d1551b5 100644 --- a/src/frontend/mame/ui/selsoft.cpp +++ b/src/frontend/mame/ui/selsoft.cpp @@ -552,23 +552,23 @@ void menu_select_software::build_software_list() if (instance_name == nullptr || type_name == nullptr) continue; - tmpmatches.shortname = strensure(swinfo.shortname()); - tmpmatches.longname = strensure(swinfo.longname()); - tmpmatches.parentname = strensure(swinfo.parentname()); - tmpmatches.year = strensure(swinfo.year()); - tmpmatches.publisher = strensure(swinfo.publisher()); + tmpmatches.shortname = swinfo.shortname(); + tmpmatches.longname = swinfo.longname(); + tmpmatches.parentname = swinfo.parentname(); + tmpmatches.year = swinfo.year(); + tmpmatches.publisher = swinfo.publisher(); tmpmatches.supported = swinfo.supported(); - tmpmatches.part = strensure(part->name()); + tmpmatches.part = part->name(); tmpmatches.driver = m_driver; tmpmatches.listname = strensure(swlist.list_name()); - tmpmatches.interface = strensure(part->interface()); + tmpmatches.interface = part->interface(); tmpmatches.startempty = 0; tmpmatches.parentlongname.clear(); tmpmatches.usage.clear(); tmpmatches.available = false; for (feature_list_item &flist : swinfo.other_info()) - if (!strcmp(flist.name(), "usage")) + if (!strcmp(flist.name().c_str(), "usage")) tmpmatches.usage = flist.value(); m_swinfo.push_back(tmpmatches); From 40a9e787048385edd3ea5cf439dea914c0a96f3e Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Wed, 20 Jul 2016 19:16:30 -0400 Subject: [PATCH 3/3] Vas Crabb feedback: Better adoption of move constructors, other cleanups --- src/emu/softlist.cpp | 89 +++++++++++++++++++++----------------------- src/emu/softlist.h | 15 +++++--- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/emu/softlist.cpp b/src/emu/softlist.cpp index 8e46d654d0e..57977ed9a51 100644 --- a/src/emu/softlist.cpp +++ b/src/emu/softlist.cpp @@ -102,11 +102,11 @@ const device_type SOFTWARE_LIST = &device_creator; // software_part - constructor //------------------------------------------------- -software_part::software_part(software_info &info, const std::string &name, const std::string &interface) +software_part::software_part(software_info &info, std::string &&name, std::string &&interface) : m_next(nullptr), m_info(info), - m_name(name), - m_interface(interface) + m_name(std::move(name)), + m_interface(std::move(interface)) { } @@ -116,13 +116,11 @@ software_part::software_part(software_info &info, const std::string &name, const // feature, if specified //------------------------------------------------- -const char *software_part::feature(const char *feature_name) const +const char *software_part::feature(const std::string &feature_name) const { - assert(feature_name != nullptr); - // scan the feature list for an entry matching feature_name and return the value for (const feature_list_item &feature : m_featurelist) - if (strcmp(feature.name().c_str(), feature_name) == 0) + if (feature.name() == feature_name) return feature.value().c_str(); return nullptr; @@ -236,12 +234,12 @@ device_image_interface *software_part::find_mountable_image(const machine_config // software_info - constructor //------------------------------------------------- -software_info::software_info(software_list_device &list, const std::string &name, const std::string &parent, const char *supported) +software_info::software_info(software_list_device &list, std::string &&name, std::string &&parent, const char *supported) : m_next(nullptr), m_list(list), m_supported(SOFTWARE_SUPPORTED_YES), - m_shortname(name), - m_parentname(parent) + m_shortname(std::move(name)), + m_parentname(std::move(parent)) { // handle the supported flag if provided if (supported != nullptr) @@ -937,7 +935,7 @@ void softlist_parser::parse_main_start(const char *tagname, const char **attribu auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); if (!attrvalues[0].empty()) - m_current_info = &m_list.m_infolist.append(*global_alloc(software_info(m_list, attrvalues[0], attrvalues[1], attrvalues[2].c_str()))); + m_current_info = &m_list.m_infolist.append(*global_alloc(software_info(m_list, std::move(attrvalues[0]), std::move(attrvalues[1]), attrvalues[2].c_str()))); else parse_error("No name defined for item"); } @@ -979,7 +977,7 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); if (!attrvalues[0].empty() && !attrvalues[1].empty()) - m_current_info->m_other_info.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1]))); + m_current_info->m_other_info.append(*global_alloc(feature_list_item(std::move(attrvalues[0]), std::move(attrvalues[1])))); else parse_error("Incomplete other_info definition"); } @@ -991,7 +989,7 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); if (!attrvalues[0].empty() && !attrvalues[1].empty()) - m_current_info->m_shared_info.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1]))); + m_current_info->m_shared_info.append(*global_alloc(feature_list_item(std::move(attrvalues[0]), std::move(attrvalues[1])))); else parse_error("Incomplete sharedfeat definition"); } @@ -1003,7 +1001,7 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); if (!attrvalues[0].empty() && !attrvalues[1].empty()) - m_current_part = &m_current_info->m_partdata.append(*global_alloc(software_part(*m_current_info, attrvalues[0], attrvalues[1]))); + m_current_part = &m_current_info->m_partdata.append(*global_alloc(software_part(*m_current_info, std::move(attrvalues[0]), std::move(attrvalues[1])))); else parse_error("Incomplete part definition"); } @@ -1087,7 +1085,7 @@ void softlist_parser::parse_part_start(const char *tagname, const char **attribu auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); if (!attrvalues[0].empty()) - m_current_part->m_featurelist.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1]))); + m_current_part->m_featurelist.append(*global_alloc(feature_list_item(std::move(attrvalues[0]), std::move(attrvalues[1])))); else parse_error("Incomplete feature definition"); } @@ -1120,45 +1118,42 @@ void softlist_parser::parse_data_start(const char *tagname, const char **attribu static const char *attrnames[] = { "name", "size", "crc", "sha1", "offset", "value", "status", "loadflag" }; auto attrvalues = parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames); - const char *name = attrvalues[0].c_str(); - const char *sizestr = attrvalues[1].c_str(); - const char *crc = attrvalues[2].c_str(); - const char *sha1 = attrvalues[3].c_str(); - const char *offsetstr = attrvalues[4].c_str(); - const char *value = attrvalues[5].c_str(); - const char *status = attrvalues[6].c_str(); - const char *loadflag = attrvalues[7].c_str(); - if (sizestr != nullptr && offsetstr != nullptr) + const std::string &name = attrvalues[0]; + const std::string &sizestr = attrvalues[1]; + const std::string &crc = attrvalues[2]; + const std::string &sha1 = attrvalues[3]; + const std::string &offsetstr = attrvalues[4]; + const std::string &value = attrvalues[5]; + const std::string &status = attrvalues[6]; + const std::string &loadflag = attrvalues[7]; + if (!sizestr.empty() && !offsetstr.empty()) { - UINT32 length = strtol(sizestr, nullptr, 0); - UINT32 offset = strtol(offsetstr, nullptr, 0); + UINT32 length = strtol(sizestr.c_str(), nullptr, 0); + UINT32 offset = strtol(offsetstr.c_str(), nullptr, 0); - if (loadflag != nullptr && strcmp(loadflag, "reload") == 0) + if (loadflag == "reload") add_rom_entry(nullptr, nullptr, offset, length, ROMENTRYTYPE_RELOAD | ROM_INHERITFLAGS); - else if (loadflag != nullptr && strcmp(loadflag, "reload_plain") == 0) + else if (loadflag == "reload_plain") add_rom_entry(nullptr, nullptr, offset, length, ROMENTRYTYPE_RELOAD); - else if (loadflag != nullptr && strcmp(loadflag, "continue") == 0) + else if (loadflag == "continue") add_rom_entry(nullptr, nullptr, offset, length, ROMENTRYTYPE_CONTINUE | ROM_INHERITFLAGS); - else if (loadflag != nullptr && strcmp(loadflag, "fill") == 0) + else if (loadflag == "fill") + add_rom_entry(nullptr, (const char *)(FPTR)(strtol(value.c_str(), nullptr, 0) & 0xff), offset, length, ROMENTRYTYPE_FILL); + else if (!name.empty()) { - auto fill_string = string_format("%02X", strtol(value, nullptr, 0) & 0xff); - add_rom_entry(nullptr, fill_string.c_str(), offset, length, ROMENTRYTYPE_FILL); - } - else if (name != nullptr) - { - bool baddump = (status != nullptr && strcmp(status, "baddump") == 0); - bool nodump = (status != nullptr && strcmp(status, "nodump") == 0); + bool baddump = (status == "baddump"); + bool nodump = (status == "nodump"); std::string hashdata; if (nodump) { hashdata = string_format("%s", NO_DUMP); - if (crc != nullptr && sha1 != nullptr) + if (!crc.empty() && !sha1.empty()) parse_error("No need for hash definition"); } else { - if (crc != nullptr && sha1 != nullptr) + if (!crc.empty() && !sha1.empty()) hashdata = string_format("%c%s%c%s%s", hash_collection::HASH_CRC, crc, hash_collection::HASH_SHA1, sha1, (baddump ? BAD_DUMP : "")); else parse_error("Incomplete rom hash definition"); @@ -1166,25 +1161,25 @@ void softlist_parser::parse_data_start(const char *tagname, const char **attribu // Handle loadflag attribute int romflags = 0; - if (loadflag != nullptr && strcmp(loadflag, "load16_word_swap") == 0) + if (loadflag == "load16_word_swap") romflags = ROM_GROUPWORD | ROM_REVERSE; - else if (loadflag != nullptr && strcmp(loadflag, "load16_byte") == 0) + else if (loadflag == "load16_byte") romflags = ROM_SKIP(1); - else if (loadflag != nullptr && strcmp(loadflag, "load32_word_swap") == 0) + else if (loadflag == "load32_word_swap") romflags = ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2); - else if (loadflag != nullptr && strcmp(loadflag, "load32_word") == 0) + else if (loadflag == "load32_word") romflags = ROM_GROUPWORD | ROM_SKIP(2); - else if (loadflag != nullptr && strcmp(loadflag, "load32_byte") == 0) + else if (loadflag == "load32_byte") romflags = ROM_SKIP(3); - add_rom_entry(name, hashdata.c_str(), offset, length, ROMENTRYTYPE_ROM | romflags); + add_rom_entry(name.c_str(), hashdata.c_str(), offset, length, ROMENTRYTYPE_ROM | romflags); } else parse_error("Rom name missing"); } - else if (sizestr != nullptr && loadflag != nullptr && strcmp(loadflag, "ignore") == 0) + else if (!sizestr.empty() && !loadflag.empty() && loadflag == "ignore") { - UINT32 length = strtol(sizestr, nullptr, 0); + UINT32 length = strtol(sizestr.c_str(), nullptr, 0); add_rom_entry(nullptr, nullptr, 0, length, ROMENTRYTYPE_IGNORE | ROM_INHERITFLAGS); } else diff --git a/src/emu/softlist.h b/src/emu/softlist.h index 698dcff74d4..c0356e5ce4d 100644 --- a/src/emu/softlist.h +++ b/src/emu/softlist.h @@ -82,10 +82,15 @@ class feature_list_item public: // construction/destruction + feature_list_item(std::string &&name, std::string &&value) + : m_next(nullptr), + m_name(std::move(name)), + m_value(std::move(value)) { } + feature_list_item(const std::string &name, const std::string &value) : m_next(nullptr), - m_name(name), - m_value(value) { } + m_name(name), + m_value(value) { } // getters feature_list_item *next() const { return m_next; } @@ -110,7 +115,7 @@ class software_part public: // construction/destruction - software_part(software_info &info, const std::string &name, const std::string &interface); + software_part(software_info &info, std::string &&name, std::string &&interface); // getters software_part *next() const { return m_next; } @@ -123,7 +128,7 @@ public: // helpers software_compatibility is_compatible(const software_list_device &swlist) const; bool matches_interface(const char *interface) const; - const char *feature(const char *feature_name) const; + const char *feature(const std::string &feature_name) const; device_image_interface *find_mountable_image(const machine_config &mconfig) const; private: @@ -148,7 +153,7 @@ class software_info public: // construction/destruction - software_info(software_list_device &list, const std::string &name, const std::string &parent, const char *supported); + software_info(software_list_device &list, std::string &&name, std::string &&parent, const char *supported); // getters software_info *next() const { return m_next; }