From dd57d5c00eb9ae75e8c9cab3ccfeddfd917beab8 Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Thu, 30 Jun 2016 07:19:17 -0400 Subject: [PATCH 1/4] Changed filesel entrylist to be a vector --- src/frontend/mame/ui/filesel.cpp | 66 ++++++++------------------------ src/frontend/mame/ui/filesel.h | 8 ++-- 2 files changed, 20 insertions(+), 54 deletions(-) diff --git a/src/frontend/mame/ui/filesel.cpp b/src/frontend/mame/ui/filesel.cpp index 25f10f49179..cc4ef070020 100644 --- a/src/frontend/mame/ui/filesel.cpp +++ b/src/frontend/mame/ui/filesel.cpp @@ -293,7 +293,6 @@ menu_file_selector::menu_file_selector(mame_ui_manager &mui, render_container *c : menu(mui, container) , m_current_directory(current_directory) , m_current_file(current_file) - , m_entrylist(nullptr) { m_image = image; m_has_empty = has_empty; @@ -384,8 +383,8 @@ bool menu_file_selector::custom_mouse_down() int menu_file_selector::compare_entries(const file_selector_entry *e1, const file_selector_entry *e2) { int result; - const char *e1_basename = (e1->basename != nullptr) ? e1->basename : ""; - const char *e2_basename = (e2->basename != nullptr) ? e2->basename : ""; + const char *e1_basename = e1->basename.c_str(); + const char *e2_basename = e2->basename.c_str(); if (e1->type < e2->type) { @@ -423,25 +422,15 @@ int menu_file_selector::compare_entries(const file_selector_entry *e1, const fil menu_file_selector::file_selector_entry *menu_file_selector::append_entry( file_selector_entry_type entry_type, const char *entry_basename, const char *entry_fullpath) { - file_selector_entry *entry; - file_selector_entry **entryptr; - // allocate a new entry - entry = (file_selector_entry *) m_pool_alloc(sizeof(*entry)); - memset(entry, 0, sizeof(*entry)); - entry->type = entry_type; - entry->basename = (entry_basename != nullptr) ? pool_strdup(entry_basename) : entry_basename; - entry->fullpath = (entry_fullpath != nullptr) ? pool_strdup(entry_fullpath) : entry_fullpath; + file_selector_entry entry; + entry.type = entry_type; + entry.basename.assign(entry_basename ? entry_basename : ""); + entry.fullpath.assign(entry_fullpath ? entry_fullpath : ""); // find the end of the list - entryptr = &m_entrylist; - while ((*entryptr != nullptr) && (compare_entries(entry, *entryptr) >= 0)) - entryptr = &(*entryptr)->next; - - // insert the entry - entry->next = *entryptr; - *entryptr = entry; - return entry; + m_entrylist.push_back(entry); + return &m_entrylist[m_entrylist.size() - 1]; } @@ -546,7 +535,7 @@ void menu_file_selector::populate() err = util::zippath_opendir(path, &directory); // clear out the menu entries - m_entrylist = nullptr; + m_entrylist.clear(); if (m_has_empty) { @@ -598,8 +587,8 @@ void menu_file_selector::populate() } // append all of the menu entries - for (entry = m_entrylist; entry != nullptr; entry = entry->next) - append_entry_menu_item(entry); + for (auto &entry : m_entrylist) + append_entry_menu_item(&entry); // set the selection (if we have one) if (selected_entry != nullptr) @@ -620,7 +609,6 @@ void menu_file_selector::populate() void menu_file_selector::handle() { osd_file::error err; - const file_selector_entry *entry; const file_selector_entry *selected_entry = nullptr; int bestmatch = 0; @@ -631,7 +619,7 @@ void menu_file_selector::handle() // handle selections if (event->iptkey == IPT_UI_SELECT) { - entry = (const file_selector_entry *) event->itemref; + auto entry = (const file_selector_entry *) event->itemref; switch (entry->type) { case SELECTOR_ENTRY_TYPE_EMPTY: @@ -654,7 +642,7 @@ void menu_file_selector::handle() case SELECTOR_ENTRY_TYPE_DRIVE: case SELECTOR_ENTRY_TYPE_DIRECTORY: // drive/directory - first check the path - err = util::zippath_opendir(entry->fullpath, nullptr); + err = util::zippath_opendir(entry->fullpath.c_str(), nullptr); if (err != osd_file::error::NONE) { // this path is problematic; present the user with an error and bail @@ -709,41 +697,21 @@ void menu_file_selector::handle() const file_selector_entry *cur_selected = (const file_selector_entry *)get_selection(); // check for entries which matches our m_filename_buffer: - // from current entry to the end - for (entry = cur_selected; entry != nullptr; entry = entry->next) + for (auto &entry : m_entrylist) { - if (entry->basename != nullptr && m_filename_buffer[0] != '\0') + if (cur_selected != &entry) { int match = 0; for (int i = 0; i < ARRAY_LENGTH(m_filename_buffer); i++) { - if (core_strnicmp(entry->basename, m_filename_buffer, i) == 0) + if (core_strnicmp(entry.basename.c_str(), m_filename_buffer, i) == 0) match = i; } if (match > bestmatch) { bestmatch = match; - selected_entry = entry; - } - } - } - // and from the first entry to current one - for (entry = m_entrylist; entry != cur_selected; entry = entry->next) - { - if (entry->basename != nullptr && m_filename_buffer[0] != '\0') - { - int match = 0; - for (int i = 0; i < ARRAY_LENGTH(m_filename_buffer); i++) - { - if (core_strnicmp(entry->basename, m_filename_buffer, i) == 0) - match = i; - } - - if (match > bestmatch) - { - bestmatch = match; - selected_entry = entry; + selected_entry = &entry; } } } diff --git a/src/frontend/mame/ui/filesel.h b/src/frontend/mame/ui/filesel.h index a487db4e7b7..ff436a7682b 100644 --- a/src/frontend/mame/ui/filesel.h +++ b/src/frontend/mame/ui/filesel.h @@ -84,11 +84,9 @@ private: struct file_selector_entry { - file_selector_entry *next; - file_selector_entry_type type; - const char *basename; - const char *fullpath; + std::string basename; + std::string fullpath; }; // internal state @@ -99,7 +97,7 @@ private: bool m_has_softlist; bool m_has_create; int * m_result; - file_selector_entry * m_entrylist; + std::vector m_entrylist; std::string m_hover_directory; char m_filename_buffer[1024]; From 4e5a47dc8cb05837ad06a4f474a8c0a124b6b890 Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Thu, 30 Jun 2016 07:27:54 -0400 Subject: [PATCH 2/4] Adopted move constructors on strings a bit more in filesel --- src/frontend/mame/ui/filesel.cpp | 28 ++++++++++++++++++++-------- src/frontend/mame/ui/filesel.h | 3 ++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/frontend/mame/ui/filesel.cpp b/src/frontend/mame/ui/filesel.cpp index cc4ef070020..d25abdb4d50 100644 --- a/src/frontend/mame/ui/filesel.cpp +++ b/src/frontend/mame/ui/filesel.cpp @@ -420,16 +420,28 @@ int menu_file_selector::compare_entries(const file_selector_entry *e1, const fil //------------------------------------------------- menu_file_selector::file_selector_entry *menu_file_selector::append_entry( - file_selector_entry_type entry_type, const char *entry_basename, const char *entry_fullpath) + file_selector_entry_type entry_type, const std::string &entry_basename, const std::string &entry_fullpath) +{ + return append_entry(entry_type, std::string(entry_basename), std::string(entry_fullpath)); +} + + +//------------------------------------------------- +// append_entry - appends a new +// file selector entry to an entry list +//------------------------------------------------- + +menu_file_selector::file_selector_entry *menu_file_selector::append_entry( + file_selector_entry_type entry_type, std::string &&entry_basename, std::string &&entry_fullpath) { // allocate a new entry file_selector_entry entry; entry.type = entry_type; - entry.basename.assign(entry_basename ? entry_basename : ""); - entry.fullpath.assign(entry_fullpath ? entry_fullpath : ""); + entry.basename = std::move(entry_basename); + entry.fullpath = std::move(entry_fullpath); // find the end of the list - m_entrylist.push_back(entry); + m_entrylist.emplace_back(std::move(entry)); return &m_entrylist[m_entrylist.size() - 1]; } @@ -467,7 +479,7 @@ menu_file_selector::file_selector_entry *menu_file_selector::append_dirent_entry entry = append_entry( entry_type, dirent->name, - buffer.c_str()); + std::move(buffer)); return entry; } @@ -540,19 +552,19 @@ void menu_file_selector::populate() if (m_has_empty) { // add the "[empty slot]" entry - append_entry(SELECTOR_ENTRY_TYPE_EMPTY, nullptr, nullptr); + append_entry(SELECTOR_ENTRY_TYPE_EMPTY, "", ""); } if (m_has_create) { // add the "[create]" entry - append_entry(SELECTOR_ENTRY_TYPE_CREATE, nullptr, nullptr); + append_entry(SELECTOR_ENTRY_TYPE_CREATE, "", ""); } if (m_has_softlist) { // add the "[software list]" entry - entry = append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, nullptr, nullptr); + entry = append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, "", ""); selected_entry = entry; } diff --git a/src/frontend/mame/ui/filesel.h b/src/frontend/mame/ui/filesel.h index ff436a7682b..1fd1fa45624 100644 --- a/src/frontend/mame/ui/filesel.h +++ b/src/frontend/mame/ui/filesel.h @@ -103,7 +103,8 @@ private: // methods int compare_entries(const file_selector_entry *e1, const file_selector_entry *e2); - file_selector_entry *append_entry(file_selector_entry_type entry_type, const char *entry_basename, const char *entry_fullpath); + file_selector_entry *append_entry(file_selector_entry_type entry_type, const std::string &entry_basename, const std::string &entry_fullpath); + file_selector_entry *append_entry(file_selector_entry_type entry_type, std::string &&entry_basename, std::string &&entry_fullpath); file_selector_entry *append_dirent_entry(const osd::directory::entry *dirent); void append_entry_menu_item(const file_selector_entry *entry); }; From 37e0253f51300a333c9e0596d5a0fa4fed94af9c Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Thu, 30 Jun 2016 07:45:57 -0400 Subject: [PATCH 3/4] Reduced usage of c_str() when used with menu::item_append() --- src/frontend/mame/ui/barcode.cpp | 2 +- src/frontend/mame/ui/custmenu.cpp | 14 +++++++------- src/frontend/mame/ui/custui.cpp | 22 +++++++++++----------- src/frontend/mame/ui/inputmap.cpp | 6 +++--- src/frontend/mame/ui/miscmenu.cpp | 2 +- src/frontend/mame/ui/optsmenu.cpp | 10 +++++----- src/frontend/mame/ui/pluginopt.cpp | 2 +- src/frontend/mame/ui/selector.cpp | 4 ++-- src/frontend/mame/ui/selgame.cpp | 2 +- src/frontend/mame/ui/selsoft.cpp | 6 +++--- src/frontend/mame/ui/sliders.cpp | 4 ++-- src/frontend/mame/ui/slotopt.cpp | 2 +- src/frontend/mame/ui/sndmenu.cpp | 2 +- src/frontend/mame/ui/swlist.cpp | 2 +- src/frontend/mame/ui/tapectrl.cpp | 2 +- src/frontend/mame/ui/videoopt.cpp | 2 +- 16 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/frontend/mame/ui/barcode.cpp b/src/frontend/mame/ui/barcode.cpp index 48c3ed52b2e..bd31e625a5a 100644 --- a/src/frontend/mame/ui/barcode.cpp +++ b/src/frontend/mame/ui/barcode.cpp @@ -57,7 +57,7 @@ void menu_barcode_reader::populate() const char *new_barcode; // selected device - item_append(current_display_name().c_str(), "", current_display_flags(), ITEMREF_SELECT_READER); + item_append(current_display_name(), "", current_display_flags(), ITEMREF_SELECT_READER); // append the "New Barcode" item if (get_selection() == ITEMREF_NEW_BARCODE) diff --git a/src/frontend/mame/ui/custmenu.cpp b/src/frontend/mame/ui/custmenu.cpp index 33e940a21b5..ed2db5fcd96 100644 --- a/src/frontend/mame/ui/custmenu.cpp +++ b/src/frontend/mame/ui/custmenu.cpp @@ -176,7 +176,7 @@ void menu_custom_filter::populate() arrow_flags = get_arrow_flags(0, c_mnfct::ui.size() - 1, custfltr::mnfct[x]); std::string fbuff(_("^!Manufacturer")); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), c_mnfct::ui[custfltr::mnfct[x]].c_str(), arrow_flags, (void *)(FPTR)(MNFCT_FILTER + x)); + item_append(fbuff, c_mnfct::ui[custfltr::mnfct[x]], arrow_flags, (void *)(FPTR)(MNFCT_FILTER + x)); } // add year subitem @@ -185,7 +185,7 @@ void menu_custom_filter::populate() arrow_flags = get_arrow_flags(0, c_year::ui.size() - 1, custfltr::year[x]); std::string fbuff(_("^!Year")); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), c_year::ui[custfltr::year[x]].c_str(), arrow_flags, (void *)(FPTR)(YEAR_FILTER + x)); + item_append(fbuff, c_year::ui[custfltr::year[x]], arrow_flags, (void *)(FPTR)(YEAR_FILTER + x)); } } @@ -463,7 +463,7 @@ void menu_swcustom_filter::populate() arrow_flags = get_arrow_flags(0, m_filter.publisher.ui.size() - 1, sw_custfltr::mnfct[x]); std::string fbuff(_("^!Publisher")); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), m_filter.publisher.ui[sw_custfltr::mnfct[x]].c_str(), arrow_flags, (void *)(FPTR)(MNFCT_FILTER + x)); + item_append(fbuff, m_filter.publisher.ui[sw_custfltr::mnfct[x]], arrow_flags, (void *)(FPTR)(MNFCT_FILTER + x)); } // add year subitem @@ -472,7 +472,7 @@ void menu_swcustom_filter::populate() arrow_flags = get_arrow_flags(0, m_filter.year.ui.size() - 1, sw_custfltr::year[x]); std::string fbuff(_("^!Year")); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), m_filter.year.ui[sw_custfltr::year[x]].c_str(), arrow_flags, (void *)(FPTR)(YEAR_FILTER + x)); + item_append(fbuff, m_filter.year.ui[sw_custfltr::year[x]], arrow_flags, (void *)(FPTR)(YEAR_FILTER + x)); } // add year subitem @@ -481,7 +481,7 @@ void menu_swcustom_filter::populate() arrow_flags = get_arrow_flags(0, m_filter.swlist.name.size() - 1, sw_custfltr::list[x]); std::string fbuff(_("^!Software List")); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), m_filter.swlist.description[sw_custfltr::list[x]].c_str(), arrow_flags, (void *)(FPTR)(LIST_FILTER + x)); + item_append(fbuff, m_filter.swlist.description[sw_custfltr::list[x]], arrow_flags, (void *)(FPTR)(LIST_FILTER + x)); } // add device type subitem @@ -490,7 +490,7 @@ void menu_swcustom_filter::populate() arrow_flags = get_arrow_flags(0, m_filter.type.ui.size() - 1, sw_custfltr::type[x]); std::string fbuff(_("^!Device type")); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), m_filter.type.ui[sw_custfltr::type[x]].c_str(), arrow_flags, (void *)(FPTR)(TYPE_FILTER + x)); + item_append(fbuff, m_filter.type.ui[sw_custfltr::type[x]], arrow_flags, (void *)(FPTR)(TYPE_FILTER + x)); } // add region subitem @@ -499,7 +499,7 @@ void menu_swcustom_filter::populate() arrow_flags = get_arrow_flags(0, m_filter.region.ui.size() - 1, sw_custfltr::region[x]); std::string fbuff(_("^!Region")); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), m_filter.region.ui[sw_custfltr::region[x]].c_str(), arrow_flags, (void *)(FPTR)(REGION_FILTER + x)); + item_append(fbuff, m_filter.region.ui[sw_custfltr::region[x]], arrow_flags, (void *)(FPTR)(REGION_FILTER + x)); } } diff --git a/src/frontend/mame/ui/custui.cpp b/src/frontend/mame/ui/custui.cpp index 77ae3388959..6eb4352e0c5 100644 --- a/src/frontend/mame/ui/custui.cpp +++ b/src/frontend/mame/ui/custui.cpp @@ -345,7 +345,7 @@ void menu_font_ui::populate() // add fonts option arrow_flags = get_arrow_flags(0, m_fonts.size() - 1, m_actual); - item_append(_("UI Font"), m_fonts[m_actual].second.c_str(), arrow_flags, (void *)(FPTR)MUI_FNT); + item_append(_("UI Font"), m_fonts[m_actual].second, arrow_flags, (void *)(FPTR)MUI_FNT); #ifdef UI_WINDOWS if (m_fonts[m_actual].first != "default") @@ -356,13 +356,13 @@ void menu_font_ui::populate() #endif arrow_flags = get_arrow_flags(m_font_min, m_font_max, m_font_size); - item_append(_("Lines"), string_format("%2d", m_font_size).c_str(), arrow_flags, (void *)(FPTR)FONT_SIZE); + item_append(_("Lines"), string_format("%2d", m_font_size), arrow_flags, (void *)(FPTR)FONT_SIZE); item_append(menu_item_type::SEPARATOR); // add item arrow_flags = get_arrow_flags(m_info_min, m_info_max, m_info_size); - item_append(_("Infos text size"), string_format("%3.2f", m_info_size).c_str(), arrow_flags, (void *)(FPTR)INFOS_SIZE); + item_append(_("Infos text size"), string_format("%3.2f", m_info_size), arrow_flags, (void *)(FPTR)INFOS_SIZE); item_append(menu_item_type::SEPARATOR); @@ -833,34 +833,34 @@ void menu_rgb_ui::populate() if (m_lock_ref != RGB_ALPHA) { arrow_flags = get_arrow_flags(0, 255, m_color->a()); - item_append(_("Alpha"), string_format("%3u", m_color->a()).c_str(), arrow_flags, (void *)(FPTR)RGB_ALPHA); + item_append(_("Alpha"), string_format("%3u", m_color->a()), arrow_flags, (void *)(FPTR)RGB_ALPHA); } else - item_append(_("Alpha"), s_text.c_str(), 0, (void *)(FPTR)RGB_ALPHA); + item_append(_("Alpha"), s_text, 0, (void *)(FPTR)RGB_ALPHA); if (m_lock_ref != RGB_RED) { arrow_flags = get_arrow_flags(0, 255, m_color->r()); - item_append(_("Red"), string_format("%3u", m_color->r()).c_str(), arrow_flags, (void *)(FPTR)RGB_RED); + item_append(_("Red"), string_format("%3u", m_color->r()), arrow_flags, (void *)(FPTR)RGB_RED); } else - item_append(_("Red"), s_text.c_str(), 0, (void *)(FPTR)RGB_RED); + item_append(_("Red"), s_text, 0, (void *)(FPTR)RGB_RED); if (m_lock_ref != RGB_GREEN) { arrow_flags = get_arrow_flags(0, 255, m_color->g()); - item_append(_("Green"), string_format("%3u", m_color->g()).c_str(), arrow_flags, (void *)(FPTR)RGB_GREEN); + item_append(_("Green"), string_format("%3u", m_color->g()), arrow_flags, (void *)(FPTR)RGB_GREEN); } else - item_append(_("Green"), s_text.c_str(), 0, (void *)(FPTR)RGB_GREEN); + item_append(_("Green"), s_text, 0, (void *)(FPTR)RGB_GREEN); if (m_lock_ref != RGB_BLUE) { arrow_flags = get_arrow_flags(0, 255, m_color->b()); - item_append(_("Blue"), string_format("%3u", m_color->b()).c_str(), arrow_flags, (void *)(FPTR)RGB_BLUE); + item_append(_("Blue"), string_format("%3u", m_color->b()), arrow_flags, (void *)(FPTR)RGB_BLUE); } else - item_append(_("Blue"), s_text.c_str(), 0, (void *)(FPTR)RGB_BLUE); + item_append(_("Blue"), s_text, 0, (void *)(FPTR)RGB_BLUE); item_append(menu_item_type::SEPARATOR); item_append(_("Choose from palette"), "", 0, (void *)(FPTR)PALETTE_CHOOSE); diff --git a/src/frontend/mame/ui/inputmap.cpp b/src/frontend/mame/ui/inputmap.cpp index bf883b6cfa8..224b37c7944 100644 --- a/src/frontend/mame/ui/inputmap.cpp +++ b/src/frontend/mame/ui/inputmap.cpp @@ -810,8 +810,6 @@ menu_analog::menu_analog(mame_ui_manager &mui, render_container *container) : me void menu_analog::populate() { - std::string text; - std::string subtext; std::string prev_owner; bool first_entry = true; @@ -856,6 +854,8 @@ void menu_analog::populate() { analog_item_data *data; UINT32 flags = 0; + std::string text; + std::string subtext; if (strcmp(field.device().tag(), prev_owner.c_str()) != 0) { if (first_entry) @@ -919,7 +919,7 @@ void menu_analog::populate() flags |= FLAG_RIGHT_ARROW; /* append a menu item */ - item_append(text.c_str(), subtext.c_str(), flags, data); + item_append(std::move(text), std::move(subtext), flags, data); } } } diff --git a/src/frontend/mame/ui/miscmenu.cpp b/src/frontend/mame/ui/miscmenu.cpp index 75458399e75..cbaeafc258a 100644 --- a/src/frontend/mame/ui/miscmenu.cpp +++ b/src/frontend/mame/ui/miscmenu.cpp @@ -775,7 +775,7 @@ void menu_machine_configure::populate() if (!m_bios.empty()) { UINT32 arrows = get_arrow_flags(0, m_bios.size() - 1, m_curbios); - item_append(_("Driver"), m_bios[m_curbios].first.c_str(), arrows, (void *)(FPTR)BIOS); + item_append(_("Driver"), m_bios[m_curbios].first, arrows, (void *)(FPTR)BIOS); } else item_append(_("This machine has no bios."), "", FLAG_DISABLE, nullptr); diff --git a/src/frontend/mame/ui/optsmenu.cpp b/src/frontend/mame/ui/optsmenu.cpp index 53af02c2363..5762ec9af9f 100644 --- a/src/frontend/mame/ui/optsmenu.cpp +++ b/src/frontend/mame/ui/optsmenu.cpp @@ -239,12 +239,12 @@ void menu_game_options::populate() arrow_flags = get_arrow_flags(0, inif.total() - 1, inif.cur_file()); fbuff = _(" ^!File"); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), inif.get_file().c_str(), arrow_flags, (void *)(FPTR)FILE_CATEGORY_FILTER); + item_append(fbuff, inif.get_file(), arrow_flags, (void *)(FPTR)FILE_CATEGORY_FILTER); arrow_flags = get_arrow_flags(0, inif.cat_total() - 1, inif.cur_cat()); fbuff = _(" ^!Category"); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), inif.get_category().c_str(), arrow_flags, (void *)(FPTR)CATEGORY_FILTER); + item_append(fbuff, inif.get_category(), arrow_flags, (void *)(FPTR)CATEGORY_FILTER); } // add manufacturer subitem else if (m_main == FILTER_MANUFACTURER && c_mnfct::ui.size() > 0) @@ -252,7 +252,7 @@ void menu_game_options::populate() arrow_flags = get_arrow_flags(0, c_mnfct::ui.size() - 1, c_mnfct::actual); fbuff = _("^!Manufacturer"); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), c_mnfct::ui[c_mnfct::actual].c_str(), arrow_flags, (void *)(FPTR)MANUFACT_CAT_FILTER); + item_append(fbuff, c_mnfct::ui[c_mnfct::actual], arrow_flags, (void *)(FPTR)MANUFACT_CAT_FILTER); } // add year subitem else if (m_main == FILTER_YEAR && c_year::ui.size() > 0) @@ -260,14 +260,14 @@ void menu_game_options::populate() arrow_flags = get_arrow_flags(0, c_year::ui.size() - 1, c_year::actual); fbuff.assign(_("^!Year")); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), c_year::ui[c_year::actual].c_str(), arrow_flags, (void *)(FPTR)YEAR_CAT_FILTER); + item_append(fbuff, c_year::ui[c_year::actual], arrow_flags, (void *)(FPTR)YEAR_CAT_FILTER); } // add custom subitem else if (m_main == FILTER_CUSTOM) { fbuff = _("^!Setup custom filter"); convert_command_glyph(fbuff); - item_append(fbuff.c_str(), "", 0, (void *)(FPTR)CUSTOM_FILTER); + item_append(fbuff, "", 0, (void *)(FPTR)CUSTOM_FILTER); } item_append(menu_item_type::SEPARATOR); diff --git a/src/frontend/mame/ui/pluginopt.cpp b/src/frontend/mame/ui/pluginopt.cpp index c650fc78a91..c55a25468ba 100644 --- a/src/frontend/mame/ui/pluginopt.cpp +++ b/src/frontend/mame/ui/pluginopt.cpp @@ -106,7 +106,7 @@ void menu_plugin_opt::populate() else if(item.flags == "lr") flags = FLAG_RIGHT_ARROW | FLAG_LEFT_ARROW; - item_append(item.text.c_str(), item.subtext.c_str(), flags, (void *)i++); + item_append(item.text, item.subtext, flags, (void *)i++); } item_append(menu_item_type::SEPARATOR); } diff --git a/src/frontend/mame/ui/selector.cpp b/src/frontend/mame/ui/selector.cpp index aeea3aeae17..f5f07c0c2b3 100644 --- a/src/frontend/mame/ui/selector.cpp +++ b/src/frontend/mame/ui/selector.cpp @@ -137,7 +137,7 @@ void menu_selector::populate() find_matches(m_search); for (int curitem = 0; m_searchlist[curitem]; ++curitem) - item_append(m_searchlist[curitem]->c_str(), "", 0, (void *)m_searchlist[curitem]); + item_append(*m_searchlist[curitem], "", 0, (void *)m_searchlist[curitem]); } else { @@ -148,7 +148,7 @@ void menu_selector::populate() selected = added; added++; - item_append(m_str_items[index].c_str(), "", 0, (void *)&m_str_items[index]); + item_append(m_str_items[index], "", 0, (void *)&m_str_items[index]); } } diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp index 4884c8f94eb..0368d9cbbaf 100644 --- a/src/frontend/mame/ui/selgame.cpp +++ b/src/frontend/mame/ui/selgame.cpp @@ -587,7 +587,7 @@ void menu_select_game::populate() { if (old_item_selected == -1 && mfavorite.shortname == reselect_last::driver) old_item_selected = curitem; - item_append(mfavorite.longname.c_str(), mfavorite.devicetype.c_str(), + item_append(mfavorite.longname, mfavorite.devicetype, mfavorite.parentname.empty() ? flags_ui : (FLAG_INVERT | flags_ui), (void *)&mfavorite); } curitem++; diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp index 3426166af02..c1be3b66e9d 100644 --- a/src/frontend/mame/ui/selsoft.cpp +++ b/src/frontend/mame/ui/selsoft.cpp @@ -477,7 +477,7 @@ void menu_select_software::populate() else if (m_displaylist[curitem]->shortname == reselect_last::software && m_displaylist[curitem]->listname == reselect_last::swlist) old_software = m_has_empty_start ? curitem + 1 : curitem; - item_append(m_displaylist[curitem]->longname.c_str(), m_displaylist[curitem]->devicetype.c_str(), + item_append(m_displaylist[curitem]->longname, m_displaylist[curitem]->devicetype, m_displaylist[curitem]->parentname.empty() ? flags_ui : (FLAG_INVERT | flags_ui), (void *)m_displaylist[curitem]); } } @@ -487,7 +487,7 @@ void menu_select_software::populate() find_matches(m_search, VISIBLE_GAMES_IN_SEARCH); for (int curitem = 0; m_searchlist[curitem] != nullptr; ++curitem) - item_append(m_searchlist[curitem]->longname.c_str(), m_searchlist[curitem]->devicetype.c_str(), + item_append(m_searchlist[curitem]->longname, m_searchlist[curitem]->devicetype, m_searchlist[curitem]->parentname.empty() ? flags_ui : (FLAG_INVERT | flags_ui), (void *)m_searchlist[curitem]); } @@ -1938,7 +1938,7 @@ software_parts::~software_parts() void software_parts::populate() { for (auto & elem : m_parts) - item_append(elem.first.c_str(), elem.second.c_str(), 0, (void *)&elem); + item_append(elem.first, elem.second, 0, (void *)&elem); item_append(menu_item_type::SEPARATOR); customtop = ui().get_line_height() + (3.0f * UI_BOX_TB_BORDER); diff --git a/src/frontend/mame/ui/sliders.cpp b/src/frontend/mame/ui/sliders.cpp index f8854b0aaca..8d4143259e8 100644 --- a/src/frontend/mame/ui/sliders.cpp +++ b/src/frontend/mame/ui/sliders.cpp @@ -152,7 +152,7 @@ void menu_sliders::populate() flags |= FLAG_LEFT_ARROW; if (curval < slider->maxval) flags |= FLAG_RIGHT_ARROW; - item_append(slider->description, tempstring.c_str(), flags, (void *)slider, menu_item_type::SLIDER); + item_append(slider->description, tempstring, flags, (void *)slider, menu_item_type::SLIDER); } else { @@ -175,7 +175,7 @@ void menu_sliders::populate() flags |= FLAG_LEFT_ARROW; if (curval < slider->maxval) flags |= FLAG_RIGHT_ARROW; - item_append(slider->description, tempstring.c_str(), flags, (void *)slider, menu_item_type::SLIDER); + item_append(slider->description, tempstring, flags, (void *)slider, menu_item_type::SLIDER); } else { diff --git a/src/frontend/mame/ui/slotopt.cpp b/src/frontend/mame/ui/slotopt.cpp index c23346ef493..d6b1a438c30 100644 --- a/src/frontend/mame/ui/slotopt.cpp +++ b/src/frontend/mame/ui/slotopt.cpp @@ -168,7 +168,7 @@ void menu_slot_devices::populate() opt_name.append(_(" [internal]")); } - item_append(slot.device().tag() + 1, opt_name.c_str(), (slot.fixed() || slot_get_length(slot) == 0) ? 0 : (FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW), (void *)&slot); + item_append(slot.device().tag() + 1, opt_name, (slot.fixed() || slot_get_length(slot) == 0) ? 0 : (FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW), (void *)&slot); } item_append(menu_item_type::SEPARATOR); item_append(_("Reset"), "", 0, (void *)1); diff --git a/src/frontend/mame/ui/sndmenu.cpp b/src/frontend/mame/ui/sndmenu.cpp index a4f32222aa6..55e62062512 100644 --- a/src/frontend/mame/ui/sndmenu.cpp +++ b/src/frontend/mame/ui/sndmenu.cpp @@ -131,7 +131,7 @@ void menu_sound_options::populate() // add options items item_append(_("Sound"), m_sound ? _("On") : _("Off"), m_sound ? FLAG_RIGHT_ARROW : FLAG_LEFT_ARROW, (void *)(FPTR)ENABLE_SOUND); - item_append(_("Sample Rate"), string_format("%d", m_sample_rate).c_str(), arrow_flags, (void *)(FPTR)SAMPLE_RATE); + item_append(_("Sample Rate"), string_format("%d", m_sample_rate), arrow_flags, (void *)(FPTR)SAMPLE_RATE); item_append(_("Use External Samples"), m_samples ? _("On") : _("Off"), m_samples ? FLAG_RIGHT_ARROW : FLAG_LEFT_ARROW, (void *)(FPTR)ENABLE_SAMPLES); item_append(menu_item_type::SEPARATOR); diff --git a/src/frontend/mame/ui/swlist.cpp b/src/frontend/mame/ui/swlist.cpp index be1f817abc0..bc554469a25 100644 --- a/src/frontend/mame/ui/swlist.cpp +++ b/src/frontend/mame/ui/swlist.cpp @@ -90,7 +90,7 @@ void menu_software_parts::populate() menu_part_name.append(" (").append(swpart.feature("part_id")).append(")"); entry->type = T_ENTRY; entry->part = &swpart; - item_append(m_info->shortname(), menu_part_name.c_str(), 0, entry); + item_append(m_info->shortname(), menu_part_name, 0, entry); } } } diff --git a/src/frontend/mame/ui/tapectrl.cpp b/src/frontend/mame/ui/tapectrl.cpp index 44150b67467..afc5f9d6894 100644 --- a/src/frontend/mame/ui/tapectrl.cpp +++ b/src/frontend/mame/ui/tapectrl.cpp @@ -59,7 +59,7 @@ void menu_tape_control::populate() if (current_device()) { // name of tape - item_append(current_display_name().c_str(), current_device()->exists() ? current_device()->filename() : "No Tape Image loaded", current_display_flags(), TAPECMD_SELECT); + item_append(current_display_name(), current_device()->exists() ? current_device()->filename() : "No Tape Image loaded", current_display_flags(), TAPECMD_SELECT); if (current_device()->exists()) { diff --git a/src/frontend/mame/ui/videoopt.cpp b/src/frontend/mame/ui/videoopt.cpp index ff605cadf32..cf558b46467 100644 --- a/src/frontend/mame/ui/videoopt.cpp +++ b/src/frontend/mame/ui/videoopt.cpp @@ -187,7 +187,7 @@ void menu_video_options::populate() /* create a string for the item, replacing underscores with spaces */ tempstring.assign(name); strreplace(tempstring, "_", " "); - item_append(tempstring.c_str(), "", 0, (void *)(FPTR)(VIDEO_ITEM_VIEW + viewnum)); + item_append(tempstring, "", 0, (void *)(FPTR)(VIDEO_ITEM_VIEW + viewnum)); } /* add a separator */ From 1d508951c746a32a15d519afc9fe6635564aa4ec Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Thu, 30 Jun 2016 09:58:23 -0400 Subject: [PATCH 4/4] Changing menu_file_selector::append_entry() to return a reference instead of a pointer --- src/frontend/mame/ui/filesel.cpp | 10 +++++----- src/frontend/mame/ui/filesel.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/frontend/mame/ui/filesel.cpp b/src/frontend/mame/ui/filesel.cpp index d25abdb4d50..deaef81c3d0 100644 --- a/src/frontend/mame/ui/filesel.cpp +++ b/src/frontend/mame/ui/filesel.cpp @@ -419,7 +419,7 @@ int menu_file_selector::compare_entries(const file_selector_entry *e1, const fil // file selector entry to an entry list //------------------------------------------------- -menu_file_selector::file_selector_entry *menu_file_selector::append_entry( +menu_file_selector::file_selector_entry &menu_file_selector::append_entry( file_selector_entry_type entry_type, const std::string &entry_basename, const std::string &entry_fullpath) { return append_entry(entry_type, std::string(entry_basename), std::string(entry_fullpath)); @@ -431,7 +431,7 @@ menu_file_selector::file_selector_entry *menu_file_selector::append_entry( // file selector entry to an entry list //------------------------------------------------- -menu_file_selector::file_selector_entry *menu_file_selector::append_entry( +menu_file_selector::file_selector_entry &menu_file_selector::append_entry( file_selector_entry_type entry_type, std::string &&entry_basename, std::string &&entry_fullpath) { // allocate a new entry @@ -442,7 +442,7 @@ menu_file_selector::file_selector_entry *menu_file_selector::append_entry( // find the end of the list m_entrylist.emplace_back(std::move(entry)); - return &m_entrylist[m_entrylist.size() - 1]; + return m_entrylist[m_entrylist.size() - 1]; } @@ -476,7 +476,7 @@ menu_file_selector::file_selector_entry *menu_file_selector::append_dirent_entry util::zippath_combine(buffer, m_current_directory.c_str(), dirent->name); // create the file selector entry - entry = append_entry( + entry = &append_entry( entry_type, dirent->name, std::move(buffer)); @@ -564,7 +564,7 @@ void menu_file_selector::populate() if (m_has_softlist) { // add the "[software list]" entry - entry = append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, "", ""); + entry = &append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, "", ""); selected_entry = entry; } diff --git a/src/frontend/mame/ui/filesel.h b/src/frontend/mame/ui/filesel.h index 1fd1fa45624..2960c6a6b5b 100644 --- a/src/frontend/mame/ui/filesel.h +++ b/src/frontend/mame/ui/filesel.h @@ -103,8 +103,8 @@ private: // methods int compare_entries(const file_selector_entry *e1, const file_selector_entry *e2); - file_selector_entry *append_entry(file_selector_entry_type entry_type, const std::string &entry_basename, const std::string &entry_fullpath); - file_selector_entry *append_entry(file_selector_entry_type entry_type, std::string &&entry_basename, std::string &&entry_fullpath); + file_selector_entry &append_entry(file_selector_entry_type entry_type, const std::string &entry_basename, const std::string &entry_fullpath); + file_selector_entry &append_entry(file_selector_entry_type entry_type, std::string &&entry_basename, std::string &&entry_fullpath); file_selector_entry *append_dirent_entry(const osd::directory::entry *dirent); void append_entry_menu_item(const file_selector_entry *entry); };