summaryrefslogtreecommitdiff
path: root/project2/xmlObjectLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/xmlObjectLoader.cpp')
-rw-r--r--project2/xmlObjectLoader.cpp57
1 files changed, 40 insertions, 17 deletions
diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp
index 4b291da..a40c66c 100644
--- a/project2/xmlObjectLoader.cpp
+++ b/project2/xmlObjectLoader.cpp
@@ -6,11 +6,17 @@
unsigned int LoaderBase::depth = 0;
std::set<SourceObjectPtr> LoaderBase::loadedObjects;
-LoaderBase::ElementLoaderMap &
-LoaderBase::getMap()
+typedef std::map<std::string, ElementLoader *> ElementLoaderMap;
+static ElementLoaderMap * objLoaders;
+void init_loaders() __attribute__ ((constructor(101)));
+void kill_loaders() __attribute__ ((destructor(101)));
+void init_loaders()
{
- static ElementLoaderMap loaders;
- return loaders;
+ objLoaders = new ElementLoaderMap();
+}
+void kill_loaders()
+{
+ delete objLoaders;
}
LoaderBase::LoaderBase(const Glib::ustring & n, bool r) :
@@ -34,7 +40,8 @@ LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly, Unsupport
if (!childrenOnly && node->get_namespace_uri() == ns) {
Glib::ustring name = node->get_name();
unsigned int stored = 0;
- for(ElementLoaderMap::const_iterator i = getMap().lower_bound(name); i != getMap().upper_bound(name); i++) {
+ ElementLoaderMap::const_iterator i = objLoaders->find(name);
+ if (i != objLoaders->end()) {
SourceObjectPtr o = i->second->go(node);
created += 1;
loadedObjects.insert(o);
@@ -43,18 +50,18 @@ LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly, Unsupport
stored += 1;
}
}
+ if (stored < 1) {
+ if (uh == ErrorOnUnsupported) {
+ throw NotSupported(name);
+ }
+ else if (uh == WarnOnUnsupported) {
+ Logger()->messagef(LOG_WARNING, "'%s' unsupported in this location", name.c_str());
+ }
+ }
}
- if (created < 1) {
+ else {
throw NotSupported(name);
}
- if (stored < created) {
- if (uh == ErrorOnUnsupported) {
- throw NotSupported(name);
- }
- else if (uh == WarnOnUnsupported) {
- Logger()->messagef(LOG_WARNING, "'%s' unsupported in this location", name.c_str());
- }
- }
}
if (created == 0 && (recursive || childrenOnly)) {
BOOST_FOREACH(const xmlpp::Node * child, node->get_children()) {
@@ -78,9 +85,25 @@ LoaderBase::collectAll(const CommonObjects * co, const xmlpp::Element * node, bo
}
void
+LoaderBase::newLoader(const std::string & n, ElementLoader * l)
+{
+ objLoaders->insert(ElementLoaderMap::value_type(n, l));
+}
+
+void
+LoaderBase::removeLoader(const std::string & n)
+{
+ ElementLoaderMap::const_iterator i = objLoaders->find(n);
+ if (i != objLoaders->end()) {
+ delete i->second;
+ }
+ objLoaders->erase(n);
+}
+
+void
LoaderBase::onIdle()
{
- BOOST_FOREACH(ElementLoaderMap::value_type l, getMap()) {
+ BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders) {
l.second->onIdle();
}
}
@@ -92,7 +115,7 @@ LoaderBase::onIteration()
depth = 0;
loadedObjects.clear();
- BOOST_FOREACH(ElementLoaderMap::value_type l, getMap()) {
+ BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders) {
l.second->onIteration();
}
}
@@ -100,7 +123,7 @@ LoaderBase::onIteration()
void
LoaderBase::onPeriodic()
{
- BOOST_FOREACH(ElementLoaderMap::value_type l, getMap()) {
+ BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders) {
l.second->onPeriodic();
}
}