summaryrefslogtreecommitdiff
path: root/src/resources/monsterdb.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-07 08:37:23 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-07 08:37:23 +0000
commit64d58b9a7e057e6d829107678b1570082be1093f (patch)
treef95a940521150e8f5bbab1bba520c956c8b2aed9 /src/resources/monsterdb.cpp
parent36a53a1d5e3b558dafe200a6929948e7730c94f0 (diff)
downloadmana-64d58b9a7e057e6d829107678b1570082be1093f.tar.gz
mana-64d58b9a7e057e6d829107678b1570082be1093f.tar.bz2
mana-64d58b9a7e057e6d829107678b1570082be1093f.tar.xz
mana-64d58b9a7e057e6d829107678b1570082be1093f.zip
Added XML::Document class which simplifies parsing an XML document and
automatically cleans it up again.
Diffstat (limited to 'src/resources/monsterdb.cpp')
-rw-r--r--src/resources/monsterdb.cpp29
1 files changed, 6 insertions, 23 deletions
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index e7e855fa..f531a41d 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -51,27 +51,12 @@ MonsterDB::load()
logger->log("Initializing monster database...");
- ResourceManager *resman = ResourceManager::getInstance();
- int size;
- char *data = (char*)resman->loadFile("monsters.xml", size);
+ XML::Document doc("monsters.xml");
+ xmlNodePtr rootNode = doc.rootNode();
- if (!data)
- {
- logger->error("Monster Database: Could not find monsters.xml!");
- }
-
- xmlDocPtr doc = xmlParseMemory(data, size);
- free(data);
-
- if (!doc)
- {
- logger->error("Monster Database: Error while parsing monster database (monsters.xml)!");
- }
-
- xmlNodePtr rootNode = xmlDocGetRootElement(doc);
if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "monsters"))
{
- logger->error("Monster Database: monster.xml is not a valid database file!");
+ logger->error("Monster Database: Error while loading monster.xml!");
}
//iterate <monster>s
@@ -161,16 +146,14 @@ MonsterDB::load()
mMonsterInfos[XML::getProperty(monsterNode, "id", 0)] = currentInfo;
}
- xmlFreeDoc(doc);
-
mLoaded = true;
}
void
MonsterDB::unload()
{
- for_each ( mMonsterInfos.begin(), mMonsterInfos.end(),
- make_dtor(mMonsterInfos));
+ for_each(mMonsterInfos.begin(), mMonsterInfos.end(),
+ make_dtor(mMonsterInfos));
mMonsterInfos.clear();
mLoaded = false;
@@ -178,7 +161,7 @@ MonsterDB::unload()
const MonsterInfo&
-MonsterDB::get (int id)
+MonsterDB::get(int id)
{
MonsterInfoIterator i = mMonsterInfos.find(id);