mirror of
https://github.com/holub/mame
synced 2025-04-26 18:23:08 +03:00
Using std::string more pervasively in softlist.cpp
This commit is contained in:
parent
ab48d5d333
commit
8e169de1cd
@ -102,15 +102,12 @@ const device_type SOFTWARE_LIST = &device_creator<software_list_device>;
|
||||
// software_part - constructor
|
||||
//-------------------------------------------------
|
||||
|
||||
software_part::software_part(software_info &info, const char *name, const char *interface)
|
||||
software_part::software_part(software_info &info, const std::string &name, const std::string &interface)
|
||||
: m_next(nullptr),
|
||||
m_info(info),
|
||||
m_name(name),
|
||||
m_interface(interface)
|
||||
{
|
||||
// ensure strings we are passed are in the string pool
|
||||
assert(info.list().string_pool_contains(name));
|
||||
assert(info.list().string_pool_contains(interface));
|
||||
}
|
||||
|
||||
|
||||
@ -190,7 +187,7 @@ software_compatibility software_part::is_compatible(const software_list_device &
|
||||
bool software_part::matches_interface(const char *interface_list) const
|
||||
{
|
||||
// if we have no interface, then we match by default
|
||||
if (m_interface == nullptr)
|
||||
if (m_interface.empty())
|
||||
return true;
|
||||
|
||||
// copy the comma-delimited interface list and ensure it ends with a final comma
|
||||
@ -239,7 +236,7 @@ device_image_interface *software_part::find_mountable_image(const machine_config
|
||||
// software_info - constructor
|
||||
//-------------------------------------------------
|
||||
|
||||
software_info::software_info(software_list_device &list, const char *name, const char *parent, const char *supported)
|
||||
software_info::software_info(software_list_device &list, const std::string &name, const std::string &parent, const char *supported)
|
||||
: m_next(nullptr),
|
||||
m_list(list),
|
||||
m_supported(SOFTWARE_SUPPORTED_YES),
|
||||
@ -249,10 +246,6 @@ software_info::software_info(software_list_device &list, const char *name, const
|
||||
m_year(nullptr),
|
||||
m_publisher(nullptr)
|
||||
{
|
||||
// ensure strings we are passed are in the string pool
|
||||
assert(list.string_pool_contains(name));
|
||||
assert(list.string_pool_contains(parent));
|
||||
|
||||
// handle the supported flag if provided
|
||||
if (supported != nullptr)
|
||||
{
|
||||
@ -426,7 +419,6 @@ void software_list_device::release()
|
||||
m_description = nullptr;
|
||||
m_errors.clear();
|
||||
m_infolist.reset();
|
||||
m_stringpool.reset();
|
||||
}
|
||||
|
||||
|
||||
@ -801,10 +793,16 @@ void softlist_parser::add_rom_entry(const char *name, const char *hashdata, UINT
|
||||
if (elem._name != nullptr && strcmp(elem._name, name) == 0)
|
||||
parse_error("Duplicated dataarea %s in software %s", name, infoname());
|
||||
|
||||
// get our own copy of these strings (ideally rom_entry would use std::string)
|
||||
m_current_part->m_romdata_strings.emplace_back(name);
|
||||
name = m_current_part->m_romdata_strings.back().c_str();
|
||||
m_current_part->m_romdata_strings.emplace_back(hashdata);
|
||||
hashdata = m_current_part->m_romdata_strings.back().c_str();
|
||||
|
||||
// create the new entry and append it
|
||||
rom_entry entry;
|
||||
entry._name = m_list.add_string(name);
|
||||
entry._hashdata = m_list.add_string(hashdata);
|
||||
entry._name = name;
|
||||
entry._hashdata = hashdata;
|
||||
entry._offset = offset;
|
||||
entry._length = length;
|
||||
entry._flags = flags;
|
||||
@ -924,7 +922,7 @@ void softlist_parser::parse_root_start(const char *tagname, const char **attribu
|
||||
parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues);
|
||||
|
||||
if (attrvalues[1] != nullptr)
|
||||
m_list.m_description = m_list.add_string(attrvalues[1]);
|
||||
m_list.m_description = attrvalues[1];
|
||||
}
|
||||
else
|
||||
unknown_tag(tagname);
|
||||
@ -946,7 +944,7 @@ void softlist_parser::parse_main_start(const char *tagname, const char **attribu
|
||||
parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues);
|
||||
|
||||
if (attrvalues[0] != nullptr)
|
||||
m_current_info = &m_list.m_infolist.append(*global_alloc(software_info(m_list, m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1]), attrvalues[2])));
|
||||
m_current_info = &m_list.m_infolist.append(*global_alloc(software_info(m_list, attrvalues[0], attrvalues[1], attrvalues[2])));
|
||||
else
|
||||
parse_error("No name defined for item");
|
||||
}
|
||||
@ -989,7 +987,7 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu
|
||||
parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues);
|
||||
|
||||
if (attrvalues[0] != nullptr && attrvalues[1] != nullptr)
|
||||
m_current_info->m_other_info.append(*global_alloc(feature_list_item(m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1]))));
|
||||
m_current_info->m_other_info.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1])));
|
||||
else
|
||||
parse_error("Incomplete other_info definition");
|
||||
}
|
||||
@ -1002,7 +1000,7 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu
|
||||
parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues);
|
||||
|
||||
if (attrvalues[0] != nullptr && attrvalues[1] != nullptr)
|
||||
m_current_info->m_shared_info.append(*global_alloc(feature_list_item(m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1]))));
|
||||
m_current_info->m_shared_info.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1])));
|
||||
else
|
||||
parse_error("Incomplete sharedfeat definition");
|
||||
}
|
||||
@ -1015,7 +1013,7 @@ void softlist_parser::parse_soft_start(const char *tagname, const char **attribu
|
||||
parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues);
|
||||
|
||||
if (attrvalues[0] != nullptr && attrvalues[1] != nullptr && strcmp(attrvalues[0], "") != 0 && strcmp(attrvalues[1], "") != 0)
|
||||
m_current_part = &m_current_info->m_partdata.append(*global_alloc(software_part(*m_current_info, m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1]))));
|
||||
m_current_part = &m_current_info->m_partdata.append(*global_alloc(software_part(*m_current_info, attrvalues[0], attrvalues[1])));
|
||||
else
|
||||
parse_error("Incomplete part definition");
|
||||
}
|
||||
@ -1102,7 +1100,7 @@ void softlist_parser::parse_part_start(const char *tagname, const char **attribu
|
||||
parse_attributes(attributes, ARRAY_LENGTH(attrnames), attrnames, attrvalues);
|
||||
|
||||
if (attrvalues[0] != nullptr)
|
||||
m_current_part->m_featurelist.append(*global_alloc(feature_list_item(m_list.add_string(attrvalues[0]), m_list.add_string(attrvalues[1]))));
|
||||
m_current_part->m_featurelist.append(*global_alloc(feature_list_item(attrvalues[0], attrvalues[1])));
|
||||
else
|
||||
parse_error("Incomplete feature definition");
|
||||
}
|
||||
@ -1247,15 +1245,15 @@ void softlist_parser::parse_soft_end(const char *tagname)
|
||||
|
||||
// <description>
|
||||
if (strcmp(tagname, "description") == 0)
|
||||
m_current_info->m_longname = m_list.add_string(m_data_accum.c_str());
|
||||
m_current_info->m_longname = m_data_accum;
|
||||
|
||||
// <year>
|
||||
else if (strcmp(tagname, "year") == 0)
|
||||
m_current_info->m_year = m_list.add_string(m_data_accum.c_str());
|
||||
m_current_info->m_year = m_data_accum;
|
||||
|
||||
// <publisher>
|
||||
else if (strcmp(tagname, "publisher") == 0)
|
||||
m_current_info->m_publisher = m_list.add_string(m_data_accum.c_str());
|
||||
m_current_info->m_publisher = m_data_accum;
|
||||
|
||||
// </part>
|
||||
else if (strcmp(tagname, "part") == 0)
|
||||
|
@ -82,21 +82,21 @@ class feature_list_item
|
||||
|
||||
public:
|
||||
// construction/destruction
|
||||
feature_list_item(const char *name = nullptr, const char *value = nullptr)
|
||||
feature_list_item(const std::string &name, const std::string &value)
|
||||
: m_next(nullptr),
|
||||
m_name(name),
|
||||
m_value(value) { }
|
||||
|
||||
// getters
|
||||
feature_list_item *next() const { return m_next; }
|
||||
const char *name() const { return m_name; }
|
||||
const char *value() const { return m_value; }
|
||||
const char *name() const { return m_name.c_str(); }
|
||||
const char *value() const { return m_value.c_str(); }
|
||||
|
||||
private:
|
||||
// internal state
|
||||
feature_list_item * m_next;
|
||||
const char * m_name;
|
||||
const char * m_value;
|
||||
std::string m_name;
|
||||
std::string m_value;
|
||||
};
|
||||
|
||||
|
||||
@ -110,13 +110,13 @@ class software_part
|
||||
|
||||
public:
|
||||
// construction/destruction
|
||||
software_part(software_info &info, const char *name = nullptr, const char *interface = nullptr);
|
||||
software_part(software_info &info, const std::string &name, const std::string &interface);
|
||||
|
||||
// getters
|
||||
software_part *next() const { return m_next; }
|
||||
software_info &info() const { return m_info; }
|
||||
const char *name() const { return m_name; }
|
||||
const char *interface() const { return m_interface; }
|
||||
const char *name() const { return m_name.c_str(); }
|
||||
const char *interface() const { return m_interface.c_str(); }
|
||||
const simple_list<feature_list_item> &featurelist() const { return m_featurelist; }
|
||||
const rom_entry *romdata(unsigned int index = 0) const { return (index < m_romdata.size()) ? &m_romdata[index] : nullptr; }
|
||||
|
||||
@ -130,10 +130,11 @@ private:
|
||||
// internal state
|
||||
software_part * m_next;
|
||||
software_info & m_info;
|
||||
const char * m_name;
|
||||
const char * m_interface;
|
||||
std::string m_name;
|
||||
std::string m_interface;
|
||||
simple_list<feature_list_item> m_featurelist;
|
||||
std::vector<rom_entry> m_romdata;
|
||||
std::vector<std::string> m_romdata_strings;
|
||||
};
|
||||
|
||||
|
||||
@ -147,16 +148,16 @@ class software_info
|
||||
|
||||
public:
|
||||
// construction/destruction
|
||||
software_info(software_list_device &list, const char *name, const char *parent, const char *supported);
|
||||
software_info(software_list_device &list, const std::string &name, const std::string &parent, const char *supported);
|
||||
|
||||
// getters
|
||||
software_info *next() const { return m_next; }
|
||||
software_list_device &list() const { return m_list; }
|
||||
const char *shortname() const { return m_shortname; }
|
||||
const char *longname() const { return m_longname; }
|
||||
const char *parentname() const { return m_parentname; }
|
||||
const char *year() const { return m_year; }
|
||||
const char *publisher() const { return m_publisher; }
|
||||
const char *shortname() const { return m_shortname.c_str(); }
|
||||
const char *longname() const { return m_longname.c_str(); }
|
||||
const char *parentname() const { return m_parentname.c_str(); }
|
||||
const char *year() const { return m_year.c_str(); }
|
||||
const char *publisher() const { return m_publisher.c_str(); }
|
||||
const simple_list<feature_list_item> &other_info() const { return m_other_info; }
|
||||
const simple_list<feature_list_item> &shared_info() const { return m_shared_info; }
|
||||
UINT32 supported() const { return m_supported; }
|
||||
@ -172,11 +173,11 @@ private:
|
||||
software_info * m_next;
|
||||
software_list_device & m_list;
|
||||
UINT32 m_supported;
|
||||
const char * m_shortname;
|
||||
const char * m_longname;
|
||||
const char * m_parentname;
|
||||
const char * m_year; // Copyright year on title screen, actual release dates can be tracked in external resources
|
||||
const char * m_publisher;
|
||||
std::string m_shortname;
|
||||
std::string m_longname;
|
||||
std::string m_parentname;
|
||||
std::string m_year; // Copyright year on title screen, actual release dates can be tracked in external resources
|
||||
std::string m_publisher;
|
||||
simple_list<feature_list_item> m_other_info; // Here we store info like developer, serial #, etc. which belong to the software entry as a whole
|
||||
simple_list<feature_list_item> m_shared_info; // Here we store info like TV standard compatibility, or add-on requirements, etc. which get inherited
|
||||
// by each part of this software entry (after loading these are stored in partdata->featurelist)
|
||||
@ -206,7 +207,7 @@ public:
|
||||
const char *filename() { return m_file.filename(); }
|
||||
|
||||
// getters that may trigger a parse
|
||||
const char *description() { if (!m_parsed) parse(); return m_description; }
|
||||
const char *description() { if (!m_parsed) parse(); return m_description.c_str(); }
|
||||
bool valid() { if (!m_parsed) parse(); return m_infolist.count() > 0; }
|
||||
const char *errors_string() { if (!m_parsed) parse(); return m_errors.c_str(); }
|
||||
const simple_list<software_info> &get_info() { if (!m_parsed) parse(); return m_infolist; }
|
||||
@ -216,10 +217,6 @@ public:
|
||||
void find_approx_matches(const char *name, int matches, const software_info **list, const char *interface);
|
||||
void release();
|
||||
|
||||
// string pool helpers
|
||||
const char *add_string(const char *string) { return m_stringpool.add(string); }
|
||||
bool string_pool_contains(const char *string) { return m_stringpool.contains(string); }
|
||||
|
||||
// static helpers
|
||||
static software_list_device *find_by_name(const machine_config &mconfig, const char *name);
|
||||
static void display_matches(const machine_config &config, const char *interface, const char *name);
|
||||
@ -241,10 +238,9 @@ protected:
|
||||
// internal state
|
||||
bool m_parsed;
|
||||
emu_file m_file;
|
||||
const char * m_description;
|
||||
std::string m_description;
|
||||
std::string m_errors;
|
||||
simple_list<software_info> m_infolist;
|
||||
const_string_pool m_stringpool;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user