From 8318453bf9d4fd50b137ff6c6fc8d1fd22aa6395 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:07:15 +0200 Subject: 3.7 --- shared/xmlBase.h | 130 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 95 insertions(+), 35 deletions(-) (limited to 'shared/xmlBase.h') diff --git a/shared/xmlBase.h b/shared/xmlBase.h index ceed1afe..62927cae 100644 --- a/shared/xmlBase.h +++ b/shared/xmlBase.h @@ -8,9 +8,11 @@ #define XMLBASE_H_INCLUDED #include "tinyxml/tinyxml.h" +#include "globalFunctions.h" #include #include #include +#include "xmlError.h" namespace xmlAccess @@ -35,32 +37,31 @@ void saveXmlDocument(const wxString& fileName, const TiXmlDocument& document); / //------------------------------------------------------------------------------------------ //small helper functions +template +bool readXmlElement(const std::string& name, const TiXmlElement* parent, T& output); bool readXmlElement(const std::string& name, const TiXmlElement* parent, std::string& output); bool readXmlElement(const std::string& name, const TiXmlElement* parent, wxString& output); -bool readXmlElement(const std::string& name, const TiXmlElement* parent, int& output); -bool readXmlElement(const std::string& name, const TiXmlElement* parent, unsigned int& output); -bool readXmlElement(const std::string& name, const TiXmlElement* parent, long& output); bool readXmlElement(const std::string& name, const TiXmlElement* parent, bool& output); bool readXmlElement(const std::string& name, const TiXmlElement* parent, std::vector& output); + +template +bool readXmlAttribute(const std::string& name, const TiXmlElement* node, T& output); bool readXmlAttribute(const std::string& name, const TiXmlElement* node, std::string& output); bool readXmlAttribute(const std::string& name, const TiXmlElement* node, wxString& output); -bool readXmlAttribute(const std::string& name, const TiXmlElement* node, int& output); -bool readXmlAttribute(const std::string& name, const TiXmlElement* node, unsigned int& output); bool readXmlAttribute(const std::string& name, const TiXmlElement* node, bool& output); +template +void addXmlElement(const std::string& name, T value, TiXmlElement* parent); void addXmlElement(const std::string& name, const std::string& value, TiXmlElement* parent); void addXmlElement(const std::string& name, const wxString& value, TiXmlElement* parent); -void addXmlElement(const std::string& name, const int value, TiXmlElement* parent); -void addXmlElement(const std::string& name, const unsigned int value, TiXmlElement* parent); -void addXmlElement(const std::string& name, const long value, TiXmlElement* parent); void addXmlElement(const std::string& name, const bool value, TiXmlElement* parent); void addXmlElement(const std::string& name, const std::vector& value, TiXmlElement* parent); +template +void addXmlAttribute(const std::string& name, T value, TiXmlElement* node); void addXmlAttribute(const std::string& name, const std::string& value, TiXmlElement* node); void addXmlAttribute(const std::string& name, const wxString& value, TiXmlElement* node); -void addXmlAttribute(const std::string& name, const int value, TiXmlElement* node); -void addXmlAttribute(const std::string& name, const unsigned int value, TiXmlElement* node); void addXmlAttribute(const std::string& name, const bool value, TiXmlElement* node); @@ -99,31 +100,6 @@ private: const TiXmlElement* const root; std::vector failedNodes; }; - - -class XmlError //Exception class -{ -public: - enum Severity - { - WARNING = 77, - FATAL - }; - - XmlError(const wxString& message, Severity sev = FATAL) : errorMessage(message), m_severity(sev) {} - - const wxString& show() const - { - return errorMessage; - } - Severity getSeverity() const - { - return m_severity; - } -private: - const wxString errorMessage; - const Severity m_severity; -}; } @@ -147,4 +123,88 @@ private: }; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +//++++++++++++++ inline implementation +++++++++++++++++++++++++++++++++++++++ +template +inline +bool xmlAccess::readXmlElement(const std::string& name, const TiXmlElement* parent, T& output) +{ + std::string temp; + if (!readXmlElement(name, parent, temp)) + return false; + + globalFunctions::stringToNumber(temp, output); + return true; +} + + +template +inline +void xmlAccess::addXmlElement(const std::string& name, T value, TiXmlElement* parent) +{ + addXmlElement(name, globalFunctions::numberToString(value), parent); +} + + +template +inline +bool xmlAccess::readXmlAttribute(const std::string& name, const TiXmlElement* node, T& output) +{ + std::string dummy; + if (readXmlAttribute(name, node, dummy)) + { + globalFunctions::stringToNumber(dummy, output); + return true; + } + else + return false; +} + + +template +inline +void xmlAccess::addXmlAttribute(const std::string& name, T value, TiXmlElement* node) +{ + addXmlAttribute(name, globalFunctions::numberToString(value), node); +} + #endif // XMLBASE_H_INCLUDED -- cgit