diff options
author | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2018-01-08 20:09:35 -0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-08 20:09:35 -0200 |
commit | 29af4e28898f44df444fef5534134c6b6000418d (patch) | |
tree | 13fd8f4449f2cfeed8a6185e96a6889f9529285d /Project/XMLParser.cpp | |
parent | 0c0280cfcf540f943fd2dbfdf7ac0304ea96a465 (diff) | |
parent | c11a42ee83fcf535557d4f2cc259efae2da1b7ff (diff) | |
download | PSP.git-29af4e28898f44df444fef5534134c6b6000418d.tar.gz PSP.git-29af4e28898f44df444fef5534134c6b6000418d.tar.xz PSP.git-29af4e28898f44df444fef5534134c6b6000418d.zip |
Merge pull request #44 from Thales1330/org/file-handling-and-ctrl-init
Org file handling and ctrl init
Diffstat (limited to 'Project/XMLParser.cpp')
-rw-r--r-- | Project/XMLParser.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/Project/XMLParser.cpp b/Project/XMLParser.cpp new file mode 100644 index 0000000..0d1588e --- /dev/null +++ b/Project/XMLParser.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2018 Thales Lima Oliveira <thales@ufu.br> + * + * 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 <https://www.gnu.org/licenses/>. + */ + +#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; +} |