Miscellaneous cleanups to diimage.[cpp|h]; mostly std::string stuff

This commit is contained in:
Nathan Woods 2016-07-29 08:29:47 -04:00
parent 0c4056fa93
commit b12da9c090
2 changed files with 31 additions and 32 deletions

View File

@ -96,8 +96,8 @@ device_image_interface::device_image_interface(const machine_config &mconfig, de
m_init_phase(false), m_init_phase(false),
m_create_format(0), m_create_format(0),
m_create_args(nullptr), m_create_args(nullptr),
m_user_loadable(TRUE), m_user_loadable(true),
m_is_loading(FALSE) m_is_loading(false)
{ {
} }
@ -184,10 +184,10 @@ void device_image_interface::device_compute_hash(util::hash_collection &hashes,
// an image // an image
//------------------------------------------------- //-------------------------------------------------
image_error_t device_image_interface::set_image_filename(const char *filename) image_error_t device_image_interface::set_image_filename(const std::string &filename)
{ {
m_image_name = filename; m_image_name = filename;
util::zippath_parent(m_working_directory, filename); util::zippath_parent(m_working_directory, filename.c_str());
m_basename.assign(m_image_name); m_basename.assign(m_image_name);
int loc1 = m_image_name.find_last_of('\\'); int loc1 = m_image_name.find_last_of('\\');
@ -226,10 +226,10 @@ image_error_t device_image_interface::set_image_filename(const char *filename)
// image creation by name // image creation by name
//------------------------------------------------- //-------------------------------------------------
const image_device_format *device_image_interface::device_get_named_creatable_format(const char *format_name) const image_device_format *device_image_interface::device_get_named_creatable_format(const std::string &format_name)
{ {
for (auto &format : m_formatlist) for (auto &format : m_formatlist)
if (strcmp(format->name().c_str(), format_name) == 0) if (format->name() == format_name)
return format.get(); return format.get();
return nullptr; return nullptr;
} }
@ -605,7 +605,7 @@ void device_image_interface::battery_save(const void *buffer, int length)
bool device_image_interface::uses_file_extension(const char *file_extension) const bool device_image_interface::uses_file_extension(const char *file_extension) const
{ {
bool result = FALSE; bool result = false;
if (file_extension[0] == '.') if (file_extension[0] == '.')
file_extension++; file_extension++;
@ -617,7 +617,7 @@ bool device_image_interface::uses_file_extension(const char *file_extension) con
{ {
if (!core_stricmp(ext, file_extension)) if (!core_stricmp(ext, file_extension))
{ {
result = TRUE; result = true;
break; break;
} }
ext = strtok (nullptr, ","); ext = strtok (nullptr, ",");
@ -646,13 +646,13 @@ bool device_image_interface::is_loaded()
// specific path // specific path
//------------------------------------------------- //-------------------------------------------------
image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, const char *path) image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, const std::string &path)
{ {
image_error_t err; image_error_t err;
std::string revised_path; std::string revised_path;
// attempt to read the file // attempt to read the file
auto const filerr = util::zippath_fopen(path, open_flags, m_file, revised_path); auto const filerr = util::zippath_fopen(path.c_str(), open_flags, m_file, revised_path);
// did the open succeed? // did the open succeed?
switch(filerr) switch(filerr)
@ -691,7 +691,7 @@ image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, cons
// if successful, set the file name // if successful, set the file name
if (filerr == osd_file::error::NONE) if (filerr == osd_file::error::NONE)
set_image_filename(revised_path.c_str()); set_image_filename(revised_path);
return err; return err;
} }
@ -833,7 +833,7 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
{ {
std::string locationtag, breakstr("%"); std::string locationtag, breakstr("%");
const rom_entry *region; const rom_entry *region;
bool retVal = FALSE; bool retVal = false;
int warningcount = 0; int warningcount = 0;
for (region = start; region != nullptr; region = rom_next_region(region)) for (region = start; region != nullptr; region = rom_next_region(region))
{ {
@ -915,7 +915,7 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
if (filerr == osd_file::error::NONE) if (filerr == osd_file::error::NONE)
filerr = util::core_file::open_proxy(*m_mame_file, m_file); filerr = util::core_file::open_proxy(*m_mame_file, m_file);
if (filerr == osd_file::error::NONE) if (filerr == osd_file::error::NONE)
retVal = TRUE; retVal = true;
break; // load first item for start break; // load first item for start
} }
@ -934,15 +934,14 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
// load_internal - core image loading // load_internal - core image loading
//------------------------------------------------- //-------------------------------------------------
bool device_image_interface::load_internal(const char *path, bool is_create, int create_format, util::option_resolution *create_args, bool just_load) bool device_image_interface::load_internal(const std::string &path, bool is_create, int create_format, util::option_resolution *create_args, bool just_load)
{ {
UINT32 open_plan[4]; UINT32 open_plan[4];
int i; int i;
bool softload = FALSE; bool softload = false;
// if the path contains no period, we are using softlists, so we won't create an image // if the path contains no period, we are using softlists, so we won't create an image
std::string pathstr(path); bool filename_has_period = (path.find_last_of('.') != -1);
bool filename_has_period = (pathstr.find_last_of('.') != -1) ? TRUE : FALSE;
// first unload the image // first unload the image
unload(); unload();
@ -951,7 +950,7 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int
clear_error(); clear_error();
// we are now loading // we are now loading
m_is_loading = TRUE; m_is_loading = true;
// record the filename // record the filename
m_err = set_image_filename(path); m_err = set_image_filename(path);
@ -964,7 +963,7 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int
// Check if there's a software list defined for this device and use that if we're not creating an image // Check if there's a software list defined for this device and use that if we're not creating an image
if (!filename_has_period && !just_load) if (!filename_has_period && !just_load)
{ {
softload = load_software_part(path, m_software_part_ptr); softload = load_software_part(path.c_str(), m_software_part_ptr);
if (softload) if (softload)
{ {
m_software_info_ptr = &m_software_part_ptr->info(); m_software_info_ptr = &m_software_part_ptr->info();
@ -974,7 +973,7 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int
// if we had launched from softlist with a specified part, e.g. "shortname:part" // if we had launched from softlist with a specified part, e.g. "shortname:part"
// we would have recorded the wrong name, so record it again based on software_info // we would have recorded the wrong name, so record it again based on software_info
if (m_software_info_ptr && !m_full_software_name.empty()) if (m_software_info_ptr && !m_full_software_name.empty())
m_err = set_image_filename(m_full_software_name.c_str()); m_err = set_image_filename(m_full_software_name);
// check if image should be read-only // check if image should be read-only
const char *read_only = get_feature("read_only"); const char *read_only = get_feature("read_only");
@ -1025,7 +1024,7 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int
m_create_format = create_format; m_create_format = create_format;
m_create_args = create_args; m_create_args = create_args;
if (m_init_phase==FALSE) { if (m_init_phase==false) {
m_err = (image_error_t)finish_load(); m_err = (image_error_t)finish_load();
if (m_err) if (m_err)
goto done; goto done;
@ -1043,7 +1042,7 @@ done:
if (device().machine().phase() == MACHINE_PHASE_RUNNING) if (device().machine().phase() == MACHINE_PHASE_RUNNING)
device().popmessage("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error()); device().popmessage("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error());
else else
osd_printf_error("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path, error()); osd_printf_error("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path.c_str(), error());
} }
clear(); clear();
} }
@ -1058,7 +1057,7 @@ done:
if (device().machine().phase() == MACHINE_PHASE_RUNNING) if (device().machine().phase() == MACHINE_PHASE_RUNNING)
device().popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded"); device().popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded");
else else
osd_printf_info("Image '%s' was successfully %s.\n", path, is_create ? "created" : "loaded"); osd_printf_info("Image '%s' was successfully %s.\n", path.c_str(), is_create ? "created" : "loaded");
} }
} }
} }
@ -1073,7 +1072,7 @@ done:
bool device_image_interface::load(const char *path) bool device_image_interface::load(const char *path)
{ {
return load_internal(path, FALSE, 0, nullptr, FALSE); return load_internal(path, false, 0, nullptr, false);
} }
@ -1087,7 +1086,7 @@ bool device_image_interface::open_image_file(emu_options &options)
if (*path != 0) if (*path != 0)
{ {
set_init_phase(); set_init_phase();
if (load_internal(path, FALSE, 0, nullptr, TRUE)==IMAGE_INIT_PASS) if (load_internal(path, false, 0, nullptr, true)==IMAGE_INIT_PASS)
{ {
if (software_entry()==nullptr) return true; if (software_entry()==nullptr) return true;
} }
@ -1129,10 +1128,10 @@ bool device_image_interface::finish_load()
} }
} }
} }
m_is_loading = FALSE; m_is_loading = false;
m_create_format = 0; m_create_format = 0;
m_create_args = nullptr; m_create_args = nullptr;
m_init_phase = FALSE; m_init_phase = false;
return err; return err;
} }
@ -1153,7 +1152,7 @@ bool device_image_interface::create(const char *path, const image_device_format
} }
cnt++; cnt++;
} }
return load_internal(path, TRUE, format_index, create_args, FALSE); return load_internal(path, true, format_index, create_args, false);
} }

