mirror of
https://github.com/holub/mame
synced 2025-10-09 09:44:40 +03:00
tagged_list to unordered_map for slots (nw)
This commit is contained in:
parent
62805f7cac
commit
a07b82ac11
@ -36,7 +36,7 @@ void device_slot_interface::static_option_reset(device_t &device)
|
|||||||
{
|
{
|
||||||
device_slot_interface &intf = dynamic_cast<device_slot_interface &>(device);
|
device_slot_interface &intf = dynamic_cast<device_slot_interface &>(device);
|
||||||
|
|
||||||
intf.m_options.reset();
|
intf.m_options.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void device_slot_interface::static_option_add(device_t &device, const char *name, const device_type &devtype)
|
void device_slot_interface::static_option_add(device_t &device, const char *name, const device_type &devtype)
|
||||||
@ -47,7 +47,7 @@ void device_slot_interface::static_option_add(device_t &device, const char *name
|
|||||||
if (option != nullptr)
|
if (option != nullptr)
|
||||||
throw emu_fatalerror("slot '%s' duplicate option '%s\n", device.tag(), name);
|
throw emu_fatalerror("slot '%s' duplicate option '%s\n", device.tag(), name);
|
||||||
|
|
||||||
intf.m_options.append(name, *global_alloc(device_slot_option(name, devtype)));
|
intf.m_options.insert(std::make_pair(name, std::make_unique<device_slot_option>(name, devtype)));
|
||||||
}
|
}
|
||||||
|
|
||||||
device_slot_option *device_slot_interface::static_option(device_t &device, const char *name)
|
device_slot_option *device_slot_interface::static_option(device_t &device, const char *name)
|
||||||
|
@ -114,15 +114,15 @@ public:
|
|||||||
static void static_set_option_clock(device_t &device, const char *option, UINT32 default_clock) { static_option(device, option)->m_clock = default_clock; }
|
static void static_set_option_clock(device_t &device, const char *option, UINT32 default_clock) { static_option(device, option)->m_clock = default_clock; }
|
||||||
bool fixed() const { return m_fixed; }
|
bool fixed() const { return m_fixed; }
|
||||||
const char *default_option() const { return m_default_option; }
|
const char *default_option() const { return m_default_option; }
|
||||||
const tagged_list<device_slot_option> &option_list() const { return m_options; }
|
const std::unordered_map<std::string, std::unique_ptr<device_slot_option>> &option_list() const { return m_options; }
|
||||||
device_slot_option *option(const char *name) const { if (name) return m_options.find(name); return nullptr; }
|
device_slot_option *option(const char *name) const { if (name) { auto search = m_options.find(name); if (search != m_options.end()) return search->second.get(); else return nullptr; } else return nullptr; }
|
||||||
virtual std::string get_default_card_software() { return std::string(); }
|
virtual std::string get_default_card_software() { return std::string(); }
|
||||||
device_t *get_card_device();
|
device_t *get_card_device();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// internal state
|
// internal state
|
||||||
static device_slot_option *static_option(device_t &device, const char *option);
|
static device_slot_option *static_option(device_t &device, const char *option);
|
||||||
tagged_list<device_slot_option> m_options;
|
std::unordered_map<std::string,std::unique_ptr<device_slot_option>> m_options;
|
||||||
const char *m_default_option;
|
const char *m_default_option;
|
||||||
bool m_fixed;
|
bool m_fixed;
|
||||||
};
|
};
|
||||||
|
@ -570,11 +570,11 @@ void render_load_jpeg(bitmap_argb32 &bitmap, emu_file &file, const char *dirname
|
|||||||
|
|
||||||
// allocates a buffer for the image
|
// allocates a buffer for the image
|
||||||
UINT32 jpg_size = file.size();
|
UINT32 jpg_size = file.size();
|
||||||
unsigned char *jpg_buffer = global_alloc_array(unsigned char, jpg_size);
|
std::unique_ptr<unsigned char[]> jpg_buffer = std::make_unique<unsigned char[]>(jpg_size);
|
||||||
|
|
||||||
// read data from the file and set them in the buffer
|
// read data from the file and set them in the buffer
|
||||||
file.read(jpg_buffer, jpg_size);
|
file.read(jpg_buffer.get(), jpg_size);
|
||||||
jpeg_mem_src(&cinfo, jpg_buffer, jpg_size);
|
jpeg_mem_src(&cinfo, jpg_buffer.get(), jpg_size);
|
||||||
|
|
||||||
// read JPEG header and start decompression
|
// read JPEG header and start decompression
|
||||||
jpeg_read_header(&cinfo, TRUE);
|
jpeg_read_header(&cinfo, TRUE);
|
||||||
@ -617,7 +617,6 @@ void render_load_jpeg(bitmap_argb32 &bitmap, emu_file &file, const char *dirname
|
|||||||
file.close();
|
file.close();
|
||||||
free(buffer[0]);
|
free(buffer[0]);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
global_free_array(jpg_buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -971,11 +971,11 @@ void validity_checker::validate_devices()
|
|||||||
std::unordered_set<std::string> slot_device_map;
|
std::unordered_set<std::string> slot_device_map;
|
||||||
for (const device_slot_interface &slot : slot_interface_iterator(m_current_config->root_device()))
|
for (const device_slot_interface &slot : slot_interface_iterator(m_current_config->root_device()))
|
||||||
{
|
{
|
||||||
for (const device_slot_option &option : slot.option_list())
|
for (auto &option : slot.option_list())
|
||||||
{
|
{
|
||||||
std::string temptag("_");
|
std::string temptag("_");
|
||||||
temptag.append(option.name());
|
temptag.append(option.second->name());
|
||||||
device_t *dev = const_cast<machine_config &>(*m_current_config).device_add(&m_current_config->root_device(), temptag.c_str(), option.devtype(), 0);
|
device_t *dev = const_cast<machine_config &>(*m_current_config).device_add(&m_current_config->root_device(), temptag.c_str(), option.second->devtype(), 0);
|
||||||
|
|
||||||
// notify this device and all its subdevices that they are now configured
|
// notify this device and all its subdevices that they are now configured
|
||||||
for (device_t &device : device_iterator(*dev))
|
for (device_t &device : device_iterator(*dev))
|
||||||
|
@ -721,16 +721,16 @@ void cli_frontend::listslots(const char *gamename)
|
|||||||
bool first_option = true;
|
bool first_option = true;
|
||||||
|
|
||||||
// get the options and print them
|
// get the options and print them
|
||||||
for (const device_slot_option &option : slot.option_list())
|
for (auto &option : slot.option_list())
|
||||||
{
|
{
|
||||||
if (option.selectable())
|
if (option.second->selectable())
|
||||||
{
|
{
|
||||||
device_t *dev = (*option.devtype())(drivlist.config(), "dummy", &drivlist.config().root_device(), 0);
|
device_t *dev = (*option.second->devtype())(drivlist.config(), "dummy", &drivlist.config().root_device(), 0);
|
||||||
dev->config_complete();
|
dev->config_complete();
|
||||||
if (first_option) {
|
if (first_option) {
|
||||||
printf("%-15s %s\n", option.name(),dev->name());
|
printf("%-15s %s\n", option.second->name(),dev->name());
|
||||||
} else {
|
} else {
|
||||||
printf("%-23s %-15s %s\n", "",option.name(),dev->name());
|
printf("%-23s %-15s %s\n", "", option.second->name(),dev->name());
|
||||||
}
|
}
|
||||||
global_free(dev);
|
global_free(dev);
|
||||||
|
|
||||||
@ -929,11 +929,11 @@ void cli_frontend::verifyroms(const char *gamename)
|
|||||||
|
|
||||||
for (const device_slot_interface &slot : slot_interface_iterator(config.root_device()))
|
for (const device_slot_interface &slot : slot_interface_iterator(config.root_device()))
|
||||||
{
|
{
|
||||||
for (const device_slot_option &option : slot.option_list())
|
for (auto &option : slot.option_list())
|
||||||
{
|
{
|
||||||
std::string temptag("_");
|
std::string temptag("_");
|
||||||
temptag.append(option.name());
|
temptag.append(option.second->name());
|
||||||
device_t *dev = const_cast<machine_config &>(config).device_add(&config.root_device(), temptag.c_str(), option.devtype(), 0);
|
device_t *dev = const_cast<machine_config &>(config).device_add(&config.root_device(), temptag.c_str(), option.second->devtype(), 0);
|
||||||
|
|
||||||
// notify this device and all its subdevices that they are now configured
|
// notify this device and all its subdevices that they are now configured
|
||||||
for (device_t &device : device_iterator(*dev))
|
for (device_t &device : device_iterator(*dev))
|
||||||
|
@ -438,11 +438,11 @@ void info_xml_creator::output_devices()
|
|||||||
// then, run through slot devices
|
// then, run through slot devices
|
||||||
for (const device_slot_interface &slot : slot_interface_iterator(m_drivlist.config().root_device()))
|
for (const device_slot_interface &slot : slot_interface_iterator(m_drivlist.config().root_device()))
|
||||||
{
|
{
|
||||||
for (const device_slot_option &option : slot.option_list())
|
for (auto &option : slot.option_list())
|
||||||
{
|
{
|
||||||
std::string temptag("_");
|
std::string temptag("_");
|
||||||
temptag.append(option.name());
|
temptag.append(option.second->name());
|
||||||
device_t *dev = const_cast<machine_config &>(m_drivlist.config()).device_add(&m_drivlist.config().root_device(), temptag.c_str(), option.devtype(), 0);
|
device_t *dev = const_cast<machine_config &>(m_drivlist.config()).device_add(&m_drivlist.config().root_device(), temptag.c_str(), option.second->devtype(), 0);
|
||||||
|
|
||||||
// notify this device and all its subdevices that they are now configured
|
// notify this device and all its subdevices that they are now configured
|
||||||
for (device_t &device : device_iterator(*dev))
|
for (device_t &device : device_iterator(*dev))
|
||||||
@ -1528,18 +1528,18 @@ void info_xml_creator::output_slots(device_t &device, const char *root_tag)
|
|||||||
fprintf(m_output, " interface=\"%s\"", xml_normalize_string(slot.slot_interface()));
|
fprintf(m_output, " interface=\"%s\"", xml_normalize_string(slot.slot_interface()));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (const device_slot_option &option : slot.option_list())
|
for (auto &option : slot.option_list())
|
||||||
{
|
{
|
||||||
if (option.selectable())
|
if (option.second->selectable())
|
||||||
{
|
{
|
||||||
device_t *dev = const_cast<machine_config &>(m_drivlist.config()).device_add(&m_drivlist.config().root_device(), "dummy", option.devtype(), 0);
|
device_t *dev = const_cast<machine_config &>(m_drivlist.config()).device_add(&m_drivlist.config().root_device(), "dummy", option.second->devtype(), 0);
|
||||||
if (!dev->configured())
|
if (!dev->configured())
|
||||||
dev->config_complete();
|
dev->config_complete();
|
||||||
|
|
||||||
fprintf(m_output, "\t\t\t<slotoption");
|
fprintf(m_output, "\t\t\t<slotoption");
|
||||||
fprintf(m_output, " name=\"%s\"", xml_normalize_string(option.name()));
|
fprintf(m_output, " name=\"%s\"", xml_normalize_string(option.second->name()));
|
||||||
fprintf(m_output, " devname=\"%s\"", xml_normalize_string(dev->shortname()));
|
fprintf(m_output, " devname=\"%s\"", xml_normalize_string(dev->shortname()));
|
||||||
if (slot.default_option() != nullptr && strcmp(slot.default_option(),option.name())==0)
|
if (slot.default_option() != nullptr && strcmp(slot.default_option(), option.second->name())==0)
|
||||||
fprintf(m_output, " default=\"yes\"");
|
fprintf(m_output, " default=\"yes\"");
|
||||||
fprintf(m_output, "/>\n");
|
fprintf(m_output, "/>\n");
|
||||||
const_cast<machine_config &>(m_drivlist.config()).device_remove(&m_drivlist.config().root_device(), "dummy");
|
const_cast<machine_config &>(m_drivlist.config()).device_remove(&m_drivlist.config().root_device(), "dummy");
|
||||||
|
@ -49,12 +49,12 @@ int menu_slot_devices::slot_get_current_index(device_slot_interface &slot)
|
|||||||
if (current != nullptr)
|
if (current != nullptr)
|
||||||
{
|
{
|
||||||
int val = 0;
|
int val = 0;
|
||||||
for (const device_slot_option &option : slot.option_list())
|
for (auto &option : slot.option_list())
|
||||||
{
|
{
|
||||||
if (&option == current)
|
if (option.second.get() == current)
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
if (option.selectable())
|
if (option.second->selectable())
|
||||||
val++;
|
val++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,8 +68,8 @@ int menu_slot_devices::slot_get_current_index(device_slot_interface &slot)
|
|||||||
int menu_slot_devices::slot_get_length(device_slot_interface &slot)
|
int menu_slot_devices::slot_get_length(device_slot_interface &slot)
|
||||||
{
|
{
|
||||||
int val = 0;
|
int val = 0;
|
||||||
for (const device_slot_option &option : slot.option_list())
|
for (auto &option : slot.option_list())
|
||||||
if (option.selectable())
|
if (option.second->selectable())
|
||||||
val++;
|
val++;
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
@ -117,12 +117,12 @@ const char *menu_slot_devices::slot_get_option(device_slot_interface &slot, int
|
|||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
{
|
{
|
||||||
int val = 0;
|
int val = 0;
|
||||||
for (const device_slot_option &option : slot.option_list())
|
for (auto &option : slot.option_list())
|
||||||
{
|
{
|
||||||
if (val == index)
|
if (val == index)
|
||||||
return option.name();
|
return option.second->name();
|
||||||
|
|
||||||
if (option.selectable())
|
if (option.second->selectable())
|
||||||
val++;
|
val++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user