summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu
diff options
context:
space:
mode:
authorGravatarGravatar Vas Crabb <vas@vastheman.com>2019-11-10 04:08:29 +1100
committerGravatarGravatar Vas Crabb <vas@vastheman.com>2019-11-10 04:08:29 +1100
commit13b1ebb1b4512ba808cdc5dfbdac61ed0d755d8c (patch)
tree0be119271371bb88d200c5ec598c189e88218e8d /src/emu
parent1b2acde80819ca6917c248e496725158ed4fe12e (diff)
start putting noexcept on things that have no business throwing exceptions, starting with diimage. also fix a slight bug in the interface matching function for software list parts. (nw)
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/diimage.cpp15
-rw-r--r--src/emu/diimage.h80
-rw-r--r--src/emu/softlist.cpp78
-rw-r--r--src/emu/softlist.h22
4 files changed, 102 insertions, 93 deletions
diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp
index 542091471a2..5595ca809be 100644
--- a/src/emu/diimage.cpp
+++ b/src/emu/diimage.cpp
@@ -19,6 +19,7 @@
#include "softlist_dev.h"
#include "formats/ioprocs.h"
+#include <cstring>
#include <regex>
@@ -218,7 +219,7 @@ void device_image_interface::set_image_filename(const std::string &filename)
// image creation by name
//-------------------------------------------------
-const image_device_format *device_image_interface::device_get_named_creatable_format(const std::string &format_name)
+const image_device_format *device_image_interface::device_get_named_creatable_format(const std::string &format_name) noexcept
{
for (auto &format : m_formatlist)
if (format->name() == format_name)
@@ -431,7 +432,7 @@ const std::string &device_image_interface::working_directory()
// software_info structure from the softlist
//-------------------------------------------------
-const software_info *device_image_interface::software_entry() const
+const software_info *device_image_interface::software_entry() const noexcept
{
return !m_software_part_ptr ? nullptr : &m_software_part_ptr->info();
}
@@ -588,7 +589,7 @@ u32 device_image_interface::crc()
// end command line?
//-------------------------------------------------
-bool device_image_interface::support_command_line_image_creation() const
+bool device_image_interface::support_command_line_image_creation() const noexcept
{
bool result;
switch (image_type())
@@ -643,7 +644,7 @@ void device_image_interface::battery_load(void *buffer, int length, int fill)
memset(((char *)buffer) + bytes_read, fill, length - bytes_read);
}
-void device_image_interface::battery_load(void *buffer, int length, void *def_buffer)
+void device_image_interface::battery_load(void *buffer, int length, const void *def_buffer)
{
if (!buffer || (length <= 0))
throw emu_fatalerror("device_image_interface::battery_load: Must specify sensical buffer/length");
@@ -658,9 +659,9 @@ void device_image_interface::battery_load(void *buffer, int length, void *def_bu
if (filerr == osd_file::error::NONE)
bytes_read = file.read(buffer, length);
- // if no file was present, copy the default battery
- if (bytes_read == 0 && def_buffer)
- memcpy((char *)buffer, (char *)def_buffer, length);
+ // if no file was present, copy the default contents
+ if (!bytes_read && def_buffer)
+ std::memcpy(buffer, def_buffer, length);
}
diff --git a/src/emu/diimage.h b/src/emu/diimage.h
index 437546f27c6..2f9421bcf4d 100644
--- a/src/emu/diimage.h
+++ b/src/emu/diimage.h
@@ -80,10 +80,10 @@ public:
image_device_format(const std::string &name, const std::string &description, const std::string &extensions, const std::string &optspec);
~image_device_format();
- const std::string &name() const { return m_name; }
- const std::string &description() const { return m_description; }
- const std::vector<std::string> &extensions() const { return m_extensions; }
- const std::string &optspec() const { return m_optspec; }
+ const std::string &name() const noexcept { return m_name; }
+ const std::string &description() const noexcept { return m_description; }
+ const std::vector<std::string> &extensions() const noexcept { return m_extensions; }
+ const std::string &optspec() const noexcept { return m_optspec; }
private:
std::string m_name;
@@ -130,39 +130,39 @@ public:
virtual image_init_result call_create(int format_type, util::option_resolution *format_options) { return image_init_result::PASS; }
virtual void call_unload() { }
virtual std::string call_display() { return std::string(); }
- virtual u32 unhashed_header_length() const { return 0; }
- virtual bool core_opens_image_file() const { return true; }
- virtual iodevice_t image_type() const = 0;
- virtual bool is_readable() const = 0;
- virtual bool is_writeable() const = 0;
- virtual bool is_creatable() const = 0;
- virtual bool must_be_loaded() const = 0;
- virtual bool is_reset_on_load() const = 0;
- virtual bool support_command_line_image_creation() const;
- virtual const char *image_interface() const { return nullptr; }
- virtual const char *file_extensions() const = 0;
+ virtual u32 unhashed_header_length() const noexcept { return 0; }
+ virtual bool core_opens_image_file() const noexcept { return true; }
+ virtual iodevice_t image_type() const noexcept = 0;
+ virtual bool is_readable() const noexcept = 0;
+ virtual bool is_writeable() const noexcept = 0;
+ virtual bool is_creatable() const noexcept = 0;
+ virtual bool must_be_loaded() const noexcept = 0;
+ virtual bool is_reset_on_load() const noexcept = 0;
+ virtual bool support_command_line_image_creation() const noexcept;
+ virtual const char *image_interface() const noexcept { return nullptr; }
+ virtual const char *file_extensions() const noexcept = 0;
virtual const util::option_guide &create_option_guide() const;
- virtual const char *custom_instance_name() const { return nullptr; }
- virtual const char *custom_brief_instance_name() const { return nullptr; }
+ virtual const char *custom_instance_name() const noexcept { return nullptr; }
+ virtual const char *custom_brief_instance_name() const noexcept { 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 std::string &format_name);
+ const image_device_format *device_get_indexed_creatable_format(int index) const noexcept { return (index < m_formatlist.size()) ? m_formatlist.at(index).get() : nullptr; }
+ const image_device_format *device_get_named_creatable_format(const std::string &format_name) noexcept;
const util::option_guide &device_get_creation_option_guide() const { return create_option_guide(); }
const char *error();
void seterror(image_error_t err, const char *message);
void message(const char *format, ...) ATTR_PRINTF(2,3);
- bool exists() const { return !m_image_name.empty(); }
- const char *filename() const { if (m_image_name.empty()) return nullptr; else return m_image_name.c_str(); }
- const char *basename() const { if (m_basename.empty()) return nullptr; else return m_basename.c_str(); }
- const char *basename_noext() const { if (m_basename_noext.empty()) return nullptr; else return m_basename_noext.c_str(); }
- const std::string &filetype() const { return m_filetype; }
+ bool exists() const noexcept { return !m_image_name.empty(); }
+ const char *filename() const noexcept { return m_image_name.empty() ? nullptr : m_image_name.c_str(); }
+ const char *basename() const noexcept { return m_basename.empty() ? nullptr : m_basename.c_str(); }
+ const char *basename_noext() const noexcept { return m_basename_noext.empty() ? nullptr : m_basename_noext.c_str(); }
+ const std::string &filetype() const noexcept { return m_filetype; }
bool is_filetype(const std::string &candidate_filetype) { return !core_stricmp(filetype().c_str(), candidate_filetype.c_str()); }
- bool is_open() const { return bool(m_file); }
- util::core_file &image_core_file() const { return *m_file; }
+ bool is_open() const noexcept { return bool(m_file); }
+ util::core_file &image_core_file() const noexcept { return *m_file; }
u64 length() { check_for_file(); return m_file->size(); }
- bool is_readonly() const { return m_readonly; }
+ bool is_readonly() const noexcept { return m_readonly; }
u32 fread(void *buffer, u32 length) { check_for_file(); return m_file->read(buffer, length); }
u32 fread(optional_shared_ptr<u8> &ptr, u32 length) { ptr.allocate(length); return fread(ptr.target(), length); }
u32 fread(optional_shared_ptr<u8> &ptr, u32 length, offs_t offset) { ptr.allocate(length); return fread(ptr + offset, length - offset); }
@@ -175,15 +175,15 @@ public:
void *ptr() {check_for_file(); return const_cast<void *>(m_file->buffer()); }
// configuration access
- const std::string &longname() const { return m_longname; }
- const std::string &manufacturer() const { return m_manufacturer; }
- const std::string &year() const { return m_year; }
- u32 supported() const { return m_supported; }
+ const std::string &longname() const noexcept { return m_longname; }
+ const std::string &manufacturer() const noexcept { return m_manufacturer; }
+ const std::string &year() const noexcept { return m_year; }
+ u32 supported() const noexcept { return m_supported; }
- const software_info *software_entry() const;
- const software_part *part_entry() const { return m_software_part_ptr; }
- const char *software_list_name() const { return m_software_list_name.c_str(); }
- bool loaded_through_softlist() const { return m_software_part_ptr != nullptr; }
+ const software_info *software_entry() const noexcept;
+ const software_part *part_entry() const noexcept { return m_software_part_ptr; }
+ const char *software_list_name() const noexcept { return m_software_list_name.c_str(); }
+ bool loaded_through_softlist() const noexcept { return m_software_part_ptr != nullptr; }
void set_working_directory(const char *working_directory) { m_working_directory = working_directory; }
const std::string &working_directory();
@@ -198,7 +198,7 @@ public:
util::hash_collection calculate_hash_on_file(util::core_file &file) const;
void battery_load(void *buffer, int length, int fill);
- void battery_load(void *buffer, int length, void *def_buffer);
+ void battery_load(void *buffer, int length, const void *def_buffer);
void battery_save(const void *buffer, int length);
const char *image_type_name() const { return device_typename(image_type()); }
@@ -224,9 +224,9 @@ public:
void set_user_loadable(bool user_loadable) { m_user_loadable = user_loadable; }
- bool user_loadable() const { return m_user_loadable; }
- bool is_reset_and_loading() const { return m_is_reset_and_loading; }
- const std::string &full_software_name() const { return m_full_software_name; }
+ bool user_loadable() const noexcept { return m_user_loadable; }
+ bool is_reset_and_loading() const noexcept { return m_is_reset_and_loading; }
+ const std::string &full_software_name() const noexcept { return m_full_software_name; }
protected:
// interface-level overrides
@@ -249,7 +249,7 @@ protected:
void setup_working_directory();
bool try_change_working_directory(const std::string &subdir);
- void make_readonly() { m_readonly = true; }
+ void make_readonly() noexcept { m_readonly = true; }
bool image_checkhash();
diff --git a/src/emu/softlist.cpp b/src/emu/softlist.cpp
index 04302f6b514..690bb47415f 100644
--- a/src/emu/softlist.cpp
+++ b/src/emu/softlist.cpp
@@ -15,6 +15,7 @@
#include "expat.h"
+#include <cstring>
#include <regex>
@@ -34,8 +35,8 @@ static std::regex s_potenial_softlist_regex("\\w+(\\:\\w+)*");
// feature_list_item - constructor
//-------------------------------------------------
-feature_list_item::feature_list_item(const std::string &name, const std::string &value)
- : m_next(nullptr),
+feature_list_item::feature_list_item(const std::string &name, const std::string &value) :
+ m_next(nullptr),
m_name(name),
m_value(value)
{
@@ -46,8 +47,8 @@ feature_list_item::feature_list_item(const std::string &name, const std::string
// feature_list_item - constructor
//-------------------------------------------------
-feature_list_item::feature_list_item(std::string &&name, std::string &&value)
- : m_next(nullptr),
+feature_list_item::feature_list_item(std::string &&name, std::string &&value) :
+ m_next(nullptr),
m_name(std::move(name)),
m_value(std::move(value))
{
@@ -62,11 +63,11 @@ feature_list_item::feature_list_item(std::string &&name, std::string &&value)
// software_part - constructor
//-------------------------------------------------
-software_part::software_part(software_info &info, std::string &&name, std::string &&interface)
- : m_next(nullptr),
- m_info(info),
- m_name(std::move(name)),
- m_interface(std::move(interface))
+software_part::software_part(software_info &info, std::string &&name, std::string &&interface) :
+ m_next(nullptr),
+ m_info(info),
+ m_name(std::move(name)),
+ m_interface(std::move(interface))
{
}
@@ -76,13 +77,13 @@ software_part::software_part(software_info &info, std::string &&name, std::strin
// feature, if specified
//-------------------------------------------------
-const char *software_part::feature(const std::string &feature_name) const
+const char *software_part::feature(const std::string &feature_name) const noexcept
{
// scan the feature list for an entry matching feature_name and return the value
auto iter = std::find_if(
- m_featurelist.begin(),
- m_featurelist.end(),
- [&feature_name](const feature_list_item &feature) { return feature.name() == feature_name; });
+ m_featurelist.begin(),
+ m_featurelist.end(),
+ [&feature_name] (const feature_list_item &feature) { return feature.name() == feature_name; });
return iter != m_featurelist.end()
? iter->value().c_str()
@@ -95,18 +96,25 @@ const char *software_part::feature(const std::string &feature_name) const
// an interface in the provided list
//-------------------------------------------------
-bool software_part::matches_interface(const char *interface_list) const
+bool software_part::matches_interface(const char *interface_list) const noexcept
{
// if we have no interface, then we match by default
if (m_interface.empty())
return true;
- // copy the comma-delimited interface list and ensure it ends with a final comma
- std::string interfaces = std::string(interface_list).append(",");
-
- // then add a comma to the end of our interface and return true if we find it in the list string
- std::string our_interface = std::string(m_interface).append(",");
- return (interfaces.find(our_interface) != -1);
+ // find our interface at the beginning of the list or immediately following a comma
+ while (true)
+ {
+ char const *const found(std::strstr(interface_list, m_interface.c_str()));
+ if (!found)
+ return false;
+ if (((found == interface_list) || (',' == found[-1])) && ((',' == found[m_interface.size()]) || !found[m_interface.size()]))
+ return true;
+ interface_list = std::strchr(interface_list, ',');
+ if (!interface_list)
+ return false;
+ ++interface_list;
+ }
}
@@ -118,10 +126,10 @@ bool software_part::matches_interface(const char *interface_list) const
// software_info - constructor
//-------------------------------------------------
-software_info::software_info(std::string &&name, std::string &&parent, const std::string &supported)
- : m_supported(SOFTWARE_SUPPORTED_YES),
- m_shortname(std::move(name)),
- m_parentname(std::move(parent))
+software_info::software_info(std::string &&name, std::string &&parent, const std::string &supported) :
+ m_supported(SOFTWARE_SUPPORTED_YES),
+ m_shortname(std::move(name)),
+ m_parentname(std::move(parent))
{
// handle the supported flag if provided
if (supported == "partial")
@@ -184,17 +192,17 @@ bool software_info::has_multiple_parts(const char *interface) const
// softlist_parser - constructor
//-------------------------------------------------
-softlist_parser::softlist_parser(util::core_file &file, const std::string &filename, std::string &description, std::list<software_info> &infolist, std::ostringstream &errors)
- : m_file(file),
- m_filename(filename),
- m_infolist(infolist),
- m_errors(errors),
- m_done(false),
- m_description(description),
- m_data_accum_expected(false),
- m_current_info(nullptr),
- m_current_part(nullptr),
- m_pos(POS_ROOT)
+softlist_parser::softlist_parser(util::core_file &file, const std::string &filename, std::string &description, std::list<software_info> &infolist, std::ostringstream &errors) :
+ m_file(file),
+ m_filename(filename),
+ m_infolist(infolist),
+ m_errors(errors),
+ m_done(false),
+ m_description(description),
+ m_data_accum_expected(false),
+ m_current_info(nullptr),
+ m_current_part(nullptr),
+ m_pos(POS_ROOT)
{
// create the parser
m_parser = XML_ParserCreate_MM(nullptr, nullptr, nullptr);
diff --git a/src/emu/softlist.h b/src/emu/softlist.h
index feab67448d3..5bc6705f9f6 100644
--- a/src/emu/softlist.h
+++ b/src/emu/softlist.h
@@ -49,9 +49,9 @@ public:
feature_list_item& operator=(feature_list_item &&) = delete;
// getters
- feature_list_item *next() const { return m_next; }
- const std::string &name() const { return m_name; }
- const std::string &value() const { return m_value; }
+ feature_list_item *next() const noexcept { return m_next; }
+ const std::string &name() const noexcept { return m_name; }
+ const std::string &value() const noexcept { return m_value; }
private:
// internal state
@@ -77,16 +77,16 @@ public:
software_part& operator=(software_part &&) = delete;
// getters
- software_part *next() const { return m_next; }
- software_info &info() const { return m_info; }
- const std::string &name() const { return m_name; }
- const std::string &interface() const { return m_interface; }
- const std::list<feature_list_item> &featurelist() const { return m_featurelist; }
- const std::vector<rom_entry> &romdata() const { return m_romdata; }
+ software_part *next() const noexcept { return m_next; }
+ software_info &info() const noexcept { return m_info; }
+ const std::string &name() const noexcept { return m_name; }
+ const std::string &interface() const noexcept { return m_interface; }
+ const std::list<feature_list_item> &featurelist() const noexcept { return m_featurelist; }
+ const std::vector<rom_entry> &romdata() const noexcept { return m_romdata; }
// helpers
- bool matches_interface(const char *interface) const;
- const char *feature(const std::string &feature_name) const;
+ bool matches_interface(const char *interface_list) const noexcept;
+ const char *feature(const std::string &feature_name) const noexcept;
private:
// internal state