View File

@ -166,7 +166,7 @@ public:
virtual const option_guide *create_option_guide() const { return nullptr; } virtual const option_guide *create_option_guide() const { return nullptr; }
const image_device_format *device_get_indexed_creatable_format(int index) const { if (index < m_formatlist.size()) return m_formatlist.at(index).get(); else return nullptr; } const image_device_format *device_get_indexed_creatable_format(int index) const { if (index < m_formatlist.size()) return m_formatlist.at(index).get(); else return nullptr; }
const image_device_format *device_get_named_creatable_format(const char *format_name); const image_device_format *device_get_named_creatable_format(const std::string &format_name);
const option_guide *device_get_creation_option_guide() const { return create_option_guide(); } const option_guide *device_get_creation_option_guide() const { return create_option_guide(); }
const char *error(); const char *error();
@ -251,13 +251,13 @@ public:
protected: protected:
virtual const software_list_loader &get_software_list_loader() const { return false_software_list_loader::instance(); } virtual const software_list_loader &get_software_list_loader() const { return false_software_list_loader::instance(); }
bool load_internal(const char *path, bool is_create, int create_format, util::option_resolution *create_args, bool just_load); bool load_internal(const std::string &path, bool is_create, int create_format, util::option_resolution *create_args, bool just_load);
void determine_open_plan(int is_create, UINT32 *open_plan); void determine_open_plan(int is_create, UINT32 *open_plan);
image_error_t load_image_by_path(UINT32 open_flags, const char *path); image_error_t load_image_by_path(UINT32 open_flags, const std::string &path);
void clear(); void clear();
bool is_loaded(); bool is_loaded();
image_error_t set_image_filename(const char *filename); image_error_t set_image_filename(const std::string &filename);
void clear_error(); void clear_error();