summaryrefslogtreecommitdiff
path: root/project2/xmlObjectLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/xmlObjectLoader.cpp')
-rw-r--r--project2/xmlObjectLoader.cpp78
1 files changed, 23 insertions, 55 deletions
diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp
index 9187c82..372081b 100644
--- a/project2/xmlObjectLoader.cpp
+++ b/project2/xmlObjectLoader.cpp
@@ -11,15 +11,6 @@ unsigned int LoaderBase::depth = 0;
std::set<SourceObjectPtr> LoaderBase::loadedObjects;
typedef std::map<std::string, boost::shared_ptr<ElementLoader> > ElementLoaderMap;
-ElementLoaderMap * &
-objLoaders()
-{
- static ElementLoaderMap * _objLoaders = NULL;
- if (!_objLoaders) {
- _objLoaders = new ElementLoaderMap();
- }
- return _objLoaders;
-}
LoaderBase::LoaderBase(bool r) :
recursive(r),
@@ -50,27 +41,21 @@ 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;
- ElementLoaderMap::const_iterator i = objLoaders()->find(name);
- if (i != objLoaders()->end()) {
- SourceObjectPtr o = i->second->go(node);
- created += 1;
- loadedObjects.insert(o);
- BOOST_FOREACH(std::set<boost::intrusive_ptr<Storer> >::value_type s, supportedStorers) {
- if (s->save(o, node)) {
- 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());
- }
+ SourceObjectPtr o = getLoader<ElementLoader, NotSupported>(name)->go(node);
+ created += 1;
+ loadedObjects.insert(o);
+ BOOST_FOREACH(std::set<boost::intrusive_ptr<Storer> >::value_type s, supportedStorers) {
+ if (s->save(o, node)) {
+ stored += 1;
}
}
- else {
- throw NotSupported(name);
+ 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 == 0 && (recursive || childrenOnly)) {
@@ -95,26 +80,9 @@ 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, boost::shared_ptr<ElementLoader>(l)));
-}
-
-void
-LoaderBase::removeLoader(const std::string & n)
-{
- ElementLoaderMap * & o = objLoaders();
- o->erase(n);
- if (o->empty()) {
- delete o;
- o = NULL;
- }
-}
-
-void
LoaderBase::onIdle()
{
- BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders()) {
+ BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders<ElementLoader>()) {
l.second->onIdle();
}
}
@@ -126,7 +94,7 @@ LoaderBase::onIteration()
depth = 0;
loadedObjects.clear();
- BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders()) {
+ BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders<ElementLoader>()) {
l.second->onIteration();
}
}
@@ -134,16 +102,11 @@ LoaderBase::onIteration()
void
LoaderBase::onPeriodic()
{
- BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders()) {
+ BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders<ElementLoader>()) {
l.second->onPeriodic();
}
}
-void
-ElementLoader::onIdle()
-{
-}
-
Glib::ustring
xmlChildText(const xmlpp::Node * p, const Glib::ustring & t)
{
@@ -161,12 +124,17 @@ xmlChildText(const xmlpp::Node * p, const Glib::ustring & t)
}
void
-ElementLoader::onIteration()
+ComponentLoader::onIdle()
+{
+}
+
+void
+ComponentLoader::onIteration()
{
}
void
-ElementLoader::onPeriodic()
+ComponentLoader::onPeriodic()
{
}