summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-15 21:43:36 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-15 21:43:36 +0000
commit86db18d65a1c6e92b115efc3afe65f770ec93398 (patch)
tree9fedd710f689b3c9732f758330578b7b7347f391 /src/utils
parent2d7084e4f07cd56021ca47dc6124ed587883acc2 (diff)
downloadmana-86db18d65a1c6e92b115efc3afe65f770ec93398.tar.gz
mana-86db18d65a1c6e92b115efc3afe65f770ec93398.tar.bz2
mana-86db18d65a1c6e92b115efc3afe65f770ec93398.tar.xz
mana-86db18d65a1c6e92b115efc3afe65f770ec93398.zip
Separated getProperty method to an XML utility namespace.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/xml.cpp54
-rw-r--r--src/utils/xml.h46
2 files changed, 100 insertions, 0 deletions
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
new file mode 100644
index 00000000..b820011d
--- /dev/null
+++ b/src/utils/xml.cpp
@@ -0,0 +1,54 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: dtor.h 2822 2006-11-05 14:30:53Z b_lindeijer $
+ */
+
+#include "xml.h"
+
+namespace XML
+{
+ int
+ getProperty(xmlNodePtr node, const char* name, int def)
+ {
+ int &ret = def;
+
+ xmlChar *prop = xmlGetProp(node, BAD_CAST name);
+ if (prop) {
+ ret = atoi((char*)prop);
+ xmlFree(prop);
+ }
+
+ return ret;
+ }
+
+ std::string
+ getProperty(xmlNodePtr node, const char *name, const std::string &def)
+ {
+ xmlChar *prop = xmlGetProp(node, BAD_CAST name);
+ if (prop) {
+ std::string val = (char*)prop;
+ xmlFree(prop);
+ return val;
+ }
+
+ return def;
+ }
+}
diff --git a/src/utils/xml.h b/src/utils/xml.h
new file mode 100644
index 00000000..9cbb5b2a
--- /dev/null
+++ b/src/utils/xml.h
@@ -0,0 +1,46 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: dtor.h 2822 2006-11-05 14:30:53Z b_lindeijer $
+ */
+
+#ifndef _TMW_XML_H
+#define _TMW_XML_H
+
+#include <libxml/tree.h>
+
+#include <string>
+
+namespace XML
+{
+ /**
+ * Gets an integer property from an xmlNodePtr.
+ */
+ int
+ getProperty(xmlNodePtr node, const char *name, int def);
+
+ /**
+ * Gets a string property from an xmlNodePtr.
+ */
+ std::string
+ getProperty(xmlNodePtr node, const char *name, const std::string &def);
+}
+
+#endif