diff options
author | 2016-06-30 07:19:17 -0400 | |
---|---|---|
committer | 2016-06-30 07:19:17 -0400 | |
commit | dd57d5c00eb9ae75e8c9cab3ccfeddfd917beab8 (patch) | |
tree | e120b386a8b4ea0edba9575f4999e374fa9ed05e /src/frontend/mame/ui/filesel.cpp | |
parent | 7dd79891e91ba6a7591a68dc54677d6e829116be (diff) |
Changed filesel entrylist to be a vector
Diffstat (limited to 'src/frontend/mame/ui/filesel.cpp')
-rw-r--r-- | src/frontend/mame/ui/filesel.cpp | 66 |
1 files changed, 17 insertions, 49 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) - { - 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; - } - } - } - // and from the first entry to current one - for (entry = m_entrylist; entry != cur_selected; 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; + selected_entry = &entry; } } } |