diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/bus/ti99x/gromport.cpp | 77 | ||||
-rw-r--r-- | src/devices/bus/ti99x/gromport.h | 4 | ||||
-rw-r--r-- | src/devices/machine/laserdsc.cpp | 30 | ||||
-rw-r--r-- | src/emu/bookkeeping.cpp | 22 | ||||
-rw-r--r-- | src/emu/config.cpp | 38 | ||||
-rw-r--r-- | src/emu/crsshair.cpp | 28 | ||||
-rw-r--r-- | src/emu/debug/debugcpu.cpp | 60 | ||||
-rw-r--r-- | src/emu/debug/debugcpu.h | 2 | ||||
-rw-r--r-- | src/emu/image.cpp | 14 | ||||
-rw-r--r-- | src/emu/ioport.cpp | 82 | ||||
-rw-r--r-- | src/emu/ioport.h | 6 | ||||
-rw-r--r-- | src/emu/network.cpp | 18 | ||||
-rw-r--r-- | src/emu/render.cpp | 96 | ||||
-rw-r--r-- | src/emu/render.h | 44 | ||||
-rw-r--r-- | src/emu/rendlay.cpp | 124 | ||||
-rw-r--r-- | src/emu/sound.cpp | 14 | ||||
-rw-r--r-- | src/frontend/mame/cheat.cpp | 90 | ||||
-rw-r--r-- | src/frontend/mame/cheat.h | 10 | ||||
-rw-r--r-- | src/frontend/mame/mame.cpp | 8 | ||||
-rw-r--r-- | src/lib/util/xmlfile.cpp | 879 | ||||
-rw-r--r-- | src/lib/util/xmlfile.h | 202 |
21 files changed, 895 insertions, 953 deletions
diff --git a/src/devices/bus/ti99x/gromport.cpp b/src/devices/bus/ti99x/gromport.cpp index 846efab7608..eb655be167e 100644 --- a/src/devices/bus/ti99x/gromport.cpp +++ b/src/devices/bus/ti99x/gromport.cpp @@ -2615,7 +2615,7 @@ int rpk_reader::find_file(util::archive_file &zip, const char *filename, uint32_ /* Load a rom resource and put it in a pcb socket instance. */ -std::unique_ptr<rpk_socket> rpk_reader::load_rom_resource(util::archive_file &zip, xml_data_node* rom_resource_node, const char* socketname) +std::unique_ptr<rpk_socket> rpk_reader::load_rom_resource(util::archive_file &zip, xml_data_node const* rom_resource_node, const char* socketname) { const char* file; const char* crcstr; @@ -2627,13 +2627,13 @@ std::unique_ptr<rpk_socket> rpk_reader::load_rom_resource(util::archive_file &zi int header; // find the file attribute (required) - file = xml_get_attribute_string(rom_resource_node, "file", nullptr); + file = rom_resource_node->get_attribute_string("file", nullptr); if (file == nullptr) throw rpk_exception(RPK_INVALID_LAYOUT, "<rom> must have a 'file' attribute"); if (TRACE_RPK) printf("gromport/RPK: Loading ROM contents for socket '%s' from file %s\n", socketname, file); // check for crc - crcstr = xml_get_attribute_string(rom_resource_node, "crc", nullptr); + crcstr = rom_resource_node->get_attribute_string("crc", nullptr); if (crcstr==nullptr) { // no CRC, just find the file in the RPK @@ -2661,7 +2661,7 @@ std::unique_ptr<rpk_socket> rpk_reader::load_rom_resource(util::archive_file &zi } // check for sha1 - sha1 = xml_get_attribute_string(rom_resource_node, "sha1", nullptr); + sha1 = rom_resource_node->get_attribute_string("sha1", nullptr); if (sha1 != nullptr) { util::hash_collection actual_hashes; @@ -2680,7 +2680,7 @@ std::unique_ptr<rpk_socket> rpk_reader::load_rom_resource(util::archive_file &zi /* Load a ram resource and put it in a pcb socket instance. */ -std::unique_ptr<rpk_socket> rpk_reader::load_ram_resource(emu_options &options, xml_data_node* ram_resource_node, const char* socketname, const char* system_name) +std::unique_ptr<rpk_socket> rpk_reader::load_ram_resource(emu_options &options, xml_data_node const* ram_resource_node, const char* socketname, const char* system_name) { const char* length_string; const char* ram_type; @@ -2690,7 +2690,7 @@ std::unique_ptr<rpk_socket> rpk_reader::load_ram_resource(emu_options &options, uint8_t* contents; // find the length attribute - length_string = xml_get_attribute_string(ram_resource_node, "length", nullptr); + length_string = ram_resource_node->get_attribute_string("length", nullptr); if (length_string == nullptr) throw rpk_exception(RPK_MISSING_RAM_LENGTH); // parse it @@ -2725,13 +2725,13 @@ std::unique_ptr<rpk_socket> rpk_reader::load_ram_resource(emu_options &options, // That's it for pure RAM. Now check whether the RAM is "persistent", i.e. NVRAM. // In that case we must load it from the NVRAM directory. // The file name is given in the RPK file; the subdirectory is the system name. - ram_type = xml_get_attribute_string(ram_resource_node, "type", nullptr); + ram_type = ram_resource_node->get_attribute_string("type", nullptr); if (ram_type != nullptr) { if (strcmp(ram_type, "persistent")==0) { // Get the file name (required if persistent) - ram_filename = xml_get_attribute_string(ram_resource_node, "file", nullptr); + ram_filename = ram_resource_node->get_attribute_string("file", nullptr); if (ram_filename==nullptr) { global_free_array(contents); @@ -2771,21 +2771,10 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy { util::archive_file::error ziperr; - const char *pcb_type; - const char *id; - const char *uses_name; - const char *resource_name; - util::archive_file::ptr zipfile; std::vector<char> layout_text; xml_data_node *layout_xml = nullptr; - xml_data_node *romset_node; - xml_data_node *configuration_node; - xml_data_node *resources_node; - xml_data_node *resource_node; - xml_data_node *socket_node; - xml_data_node *pcb_node; int i; @@ -2814,30 +2803,30 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy layout_text[zipfile->current_uncompressed_length()] = '\0'; // Null-terminate /* parse the layout text */ - layout_xml = xml_string_read(&layout_text[0], nullptr); - if (layout_xml == nullptr) throw rpk_exception(RPK_XML_ERROR); + layout_xml = xml_data_node::string_read(&layout_text[0], nullptr); + if (!layout_xml) throw rpk_exception(RPK_XML_ERROR); // Now we work within the XML tree // romset is the root node - romset_node = xml_get_sibling(layout_xml->child, "romset"); - if (romset_node==nullptr) throw rpk_exception(RPK_INVALID_LAYOUT, "document element must be <romset>"); + xml_data_node const *const romset_node = layout_xml->get_child("romset"); + if (!romset_node) throw rpk_exception(RPK_INVALID_LAYOUT, "document element must be <romset>"); // resources is a child of romset - resources_node = xml_get_sibling(romset_node->child, "resources"); - if (resources_node==nullptr) throw rpk_exception(RPK_INVALID_LAYOUT, "<romset> must have a <resources> child"); + xml_data_node const *const resources_node = romset_node->get_child("resources"); + if (!resources_node) throw rpk_exception(RPK_INVALID_LAYOUT, "<romset> must have a <resources> child"); // configuration is a child of romset; we're actually interested in ... - configuration_node = xml_get_sibling(romset_node->child, "configuration"); - if (configuration_node==nullptr) throw rpk_exception(RPK_INVALID_LAYOUT, "<romset> must have a <configuration> child"); + xml_data_node const *const configuration_node = romset_node->get_child("configuration"); + if (!configuration_node) throw rpk_exception(RPK_INVALID_LAYOUT, "<romset> must have a <configuration> child"); // ... pcb, which is a child of configuration - pcb_node = xml_get_sibling(configuration_node->child, "pcb"); - if (pcb_node==nullptr) throw rpk_exception(RPK_INVALID_LAYOUT, "<configuration> must have a <pcb> child"); + xml_data_node const *const pcb_node = configuration_node->get_child("pcb"); + if (!pcb_node) throw rpk_exception(RPK_INVALID_LAYOUT, "<configuration> must have a <pcb> child"); // We'll try to find the PCB type on the provided type list. - pcb_type = xml_get_attribute_string(pcb_node, "type", nullptr); - if (pcb_type==nullptr) throw rpk_exception(RPK_INVALID_LAYOUT, "<pcb> must have a 'type' attribute"); + char const *const pcb_type = pcb_node->get_attribute_string("type", nullptr); + if (!pcb_type) throw rpk_exception(RPK_INVALID_LAYOUT, "<pcb> must have a 'type' attribute"); if (TRACE_RPK) printf("gromport/RPK: Cartridge says it has PCB type '%s'\n", pcb_type); i=0; @@ -2854,31 +2843,31 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy if (m_types[i].id==0) throw rpk_exception(RPK_UNKNOWN_PCB_TYPE); // Find the sockets and load their respective resource - for (socket_node = pcb_node->child; socket_node != nullptr; socket_node = socket_node->next) + for (xml_data_node const *socket_node = pcb_node->get_first_child(); socket_node != nullptr; socket_node = socket_node->get_next_sibling()) { - if (strcmp(socket_node->name, "socket")!=0) throw rpk_exception(RPK_INVALID_LAYOUT, "<pcb> element has only <socket> children"); - id = xml_get_attribute_string(socket_node, "id", nullptr); - if (id == nullptr) throw rpk_exception(RPK_INVALID_LAYOUT, "<socket> must have an 'id' attribute"); - uses_name = xml_get_attribute_string(socket_node, "uses", nullptr); - if (uses_name == nullptr) throw rpk_exception(RPK_INVALID_LAYOUT, "<socket> must have a 'uses' attribute"); + if (strcmp(socket_node->get_name(), "socket")!=0) throw rpk_exception(RPK_INVALID_LAYOUT, "<pcb> element has only <socket> children"); + char const *const id = socket_node->get_attribute_string("id", nullptr); + if (!id) throw rpk_exception(RPK_INVALID_LAYOUT, "<socket> must have an 'id' attribute"); + char const *const uses_name = socket_node->get_attribute_string("uses", nullptr); + if (!uses_name) throw rpk_exception(RPK_INVALID_LAYOUT, "<socket> must have a 'uses' attribute"); bool found = false; // Locate the resource node - for (resource_node = resources_node->child; resource_node != nullptr; resource_node = resource_node->next) + for (xml_data_node const *resource_node = resources_node->get_first_child(); resource_node != nullptr; resource_node = resource_node->get_next_sibling()) { - resource_name = xml_get_attribute_string(resource_node, "id", nullptr); - if (resource_name == nullptr) throw rpk_exception(RPK_INVALID_LAYOUT, "resource node must have an 'id' attribute"); + char const *const resource_name = resource_node->get_attribute_string("id", nullptr); + if (!resource_name) throw rpk_exception(RPK_INVALID_LAYOUT, "resource node must have an 'id' attribute"); if (strcmp(resource_name, uses_name)==0) { // found it - if (strcmp(resource_node->name, "rom")==0) + if (strcmp(resource_node->get_name(), "rom")==0) { newrpk->add_socket(id, load_rom_resource(*zipfile, resource_node, id)); } else { - if (strcmp(resource_node->name, "ram")==0) + if (strcmp(resource_node->get_name(), "ram")==0) { newrpk->add_socket(id, load_ram_resource(options, resource_node, id, system_name)); } @@ -2893,13 +2882,13 @@ rpk* rpk_reader::open(emu_options &options, const char *filename, const char *sy catch (rpk_exception &) { newrpk->close(); - if (layout_xml != nullptr) xml_file_free(layout_xml); + if (layout_xml) layout_xml->file_free(); // rethrow the exception throw; } - if (layout_xml != nullptr) xml_file_free(layout_xml); + if (layout_xml) layout_xml->file_free(); return newrpk; } diff --git a/src/devices/bus/ti99x/gromport.h b/src/devices/bus/ti99x/gromport.h index 9e0765fd826..fc7546bd804 100644 --- a/src/devices/bus/ti99x/gromport.h +++ b/src/devices/bus/ti99x/gromport.h @@ -516,8 +516,8 @@ public: private: int find_file(util::archive_file &zip, const char *filename, uint32_t crc); - std::unique_ptr<rpk_socket> load_rom_resource(util::archive_file &zip, xml_data_node* rom_resource_node, const char* socketname); - std::unique_ptr<rpk_socket> load_ram_resource(emu_options &options, xml_data_node* ram_resource_node, const char* socketname, const char* system_name); + std::unique_ptr<rpk_socket> load_rom_resource(util::archive_file &zip, xml_data_node const* rom_resource_node, const char* socketname); + std::unique_ptr<rpk_socket> load_ram_resource(emu_options &options, xml_data_node const* ram_resource_node, const char* socketname, const char* system_name); const pcb_type* m_types; }; diff --git a/src/devices/machine/laserdsc.cpp b/src/devices/machine/laserdsc.cpp index badbd395354..824779c4231 100644 --- a/src/devices/machine/laserdsc.cpp +++ b/src/devices/machine/laserdsc.cpp @@ -1153,20 +1153,20 @@ void laserdisc_device::config_load(config_type cfg_type, xml_data_node *parentno return; // iterate over overlay nodes - for (xml_data_node *ldnode = xml_get_sibling(parentnode->child, "device"); ldnode != nullptr; ldnode = xml_get_sibling(ldnode->next, "device")) + for (xml_data_node const *ldnode = parentnode->get_child("device"); ldnode != nullptr; ldnode = ldnode->get_next_sibling("device")) { - const char *devtag = xml_get_attribute_string(ldnode, "tag", ""); + const char *devtag = ldnode->get_attribute_string("tag", ""); if (strcmp(devtag, tag()) == 0) { // handle the overlay node - xml_data_node *overnode = xml_get_sibling(ldnode->child, "overlay"); + xml_data_node const *const overnode = ldnode->get_child("overlay"); if (overnode != nullptr) { // fetch positioning controls - m_overposx = xml_get_attribute_float(overnode, "hoffset", m_overposx); - m_overscalex = xml_get_attribute_float(overnode, "hstretch", m_overscalex); - m_overposy = xml_get_attribute_float(overnode, "voffset", m_overposy); - m_overscaley = xml_get_attribute_float(overnode, "vstretch", m_overscaley); + m_overposx = overnode->get_attribute_float("hoffset", m_overposx); + m_overscalex = overnode->get_attribute_float("hstretch", m_overscalex); + m_overposy = overnode->get_attribute_float("voffset", m_overposy); + m_overscaley = overnode->get_attribute_float("vstretch", m_overscaley); } } } @@ -1185,45 +1185,45 @@ void laserdisc_device::config_save(config_type cfg_type, xml_data_node *parentno return; // create a node - xml_data_node *ldnode = xml_add_child(parentnode, "device", nullptr); + xml_data_node *const ldnode = parentnode->add_child("device", nullptr); if (ldnode != nullptr) { // output the basics - xml_set_attribute(ldnode, "tag", tag()); + ldnode->set_attribute("tag", tag()); // add an overlay node - xml_data_node *overnode = xml_add_child(ldnode, "overlay", nullptr); + xml_data_node *const overnode = ldnode->add_child("overlay", nullptr); bool changed = false; if (overnode != nullptr) { // output the positioning controls if (m_overposx != m_orig_config.m_overposx) { - xml_set_attribute_float(overnode, "hoffset", m_overposx); + overnode->set_attribute_float("hoffset", m_overposx); changed = true; } if (m_overscalex != m_orig_config.m_overscalex) { - xml_set_attribute_float(overnode, "hstretch", m_overscalex); + overnode->set_attribute_float("hstretch", m_overscalex); changed = true; } if (m_overposy != m_orig_config.m_overposy) { - xml_set_attribute_float(overnode, "voffset", m_overposy); + overnode->set_attribute_float("voffset", m_overposy); changed = true; } if (m_overscaley != m_orig_config.m_overscaley) { - xml_set_attribute_float(overnode, "vstretch", m_overscaley); + overnode->set_attribute_float("vstretch", m_overscaley); changed = true; } } // if nothing changed, kill the node if (!changed) - xml_delete_node(ldnode); + ldnode->delete_node(); } } diff --git a/src/emu/bookkeeping.cpp b/src/emu/bookkeeping.cpp index 89b32c3972a..3c1cb519795 100644 --- a/src/emu/bookkeeping.cpp +++ b/src/emu/bookkeeping.cpp @@ -82,7 +82,7 @@ void bookkeeping_manager::increment_dispensed_tickets(int delta) void bookkeeping_manager::config_load(config_type cfg_type, xml_data_node *parentnode) { - xml_data_node *coinnode, *ticketnode; + xml_data_node const *coinnode, *ticketnode; /* on init, reset the counters */ if (cfg_type == config_type::CONFIG_TYPE_INIT) @@ -100,17 +100,17 @@ void bookkeeping_manager::config_load(config_type cfg_type, xml_data_node *paren return; /* iterate over coins nodes */ - for (coinnode = xml_get_sibling(parentnode->child, "coins"); coinnode; coinnode = xml_get_sibling(coinnode->next, "coins")) + for (coinnode = parentnode->get_child("coins"); coinnode; coinnode = coinnode->get_next_sibling("coins")) { - int index = xml_get_attribute_int(coinnode, "index", -1); + int index = coinnode->get_attribute_int("index", -1); if (index >= 0 && index < COIN_COUNTERS) - m_coin_count[index] = xml_get_attribute_int(coinnode, "number", 0); + m_coin_count[index] = coinnode->get_attribute_int("number", 0); } /* get the single tickets node */ - ticketnode = xml_get_sibling(parentnode->child, "tickets"); + ticketnode = parentnode->get_child("tickets"); if (ticketnode != nullptr) - m_dispensed_tickets = xml_get_attribute_int(ticketnode, "number", 0); + m_dispensed_tickets = ticketnode->get_attribute_int("number", 0); } @@ -131,20 +131,20 @@ void bookkeeping_manager::config_save(config_type cfg_type, xml_data_node *paren for (i = 0; i < COIN_COUNTERS; i++) if (m_coin_count[i] != 0) { - xml_data_node *coinnode = xml_add_child(parentnode, "coins", nullptr); + xml_data_node *coinnode = parentnode->add_child("coins", nullptr); if (coinnode != nullptr) { - xml_set_attribute_int(coinnode, "index", i); - xml_set_attribute_int(coinnode, "number", m_coin_count[i]); + coinnode->set_attribute_int("index", i); + coinnode->set_attribute_int("number", m_coin_count[i]); } } /* output tickets */ if (m_dispensed_tickets != 0) { - xml_data_node *tickets = xml_add_child(parentnode, "tickets", nullptr); + xml_data_node *tickets = parentnode->add_child("tickets", nullptr); if (tickets != nullptr) - xml_set_attribute_int(tickets, "number", m_dispensed_tickets); + tickets->set_attribute_int("number", m_dispensed_tickets); } } diff --git a/src/emu/config.cpp b/src/emu/config.cpp index 7402341ad32..8e3357adfd6 100644 --- a/src/emu/config.cpp +++ b/src/emu/config.cpp @@ -136,17 +136,17 @@ int configuration_manager::load_xml(emu_file &file, config_type which_type) int version, count; /* read the file */ - root = xml_file_read(file, nullptr); + root = xml_data_node::file_read(file, nullptr); if (!root) goto error; /* find the config node */ - confignode = xml_get_sibling(root->child, "mameconfig"); + confignode = root->get_child("mameconfig"); if (!confignode) goto error; /* validate the config data version */ - version = xml_get_attribute_int(confignode, "version", 0); + version = confignode->get_attribute_int("version", 0); if (version != CONFIG_VERSION) goto error; @@ -163,10 +163,10 @@ int configuration_manager::load_xml(emu_file &file, config_type which_type) /* loop over all system nodes in the file */ count = 0; - for (systemnode = xml_get_sibling(confignode->child, "system"); systemnode; systemnode = xml_get_sibling(systemnode->next, "system")) + for (systemnode = confignode->get_child("system"); systemnode; systemnode = systemnode->get_next_sibling("system")) { /* look up the name of the system here; skip if none */ - const char *name = xml_get_attribute_string(systemnode, "name", ""); + const char *name = systemnode->get_attribute_string("name", ""); /* based on the file type, determine whether we have a match */ switch (which_type) @@ -205,7 +205,7 @@ int configuration_manager::load_xml(emu_file &file, config_type which_type) /* loop over all registrants and call their load function */ for (auto type : m_typelist) - type.load(which_type, xml_get_sibling(systemnode->child, type.name.c_str())); + type.load(which_type, systemnode->get_child(type.name.c_str())); count++; } @@ -214,12 +214,12 @@ int configuration_manager::load_xml(emu_file &file, config_type which_type) goto error; /* free the parser */ - xml_file_free(root); + root->file_free(); return 1; error: if (root) - xml_file_free(root); + root->file_free(); return 0; } @@ -233,7 +233,7 @@ error: int configuration_manager::save_xml(emu_file &file, config_type which_type) { - xml_data_node *root = xml_file_create(); + xml_data_node *const root = xml_data_node::file_create(); xml_data_node *confignode, *systemnode; /* if we don't have a root, bail */ @@ -241,39 +241,39 @@ int configuration_manager::save_xml(emu_file &file, config_type which_type) return 0; /* create a config node */ - confignode = xml_add_child(root, "mameconfig", nullptr); + confignode = root->add_child("mameconfig", nullptr); if (!confignode) goto error; - xml_set_attribute_int(confignode, "version", CONFIG_VERSION); + confignode->set_attribute_int("version", CONFIG_VERSION); /* create a system node */ - systemnode = xml_add_child(confignode, "system", nullptr); + systemnode = confignode->add_child("system", nullptr); if (!systemnode) goto error; - xml_set_attribute(systemnode, "name", (which_type == config_type::CONFIG_TYPE_DEFAULT) ? "default" : machine().system().name); + systemnode->set_attribute("name", (which_type == config_type::CONFIG_TYPE_DEFAULT) ? "default" : machine().system().name); /* create the input node and write it out */ /* loop over all registrants and call their save function */ for (auto type : m_typelist) { - xml_data_node *curnode = xml_add_child(systemnode, type.name.c_str(), nullptr); + xml_data_node *curnode = systemnode->add_child(type.name.c_str(), nullptr); if (!curnode) goto error; type.save(which_type, curnode); /* if nothing was added, just nuke the node */ - if (!curnode->value && !curnode->child) - xml_delete_node(curnode); + if (!curnode->get_value() && !curnode->get_first_child()) + curnode->delete_node(); } /* flush the file */ - xml_file_write(root, file); + root->file_write(file); /* free and get out of here */ - xml_file_free(root); + root->file_free(); return 1; error: - xml_file_free(root); + root->file_free(); return 0; } diff --git a/src/emu/crsshair.cpp b/src/emu/crsshair.cpp index 9d2eae42762..9c2f2dbd996 100644 --- a/src/emu/crsshair.cpp +++ b/src/emu/crsshair.cpp @@ -385,7 +385,7 @@ void crosshair_manager::config_load(config_type cfg_type, xml_data_node *parentn { /* Note: crosshair_load() is only registered if croshairs are used */ - xml_data_node *crosshairnode; + xml_data_node const *crosshairnode; int auto_time; /* we only care about game files */ @@ -397,11 +397,11 @@ void crosshair_manager::config_load(config_type cfg_type, xml_data_node *parentn return; /* loop and get player crosshair info */ - for (crosshairnode = xml_get_sibling(parentnode->child, "crosshair"); crosshairnode; crosshairnode = xml_get_sibling(crosshairnode->next, "crosshair")) + for (crosshairnode = parentnode->get_child("crosshair"); crosshairnode; crosshairnode = crosshairnode->get_next_sibling("crosshair")) { int player, mode; - player = xml_get_attribute_int(crosshairnode, "player", -1); + player = crosshairnode->get_attribute_int("player", -1); // check to make sure we have a valid player if (player >= 0 && player < MAX_PLAYERS) @@ -411,7 +411,7 @@ void crosshair_manager::config_load(config_type cfg_type, xml_data_node *parentn if (crosshair.is_used()) { // get, check, and store visibility mode - mode = xml_get_attribute_int(crosshairnode, "mode", CROSSHAIR_VISIBILITY_DEFAULT); + mode = crosshairnode->get_attribute_int("mode", CROSSHAIR_VISIBILITY_DEFAULT); if (mode >= CROSSHAIR_VISIBILITY_OFF && mode <= CROSSHAIR_VISIBILITY_AUTO) { crosshair.set_mode((uint8_t)mode); @@ -421,16 +421,16 @@ void crosshair_manager::config_load(config_type cfg_type, xml_data_node *parentn } // get and store crosshair pic name - crosshair.set_bitmap_name(xml_get_attribute_string(crosshairnode, "pic", "")); + crosshair.set_bitmap_name(crosshairnode->get_attribute_string("pic", "")); } } } /* get, check, and store auto visibility time */ - crosshairnode = xml_get_sibling(parentnode->child, "autotime"); + crosshairnode = parentnode->get_child("autotime"); if (crosshairnode != nullptr) { - auto_time = xml_get_attribute_int(crosshairnode, "val", CROSSHAIR_VISIBILITY_AUTOTIME_DEFAULT); + auto_time = crosshairnode->get_attribute_int("val", CROSSHAIR_VISIBILITY_AUTOTIME_DEFAULT); if ((auto_time >= CROSSHAIR_VISIBILITY_AUTOTIME_MIN) && (auto_time <= CROSSHAIR_VISIBILITY_AUTOTIME_MAX)) m_auto_time = (uint8_t)auto_time; } @@ -460,30 +460,30 @@ void crosshair_manager::config_save(config_type cfg_type, xml_data_node *parentn if (crosshair.is_used()) { /* create a node */ - crosshairnode = xml_add_child(parentnode, "crosshair", nullptr); + crosshairnode = parentnode->add_child("crosshair", nullptr); if (crosshairnode != nullptr) { bool changed = false; - xml_set_attribute_int(crosshairnode, "player", player); + crosshairnode->set_attribute_int("player", player); if (crosshair.mode() != CROSSHAIR_VISIBILITY_DEFAULT) { - xml_set_attribute_int(crosshairnode, "mode", crosshair.mode()); + crosshairnode->set_attribute_int("mode", crosshair.mode()); changed = true; } // only save graphic name if not the default if (*crosshair.bitmap_name() != '\0') { - xml_set_attribute(crosshairnode, "pic", crosshair.bitmap_name()); + crosshairnode->set_attribute("pic", crosshair.bitmap_name()); changed = true; } /* if nothing changed, kill the node */ if (!changed) - xml_delete_node(crosshairnode); + crosshairnode->delete_node(); } } } @@ -492,10 +492,10 @@ void crosshair_manager::config_save(config_type cfg_type, xml_data_node *parentn if (m_auto_time != CROSSHAIR_VISIBILITY_AUTOTIME_DEFAULT) { /* create a node */ - crosshairnode = xml_add_child(parentnode, "autotime", nullptr); + crosshairnode = parentnode->add_child("autotime", nullptr); if (crosshairnode != nullptr) - xml_set_attribute_int(crosshairnode, "val", m_auto_time); + crosshairnode->set_attribute_int("val", m_auto_time); } } diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp index 90641019986..b8ef947b4f8 100644 --- a/src/emu/debug/debugcpu.cpp +++ b/src/emu/debug/debugcpu.cpp @@ -220,7 +220,7 @@ bool debugger_cpu::comment_save() bool comments_saved = false; // if we don't have a root, bail - xml_data_node *root = xml_file_create(); + xml_data_node *const root = xml_data_node::file_create(); if (root == nullptr) return false; @@ -228,16 +228,16 @@ bool debugger_cpu::comment_save() try { // create a comment node - xml_data_node *commentnode = xml_add_child(root, "mamecommentfile", nullptr); + xml_data_node *const commentnode = root->add_child("mamecommentfile", nullptr); if (commentnode == nullptr) throw emu_exception(); - xml_set_attribute_int(commentnode, "version", COMMENT_VERSION); + commentnode->set_attribute_int("version", COMMENT_VERSION); // create a system node - xml_data_node *systemnode = xml_add_child(commentnode, "system", nullptr); + xml_data_node *const systemnode = commentnode->add_child("system", nullptr); if (systemnode == nullptr) throw emu_exception(); - xml_set_attribute(systemnode, "name", m_machine.system().name); + systemnode->set_attribute("name", m_machine.system().name); // for each device bool found_comments = false; @@ -245,10 +245,10 @@ bool debugger_cpu::comment_save() if (device.debug() && device.debug()->comment_count() > 0) { // create a node for this device - xml_data_node *curnode = xml_add_child(systemnode, "cpu", nullptr); + xml_data_node *const curnode = systemnode->add_child("cpu", nullptr); if (curnode == nullptr) throw emu_exception(); - xml_set_attribute(curnode, "tag", device.tag()); + curnode->set_attribute("tag", device.tag()); // export the comments if (!device.debug()->comment_export(*curnode)) @@ -263,19 +263,19 @@ bool debugger_cpu::comment_save() osd_file::error filerr = file.open(m_machine.basename(), ".cmt"); if (filerr == osd_file::error::NONE) { - xml_file_write(root, file); + root->file_write(file); comments_saved = true; } } } catch (emu_exception &) { - xml_file_free(root); + root->file_free(); return false; } // free and get out of here - xml_file_free(root); + root->file_free(); return comments_saved; } @@ -295,7 +295,7 @@ bool debugger_cpu::comment_load(bool is_inline) return false; // wrap in a try/catch to handle errors - xml_data_node *root = xml_file_read(file, nullptr); + xml_data_node *const root = xml_data_node::file_read(file, nullptr); try { // read the file @@ -303,25 +303,25 @@ bool debugger_cpu::comment_load(bool is_inline) throw emu_exception(); // find the config node - xml_data_node *commentnode = xml_get_sibling(root->child, "mamecommentfile"); + xml_data_node const *const commentnode = root->get_child("mamecommentfile"); if (commentnode == nullptr) throw emu_exception(); // validate the config data version - int version = xml_get_attribute_int(commentnode, "version", 0); + int version = commentnode->get_attribute_int("version", 0); if (version != COMMENT_VERSION) throw emu_exception(); // check to make sure the file is applicable - xml_data_node *systemnode = xml_get_sibling(commentnode->child, "system"); - const char *name = xml_get_attribute_string(systemnode, "name", ""); + xml_data_node const *const systemnode = commentnode->get_child("system"); + const char *const name = systemnode->get_attribute_string("name", ""); if (strcmp(name, m_machine.system().name) != 0) throw emu_exception(); // iterate over devices - for (xml_data_node *cpunode = xml_get_sibling(systemnode->child, "cpu"); cpunode; cpunode = xml_get_sibling(cpunode->next, "cpu")) + for (xml_data_node const *cpunode = systemnode->get_child("cpu"); cpunode; cpunode = cpunode->get_next_sibling("cpu")) { - const char *cputag_name = xml_get_attribute_string(cpunode, "tag", ""); + const char *cputag_name = cpunode->get_attribute_string("tag", ""); device_t *device = m_machine.device(cputag_name); if (device != nullptr) { @@ -337,12 +337,12 @@ bool debugger_cpu::comment_load(bool is_inline) { // clean up in case of error if (root != nullptr) - xml_file_free(root); + root->file_free(); return false; } // free the parser - xml_file_free(root); + root->file_free(); return true; } @@ -2583,12 +2583,12 @@ bool device_debug::comment_export(xml_data_node &curnode) // iterate through the comments for (const auto & elem : m_comment_set) { - xml_data_node *datanode = xml_add_child(&curnode, "comment", xml_normalize_string(elem.m_text.c_str())); + xml_data_node *datanode = curnode.add_child("comment", xml_normalize_string(elem.m_text.c_str())); if (datanode == nullptr) return false; - xml_set_attribute_int(datanode, "address", elem.m_address); - xml_set_attribute_int(datanode, "color", elem.m_color); - xml_set_attribute(datanode, "crc", string_format("%08X", elem.m_crc).c_str()); + datanode->set_attribute_int("address", elem.m_address); + datanode->set_attribute_int("color", elem.m_color); + datanode->set_attribute("crc", string_format("%08X", elem.m_crc).c_str()); } return true; } @@ -2599,23 +2599,23 @@ bool device_debug::comment_export(xml_data_node &curnode) // given XML data node //------------------------------------------------- -bool device_debug::comment_import(xml_data_node &cpunode,bool is_inline) +bool device_debug::comment_import(xml_data_node const &cpunode, bool is_inline) { // iterate through nodes - for (xml_data_node *datanode = xml_get_sibling(cpunode.child, "comment"); datanode; datanode = xml_get_sibling(datanode->next, "comment")) + for (xml_data_node const *datanode = cpunode.get_child("comment"); datanode; datanode = datanode->get_next_sibling("comment")) { // extract attributes - offs_t address = xml_get_attribute_int(datanode, "address", 0); - rgb_t color = xml_get_attribute_int(datanode, "color", 0); + offs_t address = datanode->get_attribute_int("address", 0); + rgb_t color = datanode->get_attribute_int("color", 0); uint32_t crc; - sscanf(xml_get_attribute_string(datanode, "crc", nullptr), "%08X", &crc); + sscanf(datanode->get_attribute_string("crc", nullptr), "%08X", &crc); // add the new comment if(is_inline == true) - m_comment_set.insert(dasm_comment(address, crc, datanode->value, color)); + m_comment_set.insert(dasm_comment(address, crc, datanode->get_value(), color)); else - m_device.machine().debugger().console().printf(" %08X - %s\n", address, datanode->value); + m_device.machine().debugger().console().printf(" %08X - %s\n", address, datanode->get_value()); } return true; } diff --git a/src/emu/debug/debugcpu.h b/src/emu/debug/debugcpu.h index 931824ca3f1..15ea24638ac 100644 --- a/src/emu/debug/debugcpu.h +++ b/src/emu/debug/debugcpu.h @@ -243,7 +243,7 @@ public: uint32_t comment_count() const { return m_comment_set.size(); } uint32_t comment_change_count() const { return m_comment_change; } bool comment_export(xml_data_node &node); - bool comment_import(xml_data_node &node,bool is_inline); + bool comment_import(xml_data_node const &node, bool is_inline); uint32_t compute_opcode_crc32(offs_t pc) const; // history diff --git a/src/emu/image.cpp b/src/emu/image.cpp index 398a72d07e1..b7e5ddd50a0 100644 --- a/src/emu/image.cpp +++ b/src/emu/image.cpp @@ -97,22 +97,22 @@ void image_manager::unload_all() void image_manager::config_load(config_type cfg_type, xml_data_node *parentnode) { - xml_data_node *node; + xml_data_node const *node; const char *dev_instance; const char *working_directory; if ((cfg_type == config_type::CONFIG_TYPE_GAME) && (parentnode != nullptr)) { - for (node = xml_get_sibling(parentnode->child, "device"); node; node = xml_get_sibling(node->next, "device")) + for (node = parentnode->get_child("device"); node; node = node->get_next_sibling("device")) { - dev_instance = xml_get_attribute_string(node, "instance", nullptr); + dev_instance = node->get_attribute_string("instance", nullptr); if ((dev_instance != nullptr) && (dev_instance[0] != '\0')) { for (device_image_interface &image : image_interface_iterator(machine().root_device())) { if (!strcmp(dev_instance, image.instance_name())) { - working_directory = xml_get_attribute_string(node, "directory", nullptr); + working_directory = node->get_attribute_string("directory", nullptr); if (working_directory != nullptr) image.set_working_directory(working_directory); } @@ -139,11 +139,11 @@ void image_manager::config_save(config_type cfg_type, xml_data_node *parentnode) { dev_instance = image.instance_name(); - node = xml_add_child(parentnode, "device", nullptr); + node = parentnode->add_child("device", nullptr); if (node != nullptr) { - xml_set_attribute(node, "instance", dev_instance); - xml_set_attribute(node, "directory", image.working_directory().c_str()); + node->set_attribute("instance", dev_instance); + node->set_attribute("directory", image.working_directory().c_str()); } } } diff --git a/src/emu/ioport.cpp b/src/emu/ioport.cpp index 8f87d33b592..7892225d817 100644 --- a/src/emu/ioport.cpp +++ b/src/emu/ioport.cpp @@ -2101,10 +2101,10 @@ void ioport_manager::load_config(config_type cfg_type, xml_data_node *parentnode if (cfg_type == config_type::CONFIG_TYPE_CONTROLLER) { std::unique_ptr<devicemap_table_type> devicemap_table = std::make_unique<devicemap_table_type>(); - for (xml_data_node *mapdevice_node = xml_get_sibling(parentnode->child, "mapdevice"); mapdevice_node != nullptr; mapdevice_node = xml_get_sibling(mapdevice_node->next, "mapdevice")) + for (xml_data_node const *mapdevice_node = parentnode->get_child("mapdevice"); mapdevice_node != nullptr; mapdevice_node = mapdevice_node->get_next_sibling("mapdevice")) { - const char *devicename = xml_get_attribute_string(mapdevice_node, "device", nullptr); - const char *controllername = xml_get_attribute_string(mapdevice_node, "controller", nullptr); + const char *devicename = mapdevice_node->get_attribute_string("device", nullptr); + const char *controllername = mapdevice_node->get_attribute_string("controller", nullptr); if (devicename != nullptr && controllername != nullptr) { devicemap_table->insert(std::make_pair(std::string(devicename), std::string(controllername))); @@ -2119,11 +2119,11 @@ void ioport_manager::load_config(config_type cfg_type, xml_data_node *parentnode } // iterate over all the port nodes - for (xml_data_node *portnode = xml_get_sibling(parentnode->child, "port"); portnode; portnode = xml_get_sibling(portnode->next, "port")) + for (xml_data_node const *portnode = parentnode->get_child("port"); portnode; portnode = portnode->get_next_sibling("port")) { // get the basic port info from the attributes int player; - int type = token_to_input_type(xml_get_attribute_string(portnode, "type", ""), player); + int type = token_to_input_type(portnode->get_attribute_string("type", ""), player); // initialize sequences to invalid defaults input_seq newseq[SEQ_TYPE_TOTAL]; @@ -2131,16 +2131,16 @@ void ioport_manager::load_config(config_type cfg_type, xml_data_node *parentnode newseq[seqtype].set(INPUT_CODE_INVALID); // loop over new sequences - for (xml_data_node *seqnode = xml_get_sibling(portnode->child, "newseq"); seqnode; seqnode = xml_get_sibling(seqnode->next, "newseq")) + for (xml_data_node const *seqnode = portnode->get_child("newseq"); seqnode; seqnode = seqnode->get_next_sibling("newseq")) { // with a valid type, parse out the new sequence - input_seq_type seqtype = token_to_seq_type(xml_get_attribute_string(seqnode, "type", "")); - if (seqtype != -1 && seqnode->value != nullptr) + input_seq_type seqtype = token_to_seq_type(seqnode->get_attribute_string("type", "")); + if (seqtype != -1 && seqnode->get_value() != nullptr) { - if (strcmp(seqnode->value, "NONE") == 0) + if (strcmp(seqnode->get_value(), "NONE") == 0) newseq[seqtype].set(); else - machine().input().seq_from_tokens(newseq[seqtype], seqnode->value); + machine().input().seq_from_tokens(newseq[seqtype], seqnode->get_value()); } } @@ -2165,11 +2165,11 @@ void ioport_manager::load_config(config_type cfg_type, xml_data_node *parentnode // global remapping table //------------------------------------------------- -void ioport_manager::load_remap_table(xml_data_node *parentnode) +void ioport_manager::load_remap_table(xml_data_node const *parentnode) { // count items first so we can allocate int count = 0; - for (xml_data_node *remapnode = xml_get_sibling(parentnode->child, "remap"); remapnode != nullptr; remapnode = xml_get_sibling(remapnode->next, "remap")) + for (xml_data_node const *remapnode = parentnode->get_child("remap"); remapnode != nullptr; remapnode = remapnode->get_next_sibling("remap")) count++; // if we have some, deal with them @@ -2181,10 +2181,10 @@ void ioport_manager::load_remap_table(xml_data_node *parentnode) // build up the remap table count = 0; - for (xml_data_node *remapnode = xml_get_sibling(parentnode->child, "remap"); remapnode != nullptr; remapnode = xml_get_sibling(remapnode->next, "remap")) + for (xml_data_node const *remapnode = parentnode->get_child("remap"); remapnode != nullptr; remapnode = remapnode->get_next_sibling("remap")) { - input_code origcode = machine().input().code_from_token(xml_get_attribute_string(remapnode, "origcode", "")); - input_code newcode = machine().input().code_from_token(xml_get_attribute_string(remapnode, "newcode", "")); + input_code origcode = machine().input().code_from_token(remapnode->get_attribute_string("origcode", "")); + input_code newcode = machine().input().code_from_token(remapnode->get_attribute_string("newcode", "")); if (origcode != INPUT_CODE_INVALID && newcode != INPUT_CODE_INVALID) { oldtable[count] = origcode; @@ -2207,7 +2207,7 @@ void ioport_manager::load_remap_table(xml_data_node *parentnode) // data to the default mappings //------------------------------------------------- -bool ioport_manager::load_default_config(xml_data_node *portnode, int type, int player, const input_seq *newseq) +bool ioport_manager::load_default_config(xml_data_node const *portnode, int type, int player, const input_seq *newseq) { // find a matching port in the list for (input_type_entry &entry : m_typelist) @@ -2228,12 +2228,12 @@ bool ioport_manager::load_default_config(xml_data_node *portnode, int type, int // data to the current set of input ports //------------------------------------------------- -bool ioport_manager::load_game_config(xml_data_node *portnode, int type, int player, const input_seq *newseq) +bool ioport_manager::load_game_config(xml_data_node const *portnode, int type, int player, const input_seq *newseq) { // read the mask, index, and defvalue attributes - const char *tag = xml_get_attribute_string(portnode, "tag", nullptr); - ioport_value mask = xml_get_attribute_int(portnode, "mask", 0); - ioport_value defvalue = xml_get_attribute_int(portnode, "defvalue", 0); + const char *tag = portnode->get_attribute_string("tag", nullptr); + ioport_value mask = portnode->get_attribute_int("mask", 0); + ioport_value defvalue = portnode->get_attribute_int("defvalue", 0); // find the port we want; if no tag, search them all for (auto &port : m_portlist) @@ -2254,10 +2254,10 @@ bool ioport_manager::load_game_config(xml_data_node *portnode, int type, int pla if (field.live().analog == nullptr) { // fetch the value - field.live().value = xml_get_attribute_int(portnode, "value", field.defvalue()); + field.live().value = portnode->get_attribute_int("value", field.defvalue()); // fetch yes/no for toggle setting - const char *togstring = xml_get_attribute_string(portnode, "toggle", nullptr); + const char *togstring = portnode->get_attribute_string("toggle", nullptr); if (togstring != nullptr) field.live().toggle = (strcmp(togstring, "yes") == 0); } @@ -2266,12 +2266,12 @@ bool ioport_manager::load_game_config(xml_data_node *portnode, int type, int pla else { // get base attributes - field.live().analog->m_delta = xml_get_attribute_int(portnode, "keydelta", field.delta()); - field.live().analog->m_centerdelta = xml_get_attribute_int(portnode, "centerdelta", field.centerdelta()); - field.live().analog->m_sensitivity = xml_get_attribute_int(portnode, "sensitivity", field.sensitivity()); + field.live().analog->m_delta = portnode->get_attribute_int("keydelta", field.delta()); + field.live().analog->m_centerdelta = portnode->get_attribute_int("centerdelta", field.centerdelta()); + field.live().analog->m_sensitivity = portnode->get_attribute_int("sensitivity", field.sensitivity()); // fetch yes/no for reverse setting - const char *revstring = xml_get_attribute_string(portnode, "reverse", nullptr); + const char *revstring = portnode->get_attribute_string("reverse", nullptr); if (revstring != nullptr) field.live().analog->m_reverse = (strcmp(revstring, "yes") == 0); } @@ -2321,9 +2321,9 @@ void ioport_manager::save_sequence(xml_data_node *parentnode, input_seq_type typ seqstring = machine().input().seq_to_tokens(seq); // add the new node - xml_data_node *seqnode = xml_add_child(parentnode, "newseq", seqstring.c_str()); + xml_data_node *const seqnode = parentnode->add_child("newseq", seqstring.c_str()); if (seqnode != nullptr) - xml_set_attribute(seqnode, "type", seqtypestrings[type]); + seqnode->set_attribute("type", seqtypestrings[type]); } @@ -2372,11 +2372,11 @@ void ioport_manager::save_default_inputs(xml_data_node *parentnode) if (seqtype < SEQ_TYPE_TOTAL) { // add a new port node - xml_data_node *portnode = xml_add_child(parentnode, "port", nullptr); + xml_data_node *const portnode = parentnode->add_child("port", nullptr); if (portnode != nullptr) { // add the port information and attributes - xml_set_attribute(portnode, "type", input_type_to_token(entry.type(), entry.player()).c_str()); + portnode->set_attribute("type", input_type_to_token(entry.type(), entry.player()).c_str()); // add only the sequences that have changed from the defaults for (input_seq_type type = SEQ_TYPE_STANDARD; type < SEQ_TYPE_TOTAL; ++type) @@ -2426,14 +2426,14 @@ void ioport_manager::save_game_inputs(xml_data_node *parentnode) if (changed) { // add a new port node - xml_data_node *portnode = xml_add_child(parentnode, "port", nullptr); + xml_data_node *portnode = parentnode->add_child("port", nullptr); if (portnode != nullptr) { // add the identifying information and attributes - xml_set_attribute(portnode, "tag", port.second->tag()); - xml_set_attribute(portnode, "type", input_type_to_token(field.type(), field.player()).c_str()); - xml_set_attribute_int(portnode, "mask", field.mask()); - xml_set_attribute_int(portnode, "defvalue", field.defvalue() & field.mask()); + portnode->set_attribute("tag", port.second->tag()); + portnode->set_attribute("type", input_type_to_token(field.type(), field.player()).c_str()); + portnode->set_attribute_int("mask", field.mask()); + portnode->set_attribute_int("defvalue", field.defvalue() & field.mask()); // add sequences if changed for (input_seq_type seqtype = SEQ_TYPE_STANDARD; seqtype < SEQ_TYPE_TOTAL; ++seqtype) @@ -2444,22 +2444,22 @@ void ioport_manager::save_game_inputs(xml_data_node *parentnode) if (!field.is_analog()) { if ((field.live().value & field.mask()) != (field.defvalue() & field.mask())) - xml_set_attribute_int(portnode, "value", field.live().value & field.mask()); + portnode->set_attribute_int("value", field.live().value & field.mask()); if (field.live().toggle != field.toggle()) - xml_set_attribute(portnode, "toggle", field.live().toggle ? "yes" : "no"); + portnode->set_attribute("toggle", field.live().toggle ? "yes" : "no"); } // write out analog changes else { if (field.live().analog->m_delta != field.delta()) - xml_set_attribute_int(portnode, "keydelta", field.live().analog->m_delta); + portnode->set_attribute_int("keydelta", field.live().analog->m_delta); if (field.live().analog->m_centerdelta != field.centerdelta()) - xml_set_attribute_int(portnode, "centerdelta", field.live().analog->m_centerdelta); + portnode->set_attribute_int("centerdelta", field.live().analog->m_centerdelta); if (field.live().analog->m_sensitivity != field.sensitivity()) - xml_set_attribute_int(portnode, "sensitivity", field.live().analog->m_sensitivity); + portnode->set_attribute_int("sensitivity", field.live().analog->m_sensitivity); if (field.live().analog->m_reverse != field.analog_reverse()) - xml_set_attribute(portnode, "reverse", field.live().analog->m_reverse ? "yes" : "no"); + portnode->set_attribute("reverse", field.live().analog->m_reverse ? "yes" : "no"); } } } diff --git a/src/emu/ioport.h b/src/emu/ioport.h index 3b655abc006..1bb8e45c006 100644 --- a/src/emu/ioport.h +++ b/src/emu/ioport.h @@ -1437,9 +1437,9 @@ private: static const char *const seqtypestrings[]; void load_config(config_type cfg_type, xml_data_node *parentnode); - void load_remap_table(xml_data_node *parentnode); - bool load_default_config(xml_data_node *portnode, int type, int player, const input_seq *newseq); - bool load_game_config(xml_data_node *portnode, int type, int player, const input_seq *newseq); + void load_remap_table(xml_data_node const *parentnode); + bool load_default_config(xml_data_node const *portnode, int type, int player, const input_seq *newseq); + bool load_game_config(xml_data_node const *portnode, int type, int player, const input_seq *newseq); void save_config(config_type cfg_type, xml_data_node *parentnode); void save_sequence(xml_data_node *parentnode, input_seq_type type, ioport_type porttype, const input_seq &seq); diff --git a/src/emu/network.cpp b/src/emu/network.cpp index ed72e59cd06..ec1a876e117 100644 --- a/src/emu/network.cpp +++ b/src/emu/network.cpp @@ -34,21 +34,21 @@ network_manager::network_manager(running_machine &machine) void network_manager::config_load(config_type cfg_type, xml_data_node *parentnode) { - xml_data_node *node; + xml_data_node const *node; if ((cfg_type == config_type::CONFIG_TYPE_GAME) && (parentnode != nullptr)) { - for (node = xml_get_sibling(parentnode->child, "device"); node; node = xml_get_sibling(node->next, "device")) + for (node = parentnode->get_child("device"); node; node = node->get_next_sibling("device")) { - const char *tag = xml_get_attribute_string(node, "tag", nullptr); + const char *tag = node->get_attribute_string("tag", nullptr); if ((tag != nullptr) && (tag[0] != '\0')) { for (device_network_interface &network : network_interface_iterator(machine().root_device())) { if (!strcmp(tag, network.device().tag())) { - int interface = xml_get_attribute_int(node, "interface", 0); + int interface = node->get_attribute_int("interface", 0); network.set_interface(interface); - const char *mac_addr = xml_get_attribute_string(node, "mac", nullptr); + const char *mac_addr = node->get_attribute_string("mac", nullptr); if (mac_addr != nullptr && strlen(mac_addr) == 17) { char mac[7]; unsigned int mac_num[6]; @@ -77,15 +77,15 @@ void network_manager::config_save(config_type cfg_type, xml_data_node *parentnod { for (device_network_interface &network : network_interface_iterator(machine().root_device())) { - node = xml_add_child(parentnode, "device", nullptr); + node = parentnode->add_child("device", nullptr); if (node != nullptr) { - xml_set_attribute(node, "tag", network.device().tag()); - xml_set_attribute_int(node, "interface", network.get_interface()); + node->set_attribute("tag", network.device().tag()); + node->set_attribute_int("interface", network.get_interface()); const char *mac = network.get_mac(); char mac_addr[6 * 3]; sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x", (uint8_t)mac[0], (uint8_t)mac[1], (uint8_t)mac[2], (uint8_t)mac[3], (uint8_t)mac[4], (uint8_t)mac[5]); - xml_set_attribute(node, "mac", mac_addr); + node->set_attribute("mac", mac_addr); } } } diff --git a/src/emu/render.cpp b/src/emu/render.cpp index 3c883fa3d23..c4516a80726 100644 --- a/src/emu/render.cpp +++ b/src/emu/render.cpp @@ -1703,7 +1703,7 @@ bool render_target::load_layout_file(const char *dirname, const char *filename) // if the first character of the "file" is an open brace, assume it is an XML string xml_data_node *rootnode; if (filename[0] == '<') - rootnode = xml_string_read(filename, nullptr); + rootnode = xml_data_node::string_read(filename, nullptr); // otherwise, assume it is a file else @@ -1720,7 +1720,7 @@ bool render_target::load_layout_file(const char *dirname, const char *filename) return false; // read the file - rootnode = xml_file_read(layoutfile, nullptr); + rootnode = xml_data_node::file_read(layoutfile, nullptr); } // if we didn't get a properly-formatted XML file, record a warning and exit @@ -1751,7 +1751,7 @@ bool render_target::load_layout_file(const char *dirname, const char *filename) emulator_info::layout_file_cb(*rootnode); // free the root node - xml_file_free(rootnode); + rootnode->file_free(); return result; } @@ -2215,10 +2215,10 @@ int render_target::view_index(layout_view &targetview) const // config_load - process config information //------------------------------------------------- -void render_target::config_load(xml_data_node &targetnode) +void render_target::config_load(xml_data_node const &targetnode) { // find the view - const char *viewname = xml_get_attribute_string(&targetnode, "view", nullptr); + const char *viewname = targetnode.get_attribute_string("view", nullptr); if (viewname != nullptr) for (int viewnum = 0; viewnum < 1000; viewnum++) { @@ -2233,32 +2233,32 @@ void render_target::config_load(xml_data_node &targetnode) } // modify the artwork config - int tmpint = xml_get_attribute_int(&targetnode, "backdrops", -1); + int tmpint = targetnode.get_attribute_int("backdrops", -1); if (tmpint == 0 || tmpint == 1) set_backdrops_enabled(tmpint); - tmpint = xml_get_attribute_int(&targetnode, "overlays", -1); + tmpint = targetnode.get_attribute_int("overlays", -1); if (tmpint == 0 || tmpint == 1) set_overlays_enabled(tmpint); - tmpint = xml_get_attribute_int(&targetnode, "bezels", -1); + tmpint = targetnode.get_attribute_int("bezels", -1); if (tmpint == 0 || tmpint == 1) set_bezels_enabled(tmpint); - tmpint = xml_get_attribute_int(&targetnode, "cpanels", -1); + tmpint = targetnode.get_attribute_int("cpanels", -1); if (tmpint == 0 || tmpint == 1) set_cpanels_enabled(tmpint); - tmpint = xml_get_attribute_int(&targetnode, "marquees", -1); + tmpint = targetnode.get_attribute_int("marquees", -1); if (tmpint == 0 || tmpint == 1) set_marquees_enabled(tmpint); - tmpint = xml_get_attribute_int(&targetnode, "zoom", -1); + tmpint = targetnode.get_attribute_int("zoom", -1); if (tmpint == 0 || tmpint == 1) set_zoom_to_screen(tmpint); // apply orientation - tmpint = xml_get_attribute_int(&targetnode, "rotate", -1); + tmpint = targetnode.get_attribute_int("rotate", -1); if (tmpint != -1) { if (tmpint == 90) @@ -2295,24 +2295,24 @@ bool render_target::config_save(xml_data_node &targetnode) bool changed = false; // output the basics - xml_set_attribute_int(&targetnode, "index", index()); + targetnode.set_attribute_int("index", index()); // output the view if (m_curview != m_base_view) { - xml_set_attribute(&targetnode, "view", m_curview->name()); + targetnode.set_attribute("view", m_curview->name()); changed = true; } // output the layer config if (m_layerconfig != m_base_layerconfig) { - xml_set_attribute_int(&targetnode, "backdrops", m_layerconfig.backdrops_enabled()); - xml_set_attribute_int(&targetnode, "overlays", m_layerconfig.overlays_enabled()); - xml_set_attribute_int(&targetnode, "bezels", m_layerconfig.bezels_enabled()); - xml_set_attribute_int(&targetnode, "cpanels", m_layerconfig.cpanels_enabled()); - xml_set_attribute_int(&targetnode, "marquees", m_layerconfig.marquees_enabled()); - xml_set_attribute_int(&targetnode, "zoom", m_layerconfig.zoom_to_screen()); + targetnode.set_attribute_int("backdrops", m_layerconfig.backdrops_enabled()); + targetnode.set_attribute_int("overlays", m_layerconfig.overlays_enabled()); + targetnode.set_attribute_int("bezels", m_layerconfig.bezels_enabled()); + targetnode.set_attribute_int("cpanels", m_layerconfig.cpanels_enabled()); + targetnode.set_attribute_int("marquees", m_layerconfig.marquees_enabled()); + targetnode.set_attribute_int("zoom", m_layerconfig.zoom_to_screen()); changed = true; } @@ -2327,7 +2327,7 @@ bool render_target::config_save(xml_data_node &targetnode) else if (orientation_add(ROT270, m_base_orientation) == m_orientation) rotate = 270; assert(rotate != 0); - xml_set_attribute_int(&targetnode, "rotate", rotate); + targetnode.set_attribute_int("rotate", rotate); changed = true; } @@ -2881,26 +2881,26 @@ void render_manager::config_load(config_type cfg_type, xml_data_node *parentnode return; // check the UI target - xml_data_node *uinode = xml_get_sibling(parentnode->child, "interface"); + xml_data_node const *const uinode = parentnode->get_child("interface"); if (uinode != nullptr) { - render_target *target = target_by_index(xml_get_attribute_int(uinode, "target", 0)); + render_target *target = target_by_index(uinode->get_attribute_int("target", 0)); if (target != nullptr) set_ui_target(*target); } // iterate over target nodes - for (xml_data_node *targetnode = xml_get_sibling(parentnode->child, "target"); targetnode; targetnode = xml_get_sibling(targetnode->next, "target")) + for (xml_data_node const *targetnode = parentnode->get_child("target"); targetnode; targetnode = targetnode->get_next_sibling("target")) { - render_target *target = target_by_index(xml_get_attribute_int(targetnode, "index", -1)); + render_target *target = target_by_index(targetnode->get_attribute_int("index", -1)); if (target != nullptr) target->config_load(*targetnode); } // iterate over screen nodes - for (xml_data_node *screennode = xml_get_sibling(parentnode->child, "screen"); screennode; screennode = xml_get_sibling(screennode->next, "screen")) + for (xml_data_node const *screennode = parentnode->get_child("screen"); screennode; screennode = screennode->get_next_sibling("screen")) { - int index = xml_get_attribute_int(screennode, "index", -1); + int index = screennode->get_attribute_int("index", -1); render_container *container = m_screen_container_list.find(index); render_container::user_settings settings; @@ -2908,15 +2908,15 @@ void render_manager::config_load(config_type cfg_type, xml_data_node *parentnode container->get_user_settings(settings); // fetch color controls - settings.m_brightness = xml_get_attribute_float(screennode, "brightness", settings.m_brightness); - settings.m_contrast = xml_get_attribute_float(screennode, "contrast", settings.m_contrast); - settings.m_gamma = xml_get_attribute_float(screennode, "gamma", settings.m_gamma); + settings.m_brightness = screennode->get_attribute_float("brightness", settings.m_brightness); + settings.m_contrast = screennode->get_attribute_float("contrast", settings.m_contrast); + settings.m_gamma = screennode->get_attribute_float("gamma", settings.m_gamma); // fetch positioning controls - settings.m_xoffset = xml_get_attribute_float(screennode, "hoffset", settings.m_xoffset); - settings.m_xscale = xml_get_attribute_float(screennode, "hstretch", settings.m_xscale); - settings.m_yoffset = xml_get_attribute_float(screennode, "voffset", settings.m_yoffset); - settings.m_yscale = xml_get_attribute_float(screennode, "vstretch", settings.m_yscale); + settings.m_xoffset = screennode->get_attribute_float("hoffset", settings.m_xoffset); + settings.m_xscale = screennode->get_attribute_float("hstretch", settings.m_xscale); + settings.m_yoffset = screennode->get_attribute_float("voffset", settings.m_yoffset); + settings.m_yscale = screennode->get_attribute_float("vstretch", settings.m_yscale); // set the new values container->set_user_settings(settings); @@ -2939,9 +2939,9 @@ void render_manager::config_save(config_type cfg_type, xml_data_node *parentnode if (m_ui_target->index() != 0) { // create a node for it - xml_data_node *uinode = xml_add_child(parentnode, "interface", nullptr); + xml_data_node *const uinode = parentnode->add_child("interface", nullptr); if (uinode != nullptr) - xml_set_attribute_int(uinode, "target", m_ui_target->index()); + uinode->set_attribute_int("target", m_ui_target->index()); } // iterate over targets @@ -2953,9 +2953,9 @@ void render_manager::config_save(config_type cfg_type, xml_data_node *parentnode break; // create a node - xml_data_node *targetnode = xml_add_child(parentnode, "target", nullptr); + xml_data_node *const targetnode = parentnode->add_child("target", nullptr); if (targetnode != nullptr && !target->config_save(*targetnode)) - xml_delete_node(targetnode); + targetnode->delete_node(); } // iterate over screen containers @@ -2963,13 +2963,13 @@ void render_manager::config_save(config_type cfg_type, xml_data_node *parentnode for (render_container *container = m_screen_container_list.first(); container != nullptr; container = container->next(), scrnum++) { // create a node - xml_data_node *screennode = xml_add_child(parentnode, "screen", nullptr); + xml_data_node *const screennode = parentnode->add_child("screen", nullptr); if (screennode != nullptr) { bool changed = false; // output the basics - xml_set_attribute_int(screennode, "index", scrnum); + screennode->set_attribute_int("index", scrnum); render_container::user_settings settings; container->get_user_settings(settings); @@ -2977,50 +2977,50 @@ void render_manager::config_save(config_type cfg_type, xml_data_node *parentnode // output the color controls if (settings.m_brightness != machine().options().brightness()) { - xml_set_attribute_float(screennode, "brightness", settings.m_brightness); + screennode->set_attribute_float("brightness", settings.m_brightness); changed = true; } if (settings.m_contrast != machine().options().contrast()) { - xml_set_attribute_float(screennode, "contrast", settings.m_contrast); + screennode->set_attribute_float("contrast", settings.m_contrast); changed = true; } if (settings.m_gamma != machine().options().gamma()) { - xml_set_attribute_float(screennode, "gamma", settings.m_gamma); + screennode->set_attribute_float("gamma", settings.m_gamma); changed = true; } // output the positioning controls if (settings.m_xoffset != 0.0f) { - xml_set_attribute_float(screennode, "hoffset", settings.m_xoffset); + screennode->set_attribute_float("hoffset", settings.m_xoffset); changed = true; } if (settings.m_xscale != 1.0f) { - xml_set_attribute_float(screennode, "hstretch", settings.m_xscale); + screennode->set_attribute_float("hstretch", settings.m_xscale); changed = true; } if (settings.m_yoffset != 0.0f) { - xml_set_attribute_float(screennode, "voffset", settings.m_yoffset); + screennode->set_attribute_float("voffset", settings.m_yoffset); changed = true; } if (settings.m_yscale != 1.0f) { - xml_set_attribute_float(screennode, "vstretch", settings.m_yscale); + screennode->set_attribute_float("vstretch", settings.m_yscale); changed = true; } // if nothing changed, kill the node if (!changed) - xml_delete_node(screennode); + screennode->delete_node(); } } } diff --git a/src/emu/render.h b/src/emu/render.h index 5ad24046c41..2789c20d945 100644 --- a/src/emu/render.h +++ b/src/emu/render.h @@ -645,7 +645,7 @@ class layout_element public: // construction/destruction - layout_element(running_machine &machine, xml_data_node &elemnode, const char *dirname); + layout_element(running_machine &machine, xml_data_node const &elemnode, const char *dirname); virtual ~layout_element(); // getters @@ -664,7 +664,7 @@ private: typedef std::unique_ptr<component> ptr; // construction/destruction - component(running_machine &machine, xml_data_node &compnode, const char *dirname); + component(running_machine &machine, xml_data_node const &compnode, const char *dirname); virtual ~component() = default; // setup @@ -704,7 +704,7 @@ private: { public: // construction/destruction - image_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + image_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -728,7 +728,7 @@ private: { public: // construction/destruction - rect_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + rect_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -740,7 +740,7 @@ private: { public: // construction/destruction - disk_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + disk_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -752,7 +752,7 @@ private: { public: // construction/destruction - text_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + text_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -769,7 +769,7 @@ private: { public: // construction/destruction - led7seg_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + led7seg_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -782,7 +782,7 @@ private: { public: // construction/destruction - led8seg_gts1_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + led8seg_gts1_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -795,7 +795,7 @@ private: { public: // construction/destruction - led14seg_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + led14seg_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -808,7 +808,7 @@ private: { public: // construction/destruction - led16seg_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + led16seg_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -821,7 +821,7 @@ private: { public: // construction/destruction - led14segsc_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + led14segsc_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -834,7 +834,7 @@ private: { public: // construction/destruction - led16segsc_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + led16segsc_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -847,7 +847,7 @@ private: { public: // construction/destruction - dotmatrix_component(int dots, running_machine &machine, xml_data_node &compnode, const char *dirname); + dotmatrix_component(int dots, running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -864,7 +864,7 @@ private: { public: // construction/destruction - simplecounter_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + simplecounter_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -885,7 +885,7 @@ private: public: // construction/destruction - reel_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + reel_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); protected: // overrides @@ -932,13 +932,13 @@ private: int m_state; // associated state number }; - typedef component::ptr (*make_component_func)(running_machine &machine, xml_data_node &compnode, const char *dirname); + typedef component::ptr (*make_component_func)(running_machine &machine, xml_data_node const &compnode, const char *dirname); typedef std::map<std::string, make_component_func> make_component_map; // internal helpers static void element_scale(bitmap_argb32 &dest, bitmap_argb32 &source, const rectangle &sbounds, void *param); - template <typename T> static component::ptr make_component(running_machine &machine, xml_data_node &compnode, const char *dirname); - template <int D> static component::ptr make_dotmatrix_component(running_machine &machine, xml_data_node &compnode, const char *dirname); + template <typename T> static component::ptr make_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); + template <int D> static component::ptr make_dotmatrix_component(running_machine &machine, xml_data_node const &compnode, const char *dirname); static make_component_map const s_make_component; // maps component XML names to creator functions @@ -969,7 +969,7 @@ public: public: // construction/destruction - item(running_machine &machine, xml_data_node &itemnode, simple_list<layout_element> &elemlist); + item(running_machine &machine, xml_data_node const &itemnode, simple_list<layout_element> &elemlist); virtual ~item(); // getters @@ -1005,7 +1005,7 @@ public: }; // construction/destruction - layout_view(running_machine &machine, xml_data_node &viewnode, simple_list<layout_element> &elemlist); + layout_view(running_machine &machine, xml_data_node const &viewnode, simple_list<layout_element> &elemlist); virtual ~layout_view(); // getters @@ -1058,7 +1058,7 @@ class layout_file public: // construction/destruction - layout_file(running_machine &machine, xml_data_node &rootnode, const char *dirname); + layout_file(running_machine &machine, xml_data_node const &rootnode, const char *dirname); virtual ~layout_file(); // getters @@ -1171,7 +1171,7 @@ private: bool map_point_internal(int32_t target_x, int32_t target_y, render_container *container, float &mapped_x, float &mapped_y, ioport_port *&mapped_input_port, ioport_value &mapped_input_mask); // config callbacks - void config_load(xml_data_node &targetnode); + void config_load(xml_data_node const &targetnode); bool config_save(xml_data_node &targetnode); // view lookups diff --git a/src/emu/rendlay.cpp b/src/emu/rendlay.cpp index ed800c6d976..3a606eeeac3 100644 --- a/src/emu/rendlay.cpp +++ b/src/emu/rendlay.cpp @@ -222,9 +222,9 @@ static int get_variable_value(running_machine &machine, const char *string, char // substitution //------------------------------------------------- -static const char *xml_get_attribute_string_with_subst(running_machine &machine, xml_data_node &node, const char *attribute, const char *defvalue) +static const char *xml_get_attribute_string_with_subst(running_machine &machine, xml_data_node const &node, const char *attribute, const char *defvalue) { - const char *str = xml_get_attribute_string(&node, attribute, nullptr); + const char *str = node.get_attribute_string(attribute, nullptr); static char buffer[1000]; // if nothing, just return the default @@ -259,7 +259,7 @@ static const char *xml_get_attribute_string_with_subst(running_machine &machine, // substitution //------------------------------------------------- -static int xml_get_attribute_int_with_subst(running_machine &machine, xml_data_node &node, const char *attribute, int defvalue) +static int xml_get_attribute_int_with_subst(running_machine &machine, xml_data_node const &node, const char *attribute, int defvalue) { const char *string = xml_get_attribute_string_with_subst(machine, node, attribute, nullptr); int value; @@ -283,7 +283,7 @@ static int xml_get_attribute_int_with_subst(running_machine &machine, xml_data_n // substitution //------------------------------------------------- -static float xml_get_attribute_float_with_subst(running_machine &machine, xml_data_node &node, const char *attribute, float defvalue) +static float xml_get_attribute_float_with_subst(running_machine &machine, xml_data_node const &node, const char *attribute, float defvalue) { const char *string = xml_get_attribute_string_with_subst(machine, node, attribute, nullptr); float value; @@ -298,7 +298,7 @@ static float xml_get_attribute_float_with_subst(running_machine &machine, xml_da // parse_bounds - parse a bounds XML node //------------------------------------------------- -void parse_bounds(running_machine &machine, xml_data_node *boundsnode, render_bounds &bounds) +void parse_bounds(running_machine &machine, xml_data_node const *boundsnode, render_bounds &bounds) { // skip if nothing if (boundsnode == nullptr) @@ -309,7 +309,7 @@ void parse_bounds(running_machine &machine, xml_data_node *boundsnode, render_bo } // parse out the data - if (xml_get_attribute(boundsnode, "left") != nullptr) + if (boundsnode->has_attribute("left")) { // left/right/top/bottom format bounds.x0 = xml_get_attribute_float_with_subst(machine, *boundsnode, "left", 0.0f); @@ -317,7 +317,7 @@ void parse_bounds(running_machine &machine, xml_data_node *boundsnode, render_bo bounds.y0 = xml_get_attribute_float_with_subst(machine, *boundsnode, "top", 0.0f); bounds.y1 = xml_get_attribute_float_with_subst(machine, *boundsnode, "bottom", 1.0f); } - else if (xml_get_attribute(boundsnode, "x") != nullptr) + else if (boundsnode->has_attribute("x")) { // x/y/width/height format bounds.x0 = xml_get_attribute_float_with_subst(machine, *boundsnode, "x", 0.0f); @@ -339,7 +339,7 @@ void parse_bounds(running_machine &machine, xml_data_node *boundsnode, render_bo // parse_color - parse a color XML node //------------------------------------------------- -void parse_color(running_machine &machine, xml_data_node *colornode, render_color &color) +void parse_color(running_machine &machine, xml_data_node const *colornode, render_color &color) { // skip if nothing if (colornode == nullptr) @@ -367,7 +367,7 @@ void parse_color(running_machine &machine, xml_data_node *colornode, render_colo // node //------------------------------------------------- -static void parse_orientation(running_machine &machine, xml_data_node *orientnode, int &orientation) +static void parse_orientation(running_machine &machine, xml_data_node const *orientnode, int &orientation) { // skip if nothing if (orientnode == nullptr) @@ -422,7 +422,7 @@ layout_element::make_component_map const layout_element::s_make_component{ // layout_element - constructor //------------------------------------------------- -layout_element::layout_element(running_machine &machine, xml_data_node &elemnode, const char *dirname) +layout_element::layout_element(running_machine &machine, xml_data_node const &elemnode, const char *dirname) : m_next(nullptr), m_machine(machine), m_defstate(0), @@ -440,11 +440,11 @@ layout_element::layout_element(running_machine &machine, xml_data_node &elemnode // parse components in order bool first = true; render_bounds bounds = { 0 }; - for (xml_data_node *compnode = elemnode.child; compnode; compnode = compnode->next) + for (xml_data_node const *compnode = elemnode.get_first_child(); compnode; compnode = compnode->get_next_sibling()) { - make_component_map::const_iterator const make_func(s_make_component.find(compnode->name)); + make_component_map::const_iterator const make_func(s_make_component.find(compnode->get_name())); if (make_func == s_make_component.end()) - throw emu_fatalerror("Unknown element component: %s", compnode->name); + throw emu_fatalerror("Unknown element component: %s", compnode->get_name()); // insert the new component into the list component const &newcomp(**m_complist.emplace(m_complist.end(), make_func->second(machine, *compnode, dirname))); @@ -539,7 +539,7 @@ void layout_element::element_scale(bitmap_argb32 &dest, bitmap_argb32 &source, c //------------------------------------------------- template <typename T> -layout_element::component::ptr layout_element::make_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::component::ptr layout_element::make_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) { return std::make_unique<T>(machine, compnode, dirname); } @@ -551,7 +551,7 @@ layout_element::component::ptr layout_element::make_component(running_machine &m //------------------------------------------------- template <int D> -layout_element::component::ptr layout_element::make_dotmatrix_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::component::ptr layout_element::make_dotmatrix_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) { return std::make_unique<dotmatrix_component>(D, machine, compnode, dirname); } @@ -614,13 +614,13 @@ layout_element::texture &layout_element::texture::operator=(texture &&that) // component - constructor //------------------------------------------------- -layout_element::component::component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::component::component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : m_state(0) { // fetch common data m_state = xml_get_attribute_int_with_subst(machine, compnode, "state", -1); - parse_bounds(machine, xml_get_sibling(compnode.child, "bounds"), m_bounds); - parse_color(machine, xml_get_sibling(compnode.child, "color"), m_color); + parse_bounds(machine, compnode.get_child("bounds"), m_bounds); + parse_color(machine, compnode.get_child("color"), m_color); } @@ -641,9 +641,9 @@ void layout_element::component::normalize_bounds(float xoffs, float yoffs, float // image_component - constructor //------------------------------------------------- -layout_element::image_component::image_component(running_machine &machine, xml_data_node &compnode, const char *dirname) - : component(machine, compnode, dirname), - m_hasalpha(false) +layout_element::image_component::image_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) + : component(machine, compnode, dirname) + , m_hasalpha(false) { if (dirname != nullptr) m_dirname = dirname; @@ -709,7 +709,7 @@ void layout_element::image_component::load_bitmap() // text_component - constructor //------------------------------------------------- -layout_element::text_component::text_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::text_component::text_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname) { m_string = xml_get_attribute_string_with_subst(machine, compnode, "string", ""); @@ -733,7 +733,7 @@ void layout_element::text_component::draw(running_machine &machine, bitmap_argb3 // dotmatrix_component - constructor //------------------------------------------------- -layout_element::dotmatrix_component::dotmatrix_component(int dots, running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::dotmatrix_component::dotmatrix_component(int dots, running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname), m_dots(dots) { @@ -769,7 +769,7 @@ void layout_element::dotmatrix_component::draw(running_machine &machine, bitmap_ // simplecounter_component - constructor //------------------------------------------------- -layout_element::simplecounter_component::simplecounter_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::simplecounter_component::simplecounter_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname) { m_digits = xml_get_attribute_int_with_subst(machine, compnode, "digits", 2); @@ -795,7 +795,7 @@ void layout_element::simplecounter_component::draw(running_machine &machine, bit // reel_component - constructor //------------------------------------------------- -layout_element::reel_component::reel_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::reel_component::reel_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname) { for (auto & elem : m_hasalpha) @@ -1203,7 +1203,7 @@ void layout_element::reel_component::load_reel_bitmap(int number) // led7seg_component - constructor //------------------------------------------------- -layout_element::led7seg_component::led7seg_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::led7seg_component::led7seg_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname) { } @@ -1264,7 +1264,7 @@ void layout_element::led7seg_component::draw(running_machine &machine, bitmap_ar // led8seg_gts1_component - constructor //------------------------------------------------- -layout_element::led8seg_gts1_component::led8seg_gts1_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::led8seg_gts1_component::led8seg_gts1_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname) { } @@ -1331,7 +1331,7 @@ void layout_element::led8seg_gts1_component::draw(running_machine &machine, bitm // led14seg_component - constructor //------------------------------------------------- -layout_element::led14seg_component::led14seg_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::led14seg_component::led14seg_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname) { } @@ -1442,7 +1442,7 @@ void layout_element::led14seg_component::draw(running_machine &machine, bitmap_a // led14segsc_component - constructor //------------------------------------------------- -layout_element::led14segsc_component::led14segsc_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::led14segsc_component::led14segsc_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname) { } @@ -1562,7 +1562,7 @@ void layout_element::led14segsc_component::draw(running_machine &machine, bitmap // led16seg_component - constructor //------------------------------------------------- -layout_element::led16seg_component::led16seg_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::led16seg_component::led16seg_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname) { } @@ -1683,7 +1683,7 @@ void layout_element::led16seg_component::draw(running_machine &machine, bitmap_a // led16segsc_component - constructor //------------------------------------------------- -layout_element::led16segsc_component::led16segsc_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::led16segsc_component::led16segsc_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname) { } @@ -1813,7 +1813,7 @@ void layout_element::led16segsc_component::draw(running_machine &machine, bitmap // rect_component - constructor //------------------------------------------------- -layout_element::rect_component::rect_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::rect_component::rect_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname) { } @@ -1859,7 +1859,7 @@ void layout_element::rect_component::draw(running_machine &machine, bitmap_argb3 // disk_component - constructor //------------------------------------------------- -layout_element::disk_component::disk_component(running_machine &machine, xml_data_node &compnode, const char *dirname) +layout_element::disk_component::disk_component(running_machine &machine, xml_data_node const &compnode, const char *dirname) : component(machine, compnode, dirname) { } @@ -2213,42 +2213,42 @@ const simple_list<layout_view::item> layout_view::s_null_list; // layout_view - constructor //------------------------------------------------- -layout_view::layout_view(running_machine &machine, xml_data_node &viewnode, simple_list<layout_element> &elemlist) - : m_next(nullptr), - m_aspect(1.0f), - m_scraspect(1.0f) +layout_view::layout_view(running_machine &machine, xml_data_node const &viewnode, simple_list<layout_element> &elemlist) + : m_next(nullptr) + , m_aspect(1.0f) + , m_scraspect(1.0f) { // allocate a copy of the name m_name = xml_get_attribute_string_with_subst(machine, viewnode, "name", ""); // if we have a bounds item, load it - xml_data_node *boundsnode = xml_get_sibling(viewnode.child, "bounds"); + xml_data_node const *const boundsnode = viewnode.get_child("bounds"); m_expbounds.x0 = m_expbounds.y0 = m_expbounds.x1 = m_expbounds.y1 = 0; if (boundsnode != nullptr) - parse_bounds(machine, xml_get_sibling(boundsnode, "bounds"), m_expbounds); + parse_bounds(machine, boundsnode, m_expbounds); // load backdrop items - for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "backdrop"); itemnode != nullptr; itemnode = xml_get_sibling(itemnode->next, "backdrop")) + for (xml_data_node const *itemnode = viewnode.get_child("backdrop"); itemnode != nullptr; itemnode = itemnode->get_next_sibling("backdrop")) m_backdrop_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // load screen items - for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "screen"); itemnode != nullptr; itemnode = xml_get_sibling(itemnode->next, "screen")) + for (xml_data_node const *itemnode = viewnode.get_child("screen"); itemnode != nullptr; itemnode = itemnode->get_next_sibling("screen")) m_screen_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // load overlay items - for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "overlay"); itemnode != nullptr; itemnode = xml_get_sibling(itemnode->next, "overlay")) + for (xml_data_node const *itemnode = viewnode.get_child("overlay"); itemnode != nullptr; itemnode = itemnode->get_next_sibling("overlay")) m_overlay_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // load bezel items - for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "bezel"); itemnode != nullptr; itemnode = xml_get_sibling(itemnode->next, "bezel")) + for (xml_data_node const *itemnode = viewnode.get_child("bezel"); itemnode != nullptr; itemnode = itemnode->get_next_sibling("bezel")) m_bezel_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // load cpanel items - for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "cpanel"); itemnode != nullptr; itemnode = xml_get_sibling(itemnode->next, "cpanel")) + for (xml_data_node const *itemnode = viewnode.get_child("cpanel"); itemnode != nullptr; itemnode = itemnode->get_next_sibling("cpanel")) m_cpanel_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // load marquee items - for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "marquee"); itemnode != nullptr; itemnode = xml_get_sibling(itemnode->next, "marquee")) + for (xml_data_node const *itemnode = viewnode.get_child("marquee"); itemnode != nullptr; itemnode = itemnode->get_next_sibling("marquee")) m_marquee_list.append(*global_alloc(item(machine, *itemnode, elemlist))); // recompute the data for the view based on a default layer config @@ -2410,13 +2410,13 @@ void layout_view::resolve_tags() // item - constructor //------------------------------------------------- -layout_view::item::item(running_machine &machine, xml_data_node &itemnode, simple_list<layout_element> &elemlist) - : m_next(nullptr), - m_element(nullptr), - m_input_port(nullptr), - m_input_mask(0), - m_screen(nullptr), - m_orientation(ROT0) +layout_view::item::item(running_machine &machine, xml_data_node const &itemnode, simple_list<layout_element> &elemlist) + : m_next(nullptr) + , m_element(nullptr) + , m_input_port(nullptr) + , m_input_mask(0) + , m_screen(nullptr) + , m_orientation(ROT0) { // allocate a copy of the output name m_output_name = xml_get_attribute_string_with_subst(machine, itemnode, "name", ""); @@ -2448,12 +2448,12 @@ layout_view::item::item(running_machine &machine, xml_data_node &itemnode, simpl m_input_mask = xml_get_attribute_int_with_subst(machine, itemnode, "inputmask", 0); if (m_output_name[0] != 0 && m_element != nullptr) machine.output().set_value(m_output_name.c_str(), m_element->default_state()); - parse_bounds(machine, xml_get_sibling(itemnode.child, "bounds"), m_rawbounds); - parse_color(machine, xml_get_sibling(itemnode.child, "color"), m_color); - parse_orientation(machine, xml_get_sibling(itemnode.child, "orientation"), m_orientation); + parse_bounds(machine, itemnode.get_child("bounds"), m_rawbounds); + parse_color(machine, itemnode.get_child("color"), m_color); + parse_orientation(machine, itemnode.get_child("orientation"), m_orientation); // sanity checks - if (strcmp(itemnode.name, "screen") == 0) + if (strcmp(itemnode.get_name(), "screen") == 0) { if (m_screen == nullptr) throw emu_fatalerror("Layout references invalid screen index %d", index); @@ -2461,7 +2461,7 @@ layout_view::item::item(running_machine &machine, xml_data_node &itemnode, simpl else { if (m_element == nullptr) - throw emu_fatalerror("Layout item of type %s require an element tag", itemnode.name); + throw emu_fatalerror("Layout item of type %s require an element tag", itemnode.get_name()); } if (has_input()) @@ -2542,25 +2542,25 @@ void layout_view::item::resolve_tags() // layout_file - constructor //------------------------------------------------- -layout_file::layout_file(running_machine &machine, xml_data_node &rootnode, const char *dirname) +layout_file::layout_file(running_machine &machine, xml_data_node const &rootnode, const char *dirname) : m_next(nullptr) { // find the layout node - xml_data_node *mamelayoutnode = xml_get_sibling(rootnode.child, "mamelayout"); + xml_data_node const *const mamelayoutnode = rootnode.get_child("mamelayout"); if (mamelayoutnode == nullptr) throw emu_fatalerror("Invalid XML file: missing mamelayout node"); // validate the config data version - int version = xml_get_attribute_int(mamelayoutnode, "version", 0); + int const version = mamelayoutnode->get_attribute_int("version", 0); if (version != LAYOUT_VERSION) throw emu_fatalerror("Invalid XML file: unsupported version"); // parse all the elements - for (xml_data_node *elemnode = xml_get_sibling(mamelayoutnode->child, "element"); elemnode != nullptr; elemnode = xml_get_sibling(elemnode->next, "element")) + for (xml_data_node const *elemnode = mamelayoutnode->get_child("element"); elemnode != nullptr; elemnode = elemnode->get_next_sibling("element")) m_elemlist.append(*global_alloc(layout_element(machine, *elemnode, dirname))); // parse all the views - for (xml_data_node *viewnode = xml_get_sibling(mamelayoutnode->child, "view"); viewnode != nullptr; viewnode = xml_get_sibling(viewnode->next, "view")) + for (xml_data_node const *viewnode = mamelayoutnode->get_child("view"); viewnode != nullptr; viewnode = viewnode->get_next_sibling("view")) m_viewlist.append(*global_alloc(layout_view(machine, *viewnode, m_elemlist))); } diff --git a/src/emu/sound.cpp b/src/emu/sound.cpp index 28a17f111a2..06828789dc5 100644 --- a/src/emu/sound.cpp +++ b/src/emu/sound.cpp @@ -999,13 +999,13 @@ void sound_manager::config_load(config_type cfg_type, xml_data_node *parentnode) return; // iterate over channel nodes - for (xml_data_node *channelnode = xml_get_sibling(parentnode->child, "channel"); channelnode != nullptr; channelnode = xml_get_sibling(channelnode->next, "channel")) + for (xml_data_node const *channelnode = parentnode->get_child("channel"); channelnode != nullptr; channelnode = channelnode->get_next_sibling("channel")) { mixer_input info; - if (indexed_mixer_input(xml_get_attribute_int(channelnode, "index", -1), info)) + if (indexed_mixer_input(channelnode->get_attribute_int("index", -1), info)) { - float defvol = xml_get_attribute_float(channelnode, "defvol", 1.0f); - float newvol = xml_get_attribute_float(channelnode, "newvol", -1000.0f); + float defvol = channelnode->get_attribute_float("defvol", 1.0f); + float newvol = channelnode->get_attribute_float("newvol", -1000.0f); if (newvol != -1000.0f) info.stream->set_user_gain(info.inputnum, newvol / defvol); } @@ -1035,11 +1035,11 @@ void sound_manager::config_save(config_type cfg_type, xml_data_node *parentnode) if (newvol != 1.0f) { - xml_data_node *channelnode = xml_add_child(parentnode, "channel", nullptr); + xml_data_node *const channelnode = parentnode->add_child("channel", nullptr); if (channelnode != nullptr) { - xml_set_attribute_int(channelnode, "index", mixernum); - xml_set_attribute_float(channelnode, "newvol", newvol); + channelnode->set_attribute_int("index", mixernum); + channelnode->set_attribute_float("newvol", newvol); } } } diff --git a/src/frontend/mame/cheat.cpp b/src/frontend/mame/cheat.cpp index 0bb594e5c03..2841ec1d7ce 100644 --- a/src/frontend/mame/cheat.cpp +++ b/src/frontend/mame/cheat.cpp @@ -133,31 +133,31 @@ inline std::string number_and_format::format() const // cheat_parameter - constructor //------------------------------------------------- -cheat_parameter::cheat_parameter(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node ¶mnode) +cheat_parameter::cheat_parameter(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node const ¶mnode) : m_value(0) { // read the core attributes - m_minval = number_and_format(xml_get_attribute_int(¶mnode, "min", 0), xml_get_attribute_int_format(¶mnode, "min")); - m_maxval = number_and_format(xml_get_attribute_int(¶mnode, "max", 0), xml_get_attribute_int_format(¶mnode, "max")); - m_stepval = number_and_format(xml_get_attribute_int(¶mnode, "step", 1), xml_get_attribute_int_format(¶mnode, "step")); + m_minval = number_and_format(paramnode.get_attribute_int("min", 0), paramnode.get_attribute_int_format("min")); + m_maxval = number_and_format(paramnode.get_attribute_int("max", 0), paramnode.get_attribute_int_format("max")); + m_stepval = number_and_format(paramnode.get_attribute_int("step", 1), paramnode.get_attribute_int_format("step")); // iterate over items - for (xml_data_node *itemnode = xml_get_sibling(paramnode.child, "item"); itemnode != nullptr; itemnode = xml_get_sibling(itemnode->next, "item")) + for (xml_data_node const *itemnode = paramnode.get_child("item"); itemnode != nullptr; itemnode = itemnode->get_next_sibling("item")) { // check for nullptr text - if (itemnode->value == nullptr || itemnode->value[0] == 0) + if (itemnode->get_value() == nullptr || itemnode->get_value()[0] == 0) throw emu_fatalerror("%s.xml(%d): item is missing text\n", filename, itemnode->line); // check for non-existant value - if (xml_get_attribute(itemnode, "value") == nullptr) + if (!itemnode->has_attribute("value")) throw emu_fatalerror("%s.xml(%d): item is value\n", filename, itemnode->line); // extract the parameters - uint64_t value = xml_get_attribute_int(itemnode, "value", 0); - int format = xml_get_attribute_int_format(itemnode, "value"); + uint64_t value = itemnode->get_attribute_int("value", 0); + int format = itemnode->get_attribute_int_format("value"); // allocate and append a new item - auto curitem = std::make_unique<item>(itemnode->value, value, format); + auto curitem = std::make_unique<item>(itemnode->get_value(), value, format); // ensure the maximum expands to suit m_maxval = std::max(m_maxval, curitem->value()); @@ -318,11 +318,11 @@ bool cheat_parameter::set_next_state() // cheat_script - constructor //------------------------------------------------- -cheat_script::cheat_script(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node &scriptnode) +cheat_script::cheat_script(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node const &scriptnode) : m_state(SCRIPT_STATE_RUN) { // read the core attributes - const char *state = xml_get_attribute_string(&scriptnode, "state", "run"); + const char *state = scriptnode.get_attribute_string("state", "run"); if (strcmp(state, "on") == 0) m_state = SCRIPT_STATE_ON; else if (strcmp(state, "off") == 0) @@ -333,20 +333,20 @@ cheat_script::cheat_script(cheat_manager &manager, symbol_table &symbols, const throw emu_fatalerror("%s.xml(%d): invalid script state '%s'\n", filename, scriptnode.line, state); // iterate over nodes within the script - for (xml_data_node *entrynode = scriptnode.child; entrynode != nullptr; entrynode = entrynode->next) + for (xml_data_node const *entrynode = scriptnode.get_first_child(); entrynode != nullptr; entrynode = entrynode->get_next_sibling()) { // handle action nodes - if (strcmp(entrynode->name, "action") == 0) + if (strcmp(entrynode->get_name(), "action") == 0) m_entrylist.push_back(std::make_unique<script_entry>(manager, symbols, filename, *entrynode, true)); // handle output nodes - else if (strcmp(entrynode->name, "output") == 0) + else if (strcmp(entrynode->get_name(), "output") == 0) m_entrylist.push_back(std::make_unique<script_entry>(manager, symbols, filename, *entrynode, false)); // anything else is ignored else { - osd_printf_warning("%s.xml(%d): unknown script item '%s' will be lost if saved\n", filename, entrynode->line, entrynode->name); + osd_printf_warning("%s.xml(%d): unknown script item '%s' will be lost if saved\n", filename, entrynode->line, entrynode->get_name()); continue; } } @@ -400,7 +400,7 @@ void cheat_script::save(emu_file &cheatfile) const // script_entry - constructor //------------------------------------------------- -cheat_script::script_entry::script_entry(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node &entrynode, bool isaction) +cheat_script::script_entry::script_entry(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node const &entrynode, bool isaction) : m_condition(&symbols), m_expression(&symbols) { @@ -408,14 +408,14 @@ cheat_script::script_entry::script_entry(cheat_manager &manager, symbol_table &s try { // read the condition if present - expression = xml_get_attribute_string(&entrynode, "condition", nullptr); + expression = entrynode.get_attribute_string("condition", nullptr); if (expression != nullptr) m_condition.parse(expression); // if this is an action, parse the expression if (isaction) { - expression = entrynode.value; + expression = entrynode.get_value(); if (expression == nullptr || expression[0] == 0) throw emu_fatalerror("%s.xml(%d): missing expression in action tag\n", filename, entrynode.line); m_expression.parse(expression); @@ -425,15 +425,15 @@ cheat_script::script_entry::script_entry(cheat_manager &manager, symbol_table &s else { // extract format - const char *format = xml_get_attribute_string(&entrynode, "format", nullptr); + const char *format = entrynode.get_attribute_string("format", nullptr); if (format == nullptr || format[0] == 0) throw emu_fatalerror("%s.xml(%d): missing format in output tag\n", filename, entrynode.line); m_format.assign(format); // extract other attributes - m_line = xml_get_attribute_int(&entrynode, "line", 0); + m_line = entrynode.get_attribute_int("line", 0); m_justify = ui::text_layout::LEFT; - const char *align = xml_get_attribute_string(&entrynode, "align", "left"); + const char *align = entrynode.get_attribute_string("align", "left"); if (strcmp(align, "center") == 0) m_justify = ui::text_layout::CENTER; else if (strcmp(align, "right") == 0) @@ -443,7 +443,7 @@ cheat_script::script_entry::script_entry(cheat_manager &manager, symbol_table &s // then parse arguments int totalargs = 0; - for (xml_data_node *argnode = xml_get_sibling(entrynode.child, "argument"); argnode != nullptr; argnode = xml_get_sibling(argnode->next, "argument")) + for (xml_data_node const *argnode = entrynode.get_child("argument"); argnode != nullptr; argnode = argnode->get_next_sibling("argument")) { auto curarg = std::make_unique<output_argument>(manager, symbols, filename, *argnode); // verify we didn't overrun the argument count @@ -609,15 +609,15 @@ void cheat_script::script_entry::validate_format(const char *filename, int line) // output_argument - constructor //------------------------------------------------- -cheat_script::script_entry::output_argument::output_argument(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node &argnode) +cheat_script::script_entry::output_argument::output_argument(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node const &argnode) : m_expression(&symbols), m_count(0) { // first extract attributes - m_count = xml_get_attribute_int(&argnode, "count", 1); + m_count = argnode.get_attribute_int("count", 1); // read the expression - const char *expression = argnode.value; + const char *expression = argnode.get_value(); if (expression == nullptr || expression[0] == 0) throw emu_fatalerror("%s.xml(%d): missing expression in argument tag\n", filename, argnode.line); @@ -677,18 +677,18 @@ void cheat_script::script_entry::output_argument::save(emu_file &cheatfile) cons // cheat_entry - constructor //------------------------------------------------- -cheat_entry::cheat_entry(cheat_manager &manager, symbol_table &globaltable, const char *filename, xml_data_node &cheatnode) - : m_manager(manager), - m_symbols(&manager.machine(), &globaltable), - m_state(SCRIPT_STATE_OFF), - m_numtemp(DEFAULT_TEMP_VARIABLES), - m_argindex(0) +cheat_entry::cheat_entry(cheat_manager &manager, symbol_table &globaltable, const char *filename, xml_data_node const &cheatnode) + : m_manager(manager) + , m_symbols(&manager.machine(), &globaltable) + , m_state(SCRIPT_STATE_OFF) + , m_numtemp(DEFAULT_TEMP_VARIABLES) + , m_argindex(0) { // reset scripts try { // pull the variable count out ahead of things - int tempcount = xml_get_attribute_int(&cheatnode, "tempvariables", DEFAULT_TEMP_VARIABLES); + int tempcount = cheatnode.get_attribute_int("tempvariables", DEFAULT_TEMP_VARIABLES); if (tempcount < 1) throw emu_fatalerror("%s.xml(%d): invalid tempvariables attribute (%d)\n", filename, cheatnode.line, tempcount); @@ -696,7 +696,7 @@ cheat_entry::cheat_entry(cheat_manager &manager, symbol_table &globaltable, cons m_numtemp = tempcount; // get the description - const char *description = xml_get_attribute_string(&cheatnode, "desc", nullptr); + const char *description = cheatnode.get_attribute_string("desc", nullptr); if (description == nullptr || description[0] == 0) throw emu_fatalerror("%s.xml(%d): empty or missing desc attribute on cheat\n", filename, cheatnode.line); m_description = description; @@ -708,34 +708,34 @@ cheat_entry::cheat_entry(cheat_manager &manager, symbol_table &globaltable, cons } // read the first comment node - xml_data_node *commentnode = xml_get_sibling(cheatnode.child, "comment"); + xml_data_node const *commentnode = cheatnode.get_child("comment"); if (commentnode != nullptr) { // set the value if not nullptr - if (commentnode->value != nullptr && commentnode->value[0] != 0) - m_comment.assign(commentnode->value); + if (commentnode->get_value() != nullptr && commentnode->get_value()[0] != 0) + m_comment.assign(commentnode->get_value()); // only one comment is kept - commentnode = xml_get_sibling(commentnode->next, "comment"); + commentnode = commentnode->get_next_sibling("comment"); if (commentnode != nullptr) osd_printf_warning("%s.xml(%d): only one comment node is retained; ignoring additional nodes\n", filename, commentnode->line); } // read the first parameter node - xml_data_node *paramnode = xml_get_sibling(cheatnode.child, "parameter"); + xml_data_node const *paramnode = cheatnode.get_child("parameter"); if (paramnode != nullptr) { // load this parameter m_parameter.reset(global_alloc(cheat_parameter(manager, m_symbols, filename, *paramnode))); // only one parameter allowed - paramnode = xml_get_sibling(paramnode->next, "parameter"); + paramnode = paramnode->get_next_sibling("parameter"); if (paramnode != nullptr) osd_printf_warning("%s.xml(%d): only one parameter node allowed; ignoring additional nodes\n", filename, paramnode->line); } // read the script nodes - for (xml_data_node *scriptnode = xml_get_sibling(cheatnode.child, "script"); scriptnode != nullptr; scriptnode = xml_get_sibling(scriptnode->next, "script")) + for (xml_data_node const *scriptnode = cheatnode.get_child("script"); scriptnode != nullptr; scriptnode = scriptnode->get_next_sibling("script")) { // load this entry auto curscript = global_alloc(cheat_script(manager, m_symbols, filename, *scriptnode)); @@ -1401,24 +1401,24 @@ void cheat_manager::load_cheats(const char *filename) xml_parse_options options = { nullptr }; xml_parse_error error; options.error = &error; - std::unique_ptr<xml_data_node, void (*)(xml_data_node *)> rootnode(xml_file_read(cheatfile, &options), &xml_file_free); + std::unique_ptr<xml_data_node, void (*)(xml_data_node *)> rootnode(xml_data_node::file_read(cheatfile, &options), [] (xml_data_node *node) { node->file_free(); }); // if unable to parse the file, just bail if (rootnode == nullptr) throw emu_fatalerror("%s.xml(%d): error parsing XML (%s)\n", filename, error.error_line, error.error_message); // find the layout node - xml_data_node *mamecheatnode = xml_get_sibling(rootnode->child, "mamecheat"); + xml_data_node *mamecheatnode = rootnode->get_child("mamecheat"); if (mamecheatnode == nullptr) throw emu_fatalerror("%s.xml: missing mamecheatnode node", filename); // validate the config data version - int version = xml_get_attribute_int(mamecheatnode, "version", 0); + int version = mamecheatnode->get_attribute_int("version", 0); if (version != CHEAT_VERSION) throw emu_fatalerror("%s.xml(%d): Invalid cheat XML file: unsupported version", filename, mamecheatnode->line); // parse all the elements - for (xml_data_node *cheatnode = xml_get_sibling(mamecheatnode->child, "cheat"); cheatnode != nullptr; cheatnode = xml_get_sibling(cheatnode->next, "cheat")) + for (xml_data_node const *cheatnode = mamecheatnode->get_child("cheat"); cheatnode != nullptr; cheatnode = cheatnode->get_next_sibling("cheat")) { // load this entry auto curcheat = std::make_unique<cheat_entry>(*this, m_symtable, filename, *cheatnode); diff --git a/src/frontend/mame/cheat.h b/src/frontend/mame/cheat.h index febe1f85cfd..aa08106b15a 100644 --- a/src/frontend/mame/cheat.h +++ b/src/frontend/mame/cheat.h @@ -76,7 +76,7 @@ class cheat_parameter { public: // construction/destruction - cheat_parameter(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node ¶mnode); + cheat_parameter(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node const ¶mnode); // queries const char *text(); @@ -129,7 +129,7 @@ class cheat_script { public: // construction/destruction - cheat_script(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node &scriptnode); + cheat_script(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node const &scriptnode); // getters script_state state() const { return m_state; } @@ -144,7 +144,7 @@ private: { public: // construction/destruction - script_entry(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node &entrynode, bool isaction); + script_entry(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node const &entrynode, bool isaction); // actions void execute(cheat_manager &manager, uint64_t &argindex); @@ -156,7 +156,7 @@ private: { public: // construction/destruction - output_argument(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node &argnode); + output_argument(cheat_manager &manager, symbol_table &symbols, const char *filename, xml_data_node const &argnode); // getters int count() const { return m_count; } @@ -199,7 +199,7 @@ class cheat_entry { public: // construction/destruction - cheat_entry(cheat_manager &manager, symbol_table &globaltable, const char *filename, xml_data_node &cheatnode); + cheat_entry(cheat_manager &manager, symbol_table &globaltable, const char *filename, xml_data_node const &cheatnode); ~cheat_entry(); // getters diff --git a/src/frontend/mame/mame.cpp b/src/frontend/mame/mame.cpp index 5bb5486b7f7..b0913489569 100644 --- a/src/frontend/mame/mame.cpp +++ b/src/frontend/mame/mame.cpp @@ -336,12 +336,12 @@ bool emulator_info::frame_hook() void emulator_info::layout_file_cb(xml_data_node &layout) { - xml_data_node *mamelayout = xml_get_sibling(layout.child, "mamelayout"); - if(mamelayout) + xml_data_node const *const mamelayout = layout.get_child("mamelayout"); + if (mamelayout) { - xml_data_node *script = xml_get_sibling(mamelayout->child, "script"); + xml_data_node const *const script = mamelayout->get_child("script"); if(script) - mame_machine_manager::instance()->lua()->call_plugin_set("layout", script->value); + mame_machine_manager::instance()->lua()->call_plugin_set("layout", script->get_value()); } } diff --git a/src/lib/util/xmlfile.cpp b/src/lib/util/xmlfile.cpp index 2b9bc8ed20d..08512611668 100644 --- a/src/lib/util/xmlfile.cpp +++ b/src/lib/util/xmlfile.cpp @@ -11,9 +11,13 @@ #include <assert.h> #include "xmlfile.h" -#include <ctype.h> #include <expat.h> +#include <algorithm> +#include <cctype> +#include <cstdlib> +#include <cstring> + /*************************************************************************** CONSTANTS @@ -32,7 +36,7 @@ struct xml_parse_info XML_Parser parser; xml_data_node * rootnode; xml_data_node * curnode; - uint32_t flags; + uint32_t flags; }; @@ -42,19 +46,11 @@ struct xml_parse_info ***************************************************************************/ /* expat interfaces */ -static bool expat_setup_parser(xml_parse_info *parse_info, xml_parse_options *opts); +static bool expat_setup_parser(xml_parse_info &info, xml_parse_options const *opts); static void expat_element_start(void *data, const XML_Char *name, const XML_Char **attributes); static void expat_data(void *data, const XML_Char *s, int len); static void expat_element_end(void *data, const XML_Char *name); -/* node/attributes additions */ -static xml_data_node *add_child(xml_data_node *parent, const char *name, const char *value); -static xml_attribute_node *add_attribute(xml_data_node *node, const char *name, const char *value); - -/* recursive tree operations */ -static void write_node_recursive(xml_data_node *node, int indent, util::core_file &file); -static void free_node_recursive(xml_data_node *node); - /*************************************************************************** @@ -66,7 +62,7 @@ static void free_node_recursive(xml_data_node *node); string -------------------------------------------------*/ -static const char *copystring(const char *input) +static char *copystring(const char *input) { char *newstr; @@ -89,7 +85,7 @@ static const char *copystring(const char *input) the way -------------------------------------------------*/ -static const char *copystring_lower(const char *input) +static char *copystring_lower(const char *input) { char *newstr; int i; @@ -121,16 +117,10 @@ static const char *copystring_lower(const char *input) object -------------------------------------------------*/ -xml_data_node *xml_file_create(void) +xml_data_node *xml_data_node::file_create() { - xml_data_node *rootnode; - - /* create a root node */ - rootnode = (xml_data_node *)malloc(sizeof(*rootnode)); - if (rootnode == nullptr) - return nullptr; - memset(rootnode, 0, sizeof(*rootnode)); - return rootnode; + try { return new xml_data_node(); } + catch (...) { return nullptr; } } @@ -139,13 +129,13 @@ xml_data_node *xml_file_create(void) nodes -------------------------------------------------*/ -xml_data_node *xml_file_read(util::core_file &file, xml_parse_options *opts) +xml_data_node *xml_data_node::file_read(util::core_file &file, xml_parse_options const *opts) { - xml_parse_info parse_info; + xml_parse_info info; int done; /* set up the parser */ - if (!expat_setup_parser(&parse_info, opts)) + if (!expat_setup_parser(info, opts)) return nullptr; /* loop through the file and parse it */ @@ -158,27 +148,27 @@ xml_data_node *xml_file_read(util::core_file &file, xml_parse_options *opts) done = file.eof(); /* parse the data */ - if (XML_Parse(parse_info.parser, tempbuf, bytes, done) == XML_STATUS_ERROR) + if (XML_Parse(info.parser, tempbuf, bytes, done) == XML_STATUS_ERROR) { if (opts != nullptr && opts->error != nullptr) { - opts->error->error_message = XML_ErrorString(XML_GetErrorCode(parse_info.parser)); - opts->error->error_line = XML_GetCurrentLineNumber(parse_info.parser); - opts->error->error_column = XML_GetCurrentColumnNumber(parse_info.parser); + opts->error->error_message = XML_ErrorString(XML_GetErrorCode(info.parser)); + opts->error->error_line = XML_GetCurrentLineNumber(info.parser); + opts->error->error_column = XML_GetCurrentColumnNumber(info.parser); } - xml_file_free(parse_info.rootnode); - XML_ParserFree(parse_info.parser); + info.rootnode->file_free(); + XML_ParserFree(info.parser); return nullptr; } } while (!done); /* free the parser */ - XML_ParserFree(parse_info.parser); + XML_ParserFree(info.parser); /* return the root node */ - return parse_info.rootnode; + return info.rootnode; } @@ -187,35 +177,35 @@ xml_data_node *xml_file_read(util::core_file &file, xml_parse_options *opts) nodes -------------------------------------------------*/ -xml_data_node *xml_string_read(const char *string, xml_parse_options *opts) +xml_data_node *xml_data_node::string_read(const char *string, xml_parse_options const *opts) { - xml_parse_info parse_info; + xml_parse_info info; int length = (int)strlen(string); /* set up the parser */ - if (!expat_setup_parser(&parse_info, opts)) + if (!expat_setup_parser(info, opts)) return nullptr; /* parse the data */ - if (XML_Parse(parse_info.parser, string, length, 1) == XML_STATUS_ERROR) + if (XML_Parse(info.parser, string, length, 1) == XML_STATUS_ERROR) { if (opts != nullptr && opts->error != nullptr) { - opts->error->error_message = XML_ErrorString(XML_GetErrorCode(parse_info.parser)); - opts->error->error_line = XML_GetCurrentLineNumber(parse_info.parser); - opts->error->error_column = XML_GetCurrentColumnNumber(parse_info.parser); + opts->error->error_message = XML_ErrorString(XML_GetErrorCode(info.parser)); + opts->error->error_line = XML_GetCurrentLineNumber(info.parser); + opts->error->error_column = XML_GetCurrentColumnNumber(info.parser); } - xml_file_free(parse_info.rootnode); - XML_ParserFree(parse_info.parser); + info.rootnode->file_free(); + XML_ParserFree(info.parser); return nullptr; } /* free the parser */ - XML_ParserFree(parse_info.parser); + XML_ParserFree(info.parser); /* return the root node */ - return parse_info.rootnode; + return info.rootnode; } @@ -223,10 +213,10 @@ xml_data_node *xml_string_read(const char *string, xml_parse_options *opts) xml_file_write - write an XML tree to a file -------------------------------------------------*/ -void xml_file_write(xml_data_node *node, util::core_file &file) +void xml_data_node::file_write(util::core_file &file) const { /* ensure this is a root node */ - if (node->name != nullptr) + if (get_name()) return; /* output a simple header */ @@ -234,8 +224,8 @@ void xml_file_write(xml_data_node *node, util::core_file &file) file.printf("<!-- This file is autogenerated; comments and unknown tags will be stripped -->\n"); /* loop over children of the root and output */ - for (node = node->child; node; node = node->next) - write_node_recursive(node, 0, file); + for (xml_data_node const *node = get_first_child(); node; node = node->get_next_sibling()) + node->write_recursive(0, file); } @@ -243,13 +233,13 @@ void xml_file_write(xml_data_node *node, util::core_file &file) xml_file_free - free an XML file object -------------------------------------------------*/ -void xml_file_free(xml_data_node *node) +void xml_data_node::file_free() { /* ensure this is a root node */ - if (node->name != nullptr) + if (get_name()) return; - free_node_recursive(node); + delete this; } @@ -258,58 +248,199 @@ void xml_file_free(xml_data_node *node) XML NODE MANAGEMENT ***************************************************************************/ +xml_data_node::xml_data_node() + : line(0) + , m_next(nullptr) + , m_first_child(nullptr) + , m_name(nullptr) + , m_value(nullptr) + , m_parent(nullptr) + , m_attributes() +{ +} + +xml_data_node::xml_data_node(xml_data_node *parent, const char *name, const char *value) + : line(0) + , m_next(nullptr) + , m_first_child(nullptr) + , m_name(::copystring_lower(name)) + , m_value(::copystring(value)) + , m_parent(parent) + , m_attributes() +{ +} + + /*------------------------------------------------- - xml_count_children - count the number of - child nodes + free_node_recursive - recursively free + the data allocated to an XML node -------------------------------------------------*/ -int xml_count_children(xml_data_node *node) +xml_data_node::~xml_data_node() +{ + /* free name/value */ + if (m_name) + std::free((void *)m_name); + if (m_value) + std::free((void *)m_value); + + /* free the children */ + for (xml_data_node *nchild = nullptr; m_first_child; m_first_child = nchild) + { + /* note the next node and free this node */ + nchild = m_first_child->get_next_sibling(); + delete m_first_child; + } +} + + +void xml_data_node::set_value(char const *value) +{ + if (m_value) + std::free((void *)m_value); + + m_value = ::copystring(value); +} + + +void xml_data_node::append_value(char const *value, int length) +{ + if (length) + { + /* determine how much data we currently have */ + int const oldlen = m_value ? int(std::strlen(m_value)) : 0; + + /* realloc */ + char *const newdata = reinterpret_cast<char *>(std::malloc(oldlen + length + 1)); + if (newdata) + { + if (m_value) + { + std::memcpy(newdata, m_value, oldlen); + std::free((void *)m_value); + } + m_value = newdata; + + /* copy in the new data and NUL-terminate */ + std::memcpy(&newdata[oldlen], value, length); + newdata[oldlen + length] = '\0'; + } + } +} + + +void xml_data_node::trim_whitespace() +{ + if (m_value) + { + char *start = m_value; + char *end = start + strlen(m_value); + + /* first strip leading spaces */ + while (*start && std::isspace(uint8_t(*start))) + start++; + + /* then strip trailing spaces */ + while ((end > start) && std::isspace(uint8_t(end[-1]))) + end--; + + if (start == end) + { + /* if nothing left, just free it */ + std::free(m_value); + m_value = nullptr; + } + else + { + /* otherwise, memmove the data */ + std::memmove(m_value, start, end - start); + m_value[end - start] = '\0'; + } + } +} + + +/*------------------------------------------------- + xml_data_node::count_children - count the + number of child nodes +-------------------------------------------------*/ + +int xml_data_node::count_children() const { int count = 0; /* loop over children and count */ - for (node = node->child; node; node = node->next) + for (xml_data_node const *node = get_first_child(); node; node = node->get_next_sibling()) count++; return count; } /*------------------------------------------------- - xml_get_sibling - find the next sibling of - the specified node with the specified tag + xml_data_node::get_child - find the first + child of the specified node with the specified + tag -------------------------------------------------*/ -xml_data_node *xml_get_sibling(xml_data_node *node, const char *name) +xml_data_node *xml_data_node::get_child(const char *name) { - /* loop over siblings and find a matching name */ - for ( ; node; node = node->next) - if (strcmp(node->name, name) == 0) - return node; - return nullptr; + return m_first_child ? m_first_child->get_sibling(name) : nullptr; +} + +xml_data_node const *xml_data_node::get_child(const char *name) const +{ + return m_first_child ? m_first_child->get_sibling(name) : nullptr; } /*------------------------------------------------- - xml_find_matching_sibling - find the next + xml_find_first_matching_child - find the first + child of the specified node with the + specified tag or attribute/value pair +-------------------------------------------------*/ + +xml_data_node *xml_data_node::find_first_matching_child(const char *name, const char *attribute, const char *matchval) +{ + return m_first_child ? m_first_child->find_matching_sibling(name, attribute, matchval) : nullptr; +} + +xml_data_node const *xml_data_node::find_first_matching_child(const char *name, const char *attribute, const char *matchval) const +{ + return m_first_child ? m_first_child->find_matching_sibling(name, attribute, matchval) : nullptr; +} + + +/*------------------------------------------------- + xml_data_node::get_next_sibling - find the + next sibling of the specified node with the + specified tag +-------------------------------------------------*/ + +xml_data_node *xml_data_node::get_next_sibling(const char *name) +{ + return m_next ? m_next->get_sibling(name) : nullptr; +} + +xml_data_node const *xml_data_node::get_next_sibling(const char *name) const +{ + return m_next ? m_next->get_sibling(name) : nullptr; +} + + +/*------------------------------------------------- + xml_find_next_matching_sibling - find the next sibling of the specified node with the specified tag or attribute/value pair -------------------------------------------------*/ -xml_data_node *xml_find_matching_sibling(xml_data_node *node, const char *name, const char *attribute, const char *matchval) +xml_data_node *xml_data_node::find_next_matching_sibling(const char *name, const char *attribute, const char *matchval) { - /* loop over siblings and find a matching attribute */ - for ( ; node; node = node->next) - { - /* can pass nullptr as a wildcard for the node name */ - if (name == nullptr || strcmp(name, node->name) == 0) - { - /* find a matching attribute */ - xml_attribute_node *attr = xml_get_attribute(node, attribute); - if (attr != nullptr && strcmp(attr->value, matchval) == 0) - return node; - } - } - return nullptr; + return m_next ? m_next->find_matching_sibling(name, attribute, matchval) : nullptr; +} + +xml_data_node const *xml_data_node::find_next_matching_sibling(const char *name, const char *attribute, const char *matchval) const +{ + return m_next ? m_next->find_matching_sibling(name, attribute, matchval) : nullptr; } @@ -318,10 +449,25 @@ xml_data_node *xml_find_matching_sibling(xml_data_node *node, const char *name, given node -------------------------------------------------*/ -xml_data_node *xml_add_child(xml_data_node *node, const char *name, const char *value) +xml_data_node *xml_data_node::add_child(const char *name, const char *value) { - /* just a standard add child */ - return add_child(node, name, value); + /* new element: create a new node */ + xml_data_node *node; + try { node = new xml_data_node(this, name, value); } + catch (...) { return nullptr; } + + if (!node->get_name() || (!node->get_value() && value)) + { + delete node; + return nullptr; + } + + /* add us to the end of the list of siblings */ + xml_data_node **pnode; + for (pnode = &m_first_child; *pnode; pnode = &(*pnode)->m_next) { } + *pnode = node; + + return node; } @@ -330,17 +476,15 @@ xml_data_node *xml_add_child(xml_data_node *node, const char *name, const char * the specified type; if not found, add one -------------------------------------------------*/ -xml_data_node *xml_get_or_add_child(xml_data_node *node, const char *name, const char *value) +xml_data_node *xml_data_node::get_or_add_child(const char *name, const char *value) { - xml_data_node *child; - /* find the child first */ - child = xml_get_sibling(node->child, name); - if (child != nullptr) + xml_data_node *const child = m_first_child->get_sibling(name); + if (child) return child; /* if not found, do a standard add child */ - return add_child(node, name, value); + return add_child(name, value); } @@ -349,20 +493,88 @@ xml_data_node *xml_get_or_add_child(xml_data_node *node, const char *name, const children -------------------------------------------------*/ -void xml_delete_node(xml_data_node *node) +void xml_data_node::delete_node() { - xml_data_node **pnode; - /* first unhook us from the list of children of our parent */ - for (pnode = &node->parent->child; *pnode; pnode = &(*pnode)->next) - if (*pnode == node) + if (m_parent) + { + for (xml_data_node **pnode = &m_parent->m_first_child; *pnode; pnode = &(*pnode)->m_next) { - *pnode = node->next; - break; + if (*pnode == this) + { + *pnode = this->m_next; + break; + } } + } /* now free ourselves and our children */ - free_node_recursive(node); + delete this; +} + + +/*------------------------------------------------- + xml_get_next_sibling - find the next sibling of + the specified node with the specified tag +-------------------------------------------------*/ + +xml_data_node *xml_data_node::get_sibling(const char *name) +{ + /* loop over siblings and find a matching name */ + for (xml_data_node *node = this; node; node = node->get_next_sibling()) + if (strcmp(node->get_name(), name) == 0) + return node; + return nullptr; +} + +xml_data_node const *xml_data_node::get_sibling(const char *name) const +{ + /* loop over siblings and find a matching name */ + for (xml_data_node const *node = this; node; node = node->get_next_sibling()) + if (strcmp(node->get_name(), name) == 0) + return node; + return nullptr; +} + + +/*------------------------------------------------- + xml_find_matching_sibling - find the next + sibling of the specified node with the + specified tag or attribute/value pair +-------------------------------------------------*/ + +xml_data_node *xml_data_node::find_matching_sibling(const char *name, const char *attribute, const char *matchval) +{ + /* loop over siblings and find a matching attribute */ + for (xml_data_node *node = this; node; node = node->get_next_sibling()) + { + /* can pass nullptr as a wildcard for the node name */ + if (!name || !strcmp(name, node->get_name())) + { + /* find a matching attribute */ + attribute_node const *const attr = node->get_attribute(attribute); + if (attr && !strcmp(attr->value.c_str(), matchval)) + return node; + } + } + return nullptr; +} + +xml_data_node const *xml_data_node::find_matching_sibling(const char *name, const char *attribute, const char *matchval) const +{ + /* loop over siblings and find a matching attribute */ + for (xml_data_node const *node = this; node; node = node->get_next_sibling()) + { + /* can pass nullptr as a wildcard for the node name */ + if (!name || !strcmp(name, node->get_name())) + { + /* find a matching attribute */ + attribute_node const *const attr = node->get_attribute(attribute); + if (attr && !strcmp(attr->value.c_str(), matchval)) + return node; + } + } + return nullptr; } @@ -371,19 +583,32 @@ void xml_delete_node(xml_data_node *node) XML ATTRIBUTE MANAGEMENT ***************************************************************************/ +bool xml_data_node::has_attribute(const char *attribute) const +{ + return get_attribute(attribute) != nullptr; +} + + /*------------------------------------------------- xml_get_attribute - get the value of the specified attribute, or nullptr if not found -------------------------------------------------*/ -xml_attribute_node *xml_get_attribute(xml_data_node *node, const char *attribute) +xml_data_node::attribute_node *xml_data_node::get_attribute(const char *attribute) { - xml_attribute_node *anode; + /* loop over attributes and find a match */ + for (attribute_node &anode : m_attributes) + if (strcmp(anode.name.c_str(), attribute) == 0) + return &anode; + return nullptr; +} +xml_data_node::attribute_node const *xml_data_node::get_attribute(const char *attribute) const +{ /* loop over attributes and find a match */ - for (anode = node->attribute; anode; anode = anode->next) - if (strcmp(anode->name, attribute) == 0) - return anode; + for (attribute_node const &anode : m_attributes) + if (strcmp(anode.name.c_str(), attribute) == 0) + return &anode; return nullptr; } @@ -394,10 +619,10 @@ xml_attribute_node *xml_get_attribute(xml_data_node *node, const char *attribute found, return = the provided default -------------------------------------------------*/ -const char *xml_get_attribute_string(xml_data_node *node, const char *attribute, const char *defvalue) +const char *xml_data_node::get_attribute_string(const char *attribute, const char *defvalue) const { - xml_attribute_node *attr = xml_get_attribute(node, attribute); - return attr ? attr->value : defvalue; + attribute_node const *attr = get_attribute(attribute); + return attr ? attr->value.c_str() : defvalue; } @@ -407,9 +632,9 @@ const char *xml_get_attribute_string(xml_data_node *node, const char *attribute, found, return = the provided default -------------------------------------------------*/ -int xml_get_attribute_int(xml_data_node *node, const char *attribute, int defvalue) +int xml_data_node::get_attribute_int(const char *attribute, int defvalue) const { - const char *string = xml_get_attribute_string(node, attribute, nullptr); + char const *const string = get_attribute_string(attribute, nullptr); int value; unsigned int uvalue; @@ -430,9 +655,9 @@ int xml_get_attribute_int(xml_data_node *node, const char *attribute, int defval format of the given integer attribute -------------------------------------------------*/ -int xml_get_attribute_int_format(xml_data_node *node, const char *attribute) +int xml_data_node::get_attribute_int_format(const char *attribute) const { - const char *string = xml_get_attribute_string(node, attribute, nullptr); + char const *const string = get_attribute_string(attribute, nullptr); if (string == nullptr) return XML_INT_FORMAT_DECIMAL; @@ -452,21 +677,9 @@ int xml_get_attribute_int_format(xml_data_node *node, const char *attribute) found, return = the provided default -------------------------------------------------*/ -/** - * @fn float xml_get_attribute_float(xml_data_node *node, const char *attribute, float defvalue) - * - * @brief XML get attribute float. - * - * @param [in,out] node If non-null, the node. - * @param attribute The attribute. - * @param defvalue The defvalue. - * - * @return A float. - */ - -float xml_get_attribute_float(xml_data_node *node, const char *attribute, float defvalue) +float xml_data_node::get_attribute_float(const char *attribute, float defvalue) const { - const char *string = xml_get_attribute_string(node, attribute, nullptr); + char const *const string = get_attribute_string(attribute, nullptr); float value; if (string == nullptr || sscanf(string, "%f", &value) != 1) @@ -480,38 +693,23 @@ float xml_get_attribute_float(xml_data_node *node, const char *attribute, float string value on the node -------------------------------------------------*/ -/** - * @fn xml_attribute_node *xml_set_attribute(xml_data_node *node, const char *name, const char *value) - * - * @brief XML set attribute. - * - * @param [in,out] node If non-null, the node. - * @param name The name. - * @param value The value. - * - * @return null if it fails, else an xml_attribute_node*. - */ - -xml_attribute_node *xml_set_attribute(xml_data_node *node, const char *name, const char *value) +void xml_data_node::set_attribute(const char *name, const char *value) { - xml_attribute_node *anode; + attribute_node *anode; /* first find an existing one to replace */ - anode = xml_get_attribute(node, name); + anode = get_attribute(name); - /* if we found it, free the old value and replace it */ if (anode != nullptr) { - if (anode->value != nullptr) - free((void *)anode->value); - anode->value = copystring(value); + /* if we found it, free the old value and replace it */ + anode->value = value; } - - /* otherwise, create a new node */ else - anode = add_attribute(node, name, value); - - return anode; + { + /* otherwise, create a new node */ + add_attribute(name, value); + } } @@ -520,23 +718,11 @@ xml_attribute_node *xml_set_attribute(xml_data_node *node, const char *name, con integer value on the node -------------------------------------------------*/ -/** - * @fn xml_attribute_node *xml_set_attribute_int(xml_data_node *node, const char *name, int value) - * - * @brief XML set attribute int. - * - * @param [in,out] node If non-null, the node. - * @param name The name. - * @param value The value. - * - * @return null if it fails, else an xml_attribute_node*. - */ - -xml_attribute_node *xml_set_attribute_int(xml_data_node *node, const char *name, int value) +void xml_data_node::set_attribute_int(const char *name, int value) { char buffer[100]; sprintf(buffer, "%d", value); - return xml_set_attribute(node, name, buffer); + set_attribute(name, buffer); } @@ -545,23 +731,11 @@ xml_attribute_node *xml_set_attribute_int(xml_data_node *node, const char *name, float value on the node -------------------------------------------------*/ -/** - * @fn xml_attribute_node *xml_set_attribute_float(xml_data_node *node, const char *name, float value) - * - * @brief XML set attribute float. - * - * @param [in,out] node If non-null, the node. - * @param name The name. - * @param value The value. - * - * @return null if it fails, else an xml_attribute_node*. - */ - -xml_attribute_node *xml_set_attribute_float(xml_data_node *node, const char *name, float value) +void xml_data_node::set_attribute_float(const char *name, float value) { char buffer[100]; sprintf(buffer, "%f", (double) value); - return xml_set_attribute(node, name, buffer); + set_attribute(name, buffer); } @@ -575,16 +749,6 @@ xml_attribute_node *xml_set_attribute_float(xml_data_node *node, const char *nam to ensure it doesn't contain embedded tags -------------------------------------------------*/ -/** - * @fn const char *xml_normalize_string(const char *string) - * - * @brief XML normalize string. - * - * @param string The string. - * - * @return null if it fails, else a char*. - */ - const char *xml_normalize_string(const char *string) { static char buffer[1024]; @@ -623,16 +787,6 @@ const char *xml_normalize_string(const char *string) systems -------------------------------------------------*/ -/** - * @fn static void *expat_malloc(size_t size) - * - * @brief Expat malloc. - * - * @param size The size. - * - * @return null if it fails, else a void*. - */ - static void *expat_malloc(size_t size) { uint32_t *result = (uint32_t *)malloc(size + 4 * sizeof(uint32_t)); @@ -640,31 +794,12 @@ static void *expat_malloc(size_t size) return &result[4]; } -/** - * @fn static void expat_free(void *ptr) - * - * @brief Expat free. - * - * @param [in,out] ptr If non-null, the pointer. - */ - static void expat_free(void *ptr) { if (ptr != nullptr) free(&((uint32_t *)ptr)[-4]); } -/** - * @fn static void *expat_realloc(void *ptr, size_t size) - * - * @brief Expat realloc. - * - * @param [in,out] ptr If non-null, the pointer. - * @param size The size. - * - * @return null if it fails, else a void*. - */ - static void *expat_realloc(void *ptr, size_t size) { void *newptr = expat_malloc(size); @@ -684,26 +819,15 @@ static void *expat_realloc(void *ptr, size_t size) expat_setup_parser - set up expat for parsing -------------------------------------------------*/ -/** - * @fn static int expat_setup_parser(xml_parse_info *parse_info, xml_parse_options *opts) - * - * @brief Expat setup parser. - * - * @param [in,out] parse_info If non-null, information describing the parse. - * @param [in,out] opts If non-null, options for controlling the operation. - * - * @return An int. - */ - -static bool expat_setup_parser(xml_parse_info *parse_info, xml_parse_options *opts) +static bool expat_setup_parser(xml_parse_info &info, xml_parse_options const *opts) { XML_Memory_Handling_Suite memcallbacks; - /* setup parse_info structure */ - memset(parse_info, 0, sizeof(*parse_info)); + /* setup info structure */ + memset(&info, 0, sizeof(info)); if (opts != nullptr) { - parse_info->flags = opts->flags; + info.flags = opts->flags; if (opts->error != nullptr) { opts->error->error_message = nullptr; @@ -713,30 +837,30 @@ static bool expat_setup_parser(xml_parse_info *parse_info, xml_parse_options *op } /* create a root node */ - parse_info->rootnode = xml_file_create(); - if (parse_info->rootnode == nullptr) + info.rootnode = xml_data_node::file_create(); + if (info.rootnode == nullptr) return false; - parse_info->curnode = parse_info->rootnode; + info.curnode = info.rootnode; /* create the XML parser */ memcallbacks.malloc_fcn = expat_malloc; memcallbacks.realloc_fcn = expat_realloc; memcallbacks.free_fcn = expat_free; - parse_info->parser = XML_ParserCreate_MM(nullptr, &memcallbacks, nullptr); - if (parse_info->parser == nullptr) + info.parser = XML_ParserCreate_MM(nullptr, &memcallbacks, nullptr); + if (info.parser == nullptr) { - free(parse_info->rootnode); + info.rootnode->file_free(); return false; } /* configure the parser */ - XML_SetElementHandler(parse_info->parser, expat_element_start, expat_element_end); - XML_SetCharacterDataHandler(parse_info->parser, expat_data); - XML_SetUserData(parse_info->parser, parse_info); + XML_SetElementHandler(info.parser, expat_element_start, expat_element_end); + XML_SetCharacterDataHandler(info.parser, expat_data); + XML_SetUserData(info.parser, &info); /* optional parser initialization step */ if (opts != nullptr && opts->init_parser != nullptr) - (*opts->init_parser)(parse_info->parser); + (*opts->init_parser)(info.parser); return true; } @@ -746,16 +870,6 @@ static bool expat_setup_parser(xml_parse_info *parse_info, xml_parse_options *op element -------------------------------------------------*/ -/** - * @fn static void expat_element_start(void *data, const XML_Char *name, const XML_Char **attributes) - * - * @brief Expat element start. - * - * @param [in,out] data If non-null, the data. - * @param name The name. - * @param attributes The attributes. - */ - static void expat_element_start(void *data, const XML_Char *name, const XML_Char **attributes) { xml_parse_info *parse_info = (xml_parse_info *) data; @@ -764,7 +878,7 @@ static void expat_element_start(void *data, const XML_Char *name, const XML_Char int attr; /* add a new child node to the current node */ - newnode = add_child(*curnode, name, nullptr); + newnode = (*curnode)->add_child(name, nullptr); if (newnode == nullptr) return; @@ -773,7 +887,7 @@ static void expat_element_start(void *data, const XML_Char *name, const XML_Char /* add all the attributes as well */ for (attr = 0; attributes[attr]; attr += 2) - add_attribute(newnode, attributes[attr+0], attributes[attr+1]); + newnode->add_attribute(attributes[attr+0], attributes[attr+1]); /* set us up as the current node */ *curnode = newnode; @@ -785,46 +899,11 @@ static void expat_element_start(void *data, const XML_Char *name, const XML_Char element data -------------------------------------------------*/ -/** - * @fn static void expat_data(void *data, const XML_Char *s, int len) - * - * @brief Expat data. - * - * @param [in,out] data If non-null, the data. - * @param s The const XML_Char * to process. - * @param len The length. - */ - static void expat_data(void *data, const XML_Char *s, int len) { xml_parse_info *parse_info = (xml_parse_info *) data; xml_data_node **curnode = &parse_info->curnode; - int oldlen = 0; - char *newdata; - - /* if no data, skip */ - if (len == 0) - return; - - /* determine how much data we currently have */ - if ((*curnode)->value != nullptr) - oldlen = (int)strlen((*curnode)->value); - - /* realloc */ - newdata = (char *)malloc(oldlen + len + 1); - if (newdata == nullptr) - return; - if ((*curnode)->value != nullptr) - { - memcpy(newdata, (*curnode)->value, oldlen); - free((void *)(*curnode)->value); - } - (*curnode)->value = newdata; - - /* copy in the new data a NULL-terminate */ - memcpy(&newdata[oldlen], s, len); - newdata[oldlen + len] = 0; - (*curnode)->value = newdata; + (*curnode)->append_value(s, len); } @@ -833,53 +912,17 @@ static void expat_data(void *data, const XML_Char *s, int len) of an element -------------------------------------------------*/ -/** - * @fn static void expat_element_end(void *data, const XML_Char *name) - * - * @brief Expat element end. - * - * @param [in,out] data If non-null, the data. - * @param name The name. - */ - static void expat_element_end(void *data, const XML_Char *name) { xml_parse_info *parse_info = (xml_parse_info *) data; xml_data_node **curnode = &parse_info->curnode; - char *orig; /* strip leading/trailing spaces from the value data */ - orig = (char *)(*curnode)->value; - if (orig != nullptr && !(parse_info->flags & XML_PARSE_FLAG_WHITESPACE_SIGNIFICANT)) - { - char *start = orig; - char *end = start + strlen(start); - - /* first strip leading spaces */ - while (*start && isspace((uint8_t)*start)) - start++; - - /* then strip trailing spaces */ - while (end > start && isspace((uint8_t)end[-1])) - end--; - - /* if nothing left, just free it */ - if (start == end) - { - free(orig); - (*curnode)->value = nullptr; - } - - /* otherwise, memmove the data */ - else - { - memmove(orig, start, end - start); - orig[end - start] = 0; - } - } + if (!(parse_info->flags & XML_PARSE_FLAG_WHITESPACE_SIGNIFICANT)) + (*curnode)->trim_whitespace(); /* back us up a node */ - *curnode = (*curnode)->parent; + *curnode = (*curnode)->get_parent(); } @@ -889,105 +932,20 @@ static void expat_element_end(void *data, const XML_Char *name) ***************************************************************************/ /*------------------------------------------------- - add_child - add a new node to the parent --------------------------------------------------*/ - -/** - * @fn static xml_data_node *add_child(xml_data_node *parent, const char *name, const char *value) - * - * @brief Adds a child. - * - * @param [in,out] parent If non-null, the parent. - * @param name The name. - * @param value The value. - * - * @return null if it fails, else an xml_data_node*. - */ - -static xml_data_node *add_child(xml_data_node *parent, const char *name, const char *value) -{ - xml_data_node **pnode; - xml_data_node *node; - - /* new element: create a new node */ - node = (xml_data_node *)malloc(sizeof(*node)); - if (node == nullptr) - return nullptr; - - /* initialize the members */ - node->next = nullptr; - node->parent = parent; - node->child = nullptr; - node->name = copystring_lower(name); - if (node->name == nullptr) - { - free(node); - return nullptr; - } - node->value = copystring(value); - if (node->value == nullptr && value != nullptr) - { - free((void *)node->name); - free(node); - return nullptr; - } - node->attribute = nullptr; - - /* add us to the end of the list of siblings */ - for (pnode = &parent->child; *pnode; pnode = &(*pnode)->next) { } - *pnode = node; - - return node; -} - - -/*------------------------------------------------- add_attribute - add a new attribute to the given node -------------------------------------------------*/ -/** - * @fn static xml_attribute_node *add_attribute(xml_data_node *node, const char *name, const char *value) - * - * @brief Adds an attribute. - * - * @param [in,out] node If non-null, the node. - * @param name The name. - * @param value The value. - * - * @return null if it fails, else an xml_attribute_node*. - */ - -static xml_attribute_node *add_attribute(xml_data_node *node, const char *name, const char *value) +void xml_data_node::add_attribute(const char *name, const char *value) { - xml_attribute_node *anode, **panode; - - /* allocate a new attribute node */ - anode = (xml_attribute_node *)malloc(sizeof(*anode)); - if (anode == nullptr) - return nullptr; - - /* fill it in */ - anode->next = nullptr; - anode->name = copystring_lower(name); - if (anode->name == nullptr) + try { - free(anode); - return nullptr; + attribute_node &anode = *m_attributes.emplace(m_attributes.end(), name, value); + std::transform(anode.name.begin(), anode.name.end(), anode.name.begin(), [] (char ch) { return std::tolower(uint8_t(ch)); }); } - anode->value = copystring(value); - if (anode->value == nullptr) + catch (...) { - free((void *)anode->name); - free(anode); - return nullptr; } - - /* add us to the end of the list of attributes */ - for (panode = &node->attribute; *panode; panode = &(*panode)->next) { } - *panode = anode; - - return anode; } @@ -1001,100 +959,37 @@ static xml_attribute_node *add_attribute(xml_data_node *node, const char *name, an XML node and its children to a file -------------------------------------------------*/ -/** - * @fn static void write_node_recursive(xml_data_node *node, int indent, util::core_file &file) - * - * @brief Writes a node recursive. - * - * @param [in,out] node If non-null, the node. - * @param indent The indent. - * @param [in,out] file If non-null, the file. - */ - -static void write_node_recursive(xml_data_node *node, int indent, util::core_file &file) +void xml_data_node::write_recursive(int indent, util::core_file &file) const { - xml_attribute_node *anode; - xml_data_node *child; - /* output this tag */ - file.printf("%*s<%s", indent, "", node->name); + file.printf("%*s<%s", indent, "", get_name()); /* output any attributes */ - for (anode = node->attribute; anode; anode = anode->next) - file.printf(" %s=\"%s\"", anode->name, anode->value); + for (attribute_node const &anode : m_attributes) + file.printf(" %s=\"%s\"", anode.name, anode.value); - /* if there are no children and no value, end the tag here */ - if (node->child == nullptr && node->value == nullptr) + if (!get_first_child() && !get_value()) + { + /* if there are no children and no value, end the tag here */ file.printf(" />\n"); - - /* otherwise, close this tag and output more stuff */ + } else { + /* otherwise, close this tag and output more stuff */ file.printf(">\n"); /* if there is a value, output that here */ - if (node->value != nullptr) - file.printf("%*s%s\n", indent + 4, "", node->value); + if (get_value()) + file.printf("%*s%s\n", indent + 4, "", get_value()); /* loop over children and output them as well */ - if (node->child != nullptr) + if (get_first_child()) { - for (child = node->child; child; child = child->next) - write_node_recursive(child, indent + 4, file); + for (xml_data_node const *child = this->get_first_child(); child; child = child->get_next_sibling()) + child->write_recursive(indent + 4, file); } /* write a closing tag */ - file.printf("%*s</%s>\n", indent, "", node->name); - } -} - - -/*------------------------------------------------- - free_node_recursive - recursively free - the data allocated to an XML node --------------------------------------------------*/ - -/** - * @fn static void free_node_recursive(xml_data_node *node) - * - * @brief Free node recursive. - * - * @param [in,out] node If non-null, the node. - */ - -static void free_node_recursive(xml_data_node *node) -{ - xml_attribute_node *anode, *nanode; - xml_data_node *child, *nchild; - - /* free name/value */ - if (node->name != nullptr) - free((void *)node->name); - if (node->value != nullptr) - free((void *)node->value); - - /* free attributes */ - for (anode = node->attribute; anode; anode = nanode) - { - /* free name/value */ - if (anode->name != nullptr) - free((void *)anode->name); - if (anode->value != nullptr) - free((void *)anode->value); - - /* note the next node and free this node */ - nanode = anode->next; - free(anode); - } - - /* free the children */ - for (child = node->child; child; child = nchild) - { - /* note the next node and free this node */ - nchild = child->next; - free_node_recursive(child); + file.printf("%*s</%s>\n", indent, "", get_name()); } - - /* finally free ourself */ - free(node); } diff --git a/src/lib/util/xmlfile.h b/src/lib/util/xmlfile.h index eac3cdff4c2..6696b636774 100644 --- a/src/lib/util/xmlfile.h +++ b/src/lib/util/xmlfile.h @@ -10,12 +10,16 @@ #pragma once -#ifndef __XMLFILE_H__ -#define __XMLFILE_H__ +#ifndef MAME_LIB_UTIL_XMLFILE_H +#define MAME_LIB_UTIL_XMLFILE_H #include "osdcore.h" #include "corefile.h" +#include <list> +#include <string> +#include <utility> + /*************************************************************************** CONSTANTS @@ -41,32 +45,10 @@ enum TYPE DEFINITIONS ***************************************************************************/ -/* forward type declarations */ +// forward type declarations struct XML_ParserStruct; -/* a node representing an attribute */ -struct xml_attribute_node -{ - xml_attribute_node * next; /* pointer to next attribute node */ - const char * name; /* pointer to copy of tag name */ - const char * value; /* pointer to copy of value string */ -}; - - -/* a node representing a data item and its relationships */ -struct xml_data_node -{ - xml_data_node * next; /* pointer to next sibling node */ - xml_data_node * parent; /* pointer to parent node */ - xml_data_node * child; /* pointer to first child node */ - const char * name; /* pointer to copy of tag name */ - const char * value; /* pointer to copy of value string */ - xml_attribute_node * attribute; /* pointer to array of attribute nodes */ - int line; /* line number for this node's start */ -}; - - /* extended error information from parsing */ struct xml_parse_error { @@ -76,93 +58,169 @@ struct xml_parse_error }; -/* parsing options */ +// parsing options struct xml_parse_options { xml_parse_error * error; void (*init_parser)(struct XML_ParserStruct *parser); - uint32_t flags; + uint32_t flags; }; +// a node representing a data item and its relationships +class xml_data_node +{ +public: + /* ----- XML file objects ----- */ + + // create a new empty xml file object + static xml_data_node *file_create(); + + // parse an XML file into its nodes */ + static xml_data_node *file_read(util::core_file &file, xml_parse_options const *opts); + + /* parse an XML string into its nodes */ + static xml_data_node *string_read(const char *string, xml_parse_options const *opts); + + // write an XML tree to a file + void file_write(util::core_file &file) const; + + // free an XML file object + void file_free(); -/*************************************************************************** - FUNCTION PROTOTYPES -***************************************************************************/ + /* ----- XML node management ----- */ -/* ----- XML file objects ----- */ + char const *get_name() const { return m_name; } -/* create a new empty xml file object */ -xml_data_node *xml_file_create(void); + char const *get_value() const { return m_value; } + void set_value(char const *value); + void append_value(char const *value, int length); + void trim_whitespace(); -/* parse an XML file into its nodes */ -xml_data_node *xml_file_read(util::core_file &file, xml_parse_options *opts); + xml_data_node *get_parent() { return m_parent; } + xml_data_node const *get_parent() const { return m_parent; } -/* parse an XML string into its nodes */ -xml_data_node *xml_string_read(const char *string, xml_parse_options *opts); + // count the number of child nodes + int count_children() const; -/* write an XML tree to a file */ -void xml_file_write(xml_data_node *node, util::core_file &file); + // get the first child + xml_data_node *get_first_child() { return m_first_child; } + xml_data_node const *get_first_child() const { return m_first_child; } -/* free an XML file object */ -void xml_file_free(xml_data_node *node); + // find the first child with the given tag + xml_data_node *get_child(const char *name); + xml_data_node const *get_child(const char *name) const; + // find the first child with the given tag and/or attribute/value pair + xml_data_node *find_first_matching_child(const char *name, const char *attribute, const char *matchval); + xml_data_node const *find_first_matching_child(const char *name, const char *attribute, const char *matchval) const; + // get the next sibling + xml_data_node *get_next_sibling() { return m_next; } + xml_data_node const *get_next_sibling() const { return m_next; } -/* ----- XML node management ----- */ + // find the next sibling with the given tag + xml_data_node *get_next_sibling(const char *name); + xml_data_node const *get_next_sibling(const char *name) const; -/* count the number of child nodes */ -int xml_count_children(xml_data_node *node); + // find the next sibling with the given tag and/or attribute/value pair + xml_data_node *find_next_matching_sibling(const char *name, const char *attribute, const char *matchval); + xml_data_node const *find_next_matching_sibling(const char *name, const char *attribute, const char *matchval) const; -/* find the next sibling with the given tag */ -xml_data_node *xml_get_sibling(xml_data_node *node, const char *name); + // add a new child node + xml_data_node *add_child(const char *name, const char *value); -/* find the next sibling with the given tag and/or attribute/value pair */ -xml_data_node *xml_find_matching_sibling(xml_data_node *node, const char *name, const char *attribute, const char *matchval); + // either return an existing child node or create one if it doesn't exist + xml_data_node *get_or_add_child(const char *name, const char *value); -/* add a new child node */ -xml_data_node *xml_add_child(xml_data_node *node, const char *name, const char *value); + // delete a node and its children + void delete_node(); -/* either return an existing child node or create one if it doesn't exist */ -xml_data_node *xml_get_or_add_child(xml_data_node *node, const char *name, const char *value); -/* delete a node and its children */ -void xml_delete_node(xml_data_node *node); + /* ----- XML attribute management ----- */ + // return whether a node has the specified attribute + bool has_attribute(const char *attribute) const; -/* ----- XML attribute management ----- */ + // return the string value of an attribute, or the specified default if not present + const char *get_attribute_string(const char *attribute, const char *defvalue) const; -/* find an attribute node with the specified tag */ -xml_attribute_node *xml_get_attribute(xml_data_node *node, const char *attribute); + // return the integer value of an attribute, or the specified default if not present + int get_attribute_int(const char *attribute, int defvalue) const; -/* return the string value of an attribute, or the specified default if not present */ -const char *xml_get_attribute_string(xml_data_node *node, const char *attribute, const char *defvalue); + // return the format of the given integer attribute + int get_attribute_int_format(const char *attribute) const; -/* return the integer value of an attribute, or the specified default if not present */ -int xml_get_attribute_int(xml_data_node *node, const char *attribute, int defvalue); + // return the float value of an attribute, or the specified default if not present + float get_attribute_float(const char *attribute, float defvalue) const; -/* return the format of the given integer attribute */ -int xml_get_attribute_int_format(xml_data_node *node, const char *attribute); + // set the string value of an attribute + void set_attribute(const char *name, const char *value); -/* return the float value of an attribute, or the specified default if not present */ -float xml_get_attribute_float(xml_data_node *node, const char *attribute, float defvalue); + // set the integer value of an attribute + void set_attribute_int(const char *name, int value); -/* set the string value of an attribute */ -xml_attribute_node *xml_set_attribute(xml_data_node *node, const char *name, const char *value); + // set the float value of an attribute + void set_attribute_float(const char *name, float value); -/* set the integer value of an attribute */ -xml_attribute_node *xml_set_attribute_int(xml_data_node *node, const char *name, int value); + // add an attribute even if an attribute with the same name already exists + void add_attribute(const char *name, const char *value); -/* set the float value of an attribute */ -xml_attribute_node *xml_set_attribute_float(xml_data_node *node, const char *name, float value); + int line; /* line number for this node's start */ + + +private: + // a node representing an attribute + struct attribute_node + { + template <typename T, typename U> attribute_node(T &&name, U &&value) : name(std::forward<T>(name)), value(std::forward<U>(value)) { } + + std::string name; + std::string value; + }; + + + xml_data_node(); + xml_data_node(xml_data_node *parent, const char *name, const char *value); + ~xml_data_node(); + + xml_data_node(xml_data_node const &) = delete; + xml_data_node(xml_data_node &&) = delete; + xml_data_node &operator=(xml_data_node &&) = delete; + xml_data_node &operator=(xml_data_node const &) = delete; + + xml_data_node *get_sibling(const char *name); + xml_data_node const *get_sibling(const char *name) const; + xml_data_node *find_matching_sibling(const char *name, const char *attribute, const char *matchval); + xml_data_node const *find_matching_sibling(const char *name, const char *attribute, const char *matchval) const; + + attribute_node *get_attribute(const char *attribute); + attribute_node const *get_attribute(const char *attribute) const; + + void write_recursive(int indent, util::core_file &file) const; + + + xml_data_node * m_next; + xml_data_node * m_first_child; + char const * m_name; + char * m_value; + xml_data_node * m_parent; + std::list<attribute_node> m_attributes; +}; + + + +/*************************************************************************** + FUNCTION PROTOTYPES +***************************************************************************/ /* ----- miscellaneous interfaces ----- */ /* normalize a string into something that can be written to an XML file */ const char *xml_normalize_string(const char *string); -#endif /* __XMLFILE_H__ */ +#endif /* MAME_LIB_UTIL_XMLFILE_H */ |