summaryrefslogtreecommitdiff
path: root/shared/xml_base.h
diff options
context:
space:
mode:
Diffstat (limited to 'shared/xml_base.h')
-rw-r--r--shared/xml_base.h67
1 files changed, 28 insertions, 39 deletions
diff --git a/shared/xml_base.h b/shared/xml_base.h
index 44650ec9..337bfbd8 100644
--- a/shared/xml_base.h
+++ b/shared/xml_base.h
@@ -7,33 +7,33 @@
#ifndef XMLBASE_H_INCLUDED
#define XMLBASE_H_INCLUDED
-#include "tinyxml/tinyxml.h"
-#include "global_func.h"
#include <string>
#include <vector>
+#include "tinyxml/tinyxml.h"
+#include "string_tools.h"
#include <wx/string.h>
#include "xml_error.h"
namespace xmlAccess
{
+/* Init XML document:
-enum XmlType
-{
- XML_GUI_CONFIG,
- XML_BATCH_CONFIG,
- XML_GLOBAL_SETTINGS,
- XML_REAL_CONFIG,
- XML_OTHER
-};
-
-XmlType getXmlType(const wxString& filename); //throw()
+ TiXmlDocument doc;
+ TiXmlDeclaration* decl = new TiXmlDeclaration("1.0", "UTF-8", "");
+ doc.LinkEndChild(decl); //ownership passed
-void loadXmlDocument(const wxString& fileName, const XmlType type, TiXmlDocument& document); //throw (XmlError)
-void getDefaultXmlDocument(const XmlType type, TiXmlDocument& document);
+ TiXmlElement* root = new TiXmlElement("HeaderName");
+ doc.LinkEndChild(root);
+*/
+void loadXmlDocument(const wxString& fileName, TiXmlDocument& document); //throw (XmlError)
void saveXmlDocument(const wxString& fileName, const TiXmlDocument& document); //throw (XmlError)
+#ifndef TIXML_USE_STL
+#error we need this macro
+#endif
+
//------------------------------------------------------------------------------------------
//small helper functions
@@ -44,13 +44,6 @@ bool readXmlElement(const std::string& name, const TiXmlElement* parent, wxStrin
bool readXmlElement(const std::string& name, const TiXmlElement* parent, bool& output);
bool readXmlElement(const std::string& name, const TiXmlElement* parent, std::vector<wxString>& output);
-
-template <class T>
-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, bool& output);
-
template <class T>
void addXmlElement(const std::string& name, T value, TiXmlElement* parent);
void addXmlElement(const std::string& name, const std::string& value, TiXmlElement* parent);
@@ -59,6 +52,12 @@ void addXmlElement(const std::string& name, const bool value, TiXmlEleme
void addXmlElement(const std::string& name, const std::vector<wxString>& value, TiXmlElement* parent);
template <class T>
+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, bool& output);
+
+template <class T>
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);
@@ -66,16 +65,15 @@ void addXmlAttribute(const std::string& name, const bool value, TiXmlEle
-class XmlParser
+class XmlErrorLogger
{
public:
- XmlParser(const TiXmlElement* rootElement) : root(rootElement) {}
+ virtual ~XmlErrorLogger() {}
void logError(const std::string& nodeName);
- bool errorsOccurred() const;
+ bool errorsOccurred() const { return !failedNodes.empty(); }
const wxString getErrorMessageFormatted() const;
-protected:
//another level of indirection: if errors occur during xml parsing they are logged
template <class T>
void readXmlElementLogging(const std::string& name, const TiXmlElement* parent, T& output)
@@ -91,13 +89,7 @@ protected:
logError(name);
}
- const TiXmlElement* const getRoot() const
- {
- return root;
- }
-
private:
- const TiXmlElement* const root;
std::vector<wxString> failedNodes;
};
}
@@ -113,10 +105,7 @@ public:
return TiXmlHandleConst(m_element != NULL ? m_element->FirstChildElement(name) : NULL);
}
- const TiXmlElement* ToElement() const
- {
- return m_element;
- }
+ const TiXmlElement* ToElement() const { return m_element; }
private:
const TiXmlElement* const m_element;
@@ -172,7 +161,7 @@ bool xmlAccess::readXmlElement(const std::string& name, const TiXmlElement* pare
if (!readXmlElement(name, parent, temp))
return false;
- output = common::stringToNumber<T>(temp);
+ output = zen::toNumber<T>(temp);
return true;
}
@@ -181,7 +170,7 @@ template <class T>
inline
void xmlAccess::addXmlElement(const std::string& name, T value, TiXmlElement* parent)
{
- addXmlElement(name, common::numberToString<std::string::value_type>(value), parent);
+ addXmlElement(name, zen::toString<std::string>(value), parent);
}
@@ -192,7 +181,7 @@ bool xmlAccess::readXmlAttribute(const std::string& name, const TiXmlElement* no
std::string dummy;
if (readXmlAttribute(name, node, dummy))
{
- output = common::stringToNumber<T>(dummy);
+ output = zen::toNumber<T>(dummy);
return true;
}
else
@@ -204,7 +193,7 @@ template <class T>
inline
void xmlAccess::addXmlAttribute(const std::string& name, T value, TiXmlElement* node)
{
- addXmlAttribute(name, common::numberToString<std::string::value_type>(value), node);
+ addXmlAttribute(name, zen::toString<std::string>(value), node);
}
#endif // XMLBASE_H_INCLUDED
bgstack15