From cef9e14b989a3ba19321e4fe215ada2ee3998037 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Wed, 3 Jan 2018 19:01:57 -0200 Subject: Some file hand. organization and generalization --- Project/XMLParser.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Project/XMLParser.cpp (limited to 'Project/XMLParser.cpp') diff --git a/Project/XMLParser.cpp b/Project/XMLParser.cpp new file mode 100644 index 0000000..09fa2cc --- /dev/null +++ b/Project/XMLParser.cpp @@ -0,0 +1,98 @@ +#include "XMLParser.h" + +XMLParser::XMLParser() {} + +XMLParser::~XMLParser() {} + +rapidxml::xml_node<>* XMLParser::AppendNode(rapidxml::xml_document<>& doc, + rapidxml::xml_node<>* parentNode, + const char* name, + rapidxml::node_type nodeType) +{ + rapidxml::xml_node<>* node = doc.allocate_node(nodeType, name); + parentNode->append_node(node); + return node; +} + +void XMLParser::SetNodeValue(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* node, wxString value) +{ + node->value(doc.allocate_string(value.mb_str())); +} + +void XMLParser::SetNodeValue(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* node, int value) +{ + node->value(doc.allocate_string(wxString::Format("%d", value).mb_str())); +} + +void XMLParser::SetNodeValue(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* node, double value) +{ + node->value(doc.allocate_string(wxString::FromCDouble(value, 13).mb_str())); +} + +void XMLParser::SetNodeAttribute(rapidxml::xml_document<>& doc, + rapidxml::xml_node<>* node, + const char* atrName, + wxString value) +{ + node->append_attribute(doc.allocate_attribute(atrName, doc.allocate_string(value.mb_str()))); +} + +void XMLParser::SetNodeAttribute(rapidxml::xml_document<>& doc, + rapidxml::xml_node<>* node, + const char* atrName, + int value) +{ + node->append_attribute( + doc.allocate_attribute(atrName, doc.allocate_string(wxString::Format("%d", value).mb_str()))); +} + +void XMLParser::SetNodeAttribute(rapidxml::xml_document<>& doc, + rapidxml::xml_node<>* node, + const char* atrName, + double value) +{ + node->append_attribute( + doc.allocate_attribute(atrName, doc.allocate_string(wxString::FromCDouble(value, 13).mb_str()))); +} + +double XMLParser::GetNodeValueDouble(rapidxml::xml_node<>* parent, const char* nodeName) +{ + double dValue = 0.0; + if(parent) { + auto node = parent->first_node(nodeName); + if(node) wxString(node->value()).ToCDouble(&dValue); + } + return dValue; +} + +int XMLParser::GetNodeValueInt(rapidxml::xml_node<>* parent, const char* nodeName) +{ + long iValue = -1; + if(parent) { + auto node = parent->first_node(nodeName); + if(node) wxString(node->value()).ToCLong(&iValue); + } + return (int)iValue; +} + +int XMLParser::GetAttributeValueInt(rapidxml::xml_node<>* parent, const char* nodeName, const char* atrName) +{ + long iValue = -1; + if(parent) { + auto node = parent->first_node(nodeName); + if(node) { + auto atr = node->first_attribute(atrName); + if(atr) wxString(atr->value()).ToCLong(&iValue); + } + } + return (int)iValue; +} + +int XMLParser::GetAttributeValueInt(rapidxml::xml_node<>* node, const char* atrName) +{ + long intValue; + auto atr = node->first_attribute(atrName); + if(!atr) return false; + wxString(atr->value()).ToCLong(&intValue); + return (int)intValue; +} -- cgit From 76df1de5e2307229da9870306e4a1031170aaadf Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Thu, 4 Jan 2018 19:11:08 -0200 Subject: Control elements file handling reorganized --- Project/XMLParser.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Project/XMLParser.cpp') diff --git a/Project/XMLParser.cpp b/Project/XMLParser.cpp index 09fa2cc..0d1588e 100644 --- a/Project/XMLParser.cpp +++ b/Project/XMLParser.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2018 Thales Lima Oliveira + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "XMLParser.h" XMLParser::XMLParser() {} -- cgit