From aa2613c7037bd12448d58714b4bb317ea939d892 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 19 Jan 2025 20:29:13 +0100 Subject: Wrapped xmlNodePtr access with a Node class Slightly more ergonomic and this eliminates direct libxml2 usage from many places. --- src/utils/xml.cpp | 72 ------------------------------------------------------- 1 file changed, 72 deletions(-) (limited to 'src/utils/xml.cpp') diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index a1b1fa75..7ea5b9d6 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -21,14 +21,12 @@ #include "utils/xml.h" -#include #include #include "log.h" #include "resources/resourcemanager.h" -#include "utils/stringutils.h" #include "utils/zlib.h" namespace XML @@ -102,76 +100,6 @@ namespace XML xmlFreeDoc(mDoc); } - xmlNodePtr Document::rootNode() - { - return mDoc ? xmlDocGetRootElement(mDoc) : nullptr; - } - - bool hasProperty(xmlNodePtr node, const char *name) - { - return xmlHasProp(node, BAD_CAST name) != nullptr; - } - - int getProperty(xmlNodePtr node, const char* name, int def) - { - int &ret = def; - - if (xmlChar *prop = xmlGetProp(node, BAD_CAST name)) - { - ret = atol((char*)prop); - xmlFree(prop); - } - - return ret; - } - - double getFloatProperty(xmlNodePtr node, const char* name, double def) - { - double &ret = def; - - if (xmlChar *prop = xmlGetProp(node, BAD_CAST name)) - { - ret = atof((char*)prop); - xmlFree(prop); - } - - return ret; - } - - std::string getProperty(xmlNodePtr node, const char *name, - const std::string &def) - { - if (xmlChar *prop = xmlGetProp(node, BAD_CAST name)) - { - std::string val = (char*)prop; - xmlFree(prop); - return val; - } - - return def; - } - - bool getBoolProperty(xmlNodePtr node, const char* name, bool def) - { - bool ret = def; - - if (xmlChar *prop = xmlGetProp(node, BAD_CAST name)) - { - ret = getBoolFromString((char*) prop, def); - xmlFree(prop); - } - return ret; - } - - xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name) - { - for (auto child : XML::Children(parent)) - if (xmlStrEqual(child->name, BAD_CAST name)) - return child; - - return nullptr; - } - void init() { // Initialize libxml2 and check for potential ABI mismatches between -- cgit v1.2.3-70-g09d2