mirror of
https://github.com/holub/mame
synced 2025-06-13 16:15:32 +03:00
STL makes life easier
This commit is contained in:
parent
d74f5db813
commit
a26f4f3428
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <forward_list>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
|
|
||||||
@ -25,20 +26,6 @@ namespace util {
|
|||||||
TYPE DEFINITIONS
|
TYPE DEFINITIONS
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
/**
|
|
||||||
* @struct zippath_returned_directory
|
|
||||||
*
|
|
||||||
* @brief A zippath returned directory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct zippath_returned_directory
|
|
||||||
{
|
|
||||||
/** @brief The next. */
|
|
||||||
zippath_returned_directory *next;
|
|
||||||
/** @brief The name. */
|
|
||||||
std::string name;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class zippath_directory
|
* @class zippath_directory
|
||||||
*
|
*
|
||||||
@ -49,11 +36,13 @@ class zippath_directory
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
zippath_directory()
|
zippath_directory()
|
||||||
: returned_parent(false),
|
: returned_parent(false)
|
||||||
directory(nullptr),
|
, directory(nullptr)
|
||||||
called_zip_first(false),
|
, called_zip_first(false)
|
||||||
zipfile(nullptr),
|
, zipfile(nullptr)
|
||||||
returned_dirlist(nullptr) { }
|
, returned_dirlist()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
/** @brief true to returned parent. */
|
/** @brief true to returned parent. */
|
||||||
@ -73,7 +62,7 @@ public:
|
|||||||
/** @brief The zipprefix. */
|
/** @brief The zipprefix. */
|
||||||
std::string zipprefix;
|
std::string zipprefix;
|
||||||
/** @brief The returned dirlist. */
|
/** @brief The returned dirlist. */
|
||||||
zippath_returned_directory *returned_dirlist;
|
std::forward_list<std::string> returned_dirlist;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -856,12 +845,7 @@ void zippath_closedir(zippath_directory *directory)
|
|||||||
if (directory->zipfile != nullptr)
|
if (directory->zipfile != nullptr)
|
||||||
directory->zipfile.reset();
|
directory->zipfile.reset();
|
||||||
|
|
||||||
while (directory->returned_dirlist != nullptr)
|
directory->returned_dirlist.clear();
|
||||||
{
|
|
||||||
zippath_returned_directory *dirlist = directory->returned_dirlist;
|
|
||||||
directory->returned_dirlist = directory->returned_dirlist->next;
|
|
||||||
delete dirlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete directory;
|
delete directory;
|
||||||
}
|
}
|
||||||
@ -978,24 +962,23 @@ const osd_directory_entry *zippath_readdir(zippath_directory *directory)
|
|||||||
{
|
{
|
||||||
/* a nested entry; loop through returned_dirlist to see if we've returned the parent directory */
|
/* a nested entry; loop through returned_dirlist to see if we've returned the parent directory */
|
||||||
auto const len(separator - relpath);
|
auto const len(separator - relpath);
|
||||||
zippath_returned_directory *rdent;
|
auto rdent = directory->returned_dirlist.begin();
|
||||||
for (rdent = directory->returned_dirlist; rdent != nullptr; rdent = rdent->next)
|
while (directory->returned_dirlist.end() != rdent)
|
||||||
{
|
{
|
||||||
if ((rdent->name.length() == len) && !core_strnicmp(rdent->name.c_str(), relpath, len))
|
if ((rdent->length() == len) && !core_strnicmp(rdent->c_str(), relpath, len))
|
||||||
break;
|
break;
|
||||||
|
else
|
||||||
|
++rdent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rdent)
|
if (directory->returned_dirlist.end() == rdent)
|
||||||
{
|
{
|
||||||
/* we've found a new directory; add this to returned_dirlist */
|
/* we've found a new directory; add this to returned_dirlist */
|
||||||
rdent = new zippath_returned_directory;
|
directory->returned_dirlist.emplace_front(relpath, separator - relpath);
|
||||||
rdent->next = directory->returned_dirlist;
|
|
||||||
rdent->name.assign(relpath, separator - relpath);
|
|
||||||
directory->returned_dirlist = rdent;
|
|
||||||
|
|
||||||
/* ...and return it */
|
/* ...and return it */
|
||||||
memset(&directory->returned_entry, 0, sizeof(directory->returned_entry));
|
memset(&directory->returned_entry, 0, sizeof(directory->returned_entry));
|
||||||
directory->returned_entry.name = rdent->name.c_str();
|
directory->returned_entry.name = directory->returned_dirlist.front().c_str();
|
||||||
directory->returned_entry.type = ENTTYPE_DIR;
|
directory->returned_entry.type = ENTTYPE_DIR;
|
||||||
result = &directory->returned_entry;
|
result = &directory->returned_entry;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user