summaryrefslogtreecommitdiff
path: root/project2/xmlObjectLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/xmlObjectLoader.cpp')
-rw-r--r--project2/xmlObjectLoader.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp
index e789275..cfbf1a4 100644
--- a/project2/xmlObjectLoader.cpp
+++ b/project2/xmlObjectLoader.cpp
@@ -1,5 +1,5 @@
#include "xmlObjectLoader.h"
-#include <stdexcept>
+#include "exceptions.h"
#include <stdio.h>
unsigned int LoaderBase::depth = 0;
@@ -43,8 +43,11 @@ LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly) const
}
}
}
+ if (created < 1) {
+ throw NotSupported(name);
+ }
if (stored < created) {
- throw std::runtime_error("Unexpected object");
+ throw NotSupported(name);
}
}
if (created == 0 && (recursive || childrenOnly)) {
@@ -53,12 +56,19 @@ LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly) const
}
}
depth -= 1;
- if (depth == 0) {
- BOOST_FOREACH(Project2SourceObject o, loadedObjects) {
- o->loadComplete();
- }
- loadedObjects.clear();
+}
+
+void
+LoaderBase::collectAll(const CommonObjects * co, const xmlpp::Element * node, bool childrenOnly) const
+{
+ if (depth != 0) {
+ throw std::logic_error("Cannot set CommonObjects in subloader");
}
+ collectAll(node, childrenOnly);
+ BOOST_FOREACH(Project2SourceObject o, loadedObjects) {
+ o->loadComplete(co);
+ }
+ loadedObjects.clear();
}
void
@@ -72,6 +82,10 @@ LoaderBase::onIdle()
void
LoaderBase::onIteration()
{
+ // This is a fail safe in the event that something goes pearshape
+ depth = 0;
+ loadedObjects.clear();
+
BOOST_FOREACH(ElementLoaderMap::value_type l, getMap()) {
l.second->onIteration();
}