summaryrefslogtreecommitdiff
path: root/project2/xmlObjectLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/xmlObjectLoader.cpp')
-rw-r--r--project2/xmlObjectLoader.cpp33
1 files changed, 12 insertions, 21 deletions
diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp
index a40c66c..f14f773 100644
--- a/project2/xmlObjectLoader.cpp
+++ b/project2/xmlObjectLoader.cpp
@@ -6,17 +6,12 @@
unsigned int LoaderBase::depth = 0;
std::set<SourceObjectPtr> LoaderBase::loadedObjects;
-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()
+typedef std::map<std::string, boost::shared_ptr<ElementLoader> > ElementLoaderMap;
+ElementLoaderMap &
+objLoaders()
{
- objLoaders = new ElementLoaderMap();
-}
-void kill_loaders()
-{
- delete objLoaders;
+ static ElementLoaderMap _objLoaders;
+ return _objLoaders;
}
LoaderBase::LoaderBase(const Glib::ustring & n, bool r) :
@@ -40,8 +35,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;
- ElementLoaderMap::const_iterator i = objLoaders->find(name);
- if (i != objLoaders->end()) {
+ ElementLoaderMap::const_iterator i = objLoaders().find(name);
+ if (i != objLoaders().end()) {
SourceObjectPtr o = i->second->go(node);
created += 1;
loadedObjects.insert(o);
@@ -87,23 +82,19 @@ 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));
+ objLoaders().insert(ElementLoaderMap::value_type(n, boost::shared_ptr<ElementLoader>(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);
+ objLoaders().erase(n);
}
void
LoaderBase::onIdle()
{
- BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders) {
+ BOOST_FOREACH(ElementLoaderMap::value_type l, objLoaders()) {
l.second->onIdle();
}
}
@@ -115,7 +106,7 @@ LoaderBase::onIteration()
depth = 0;
loadedObjects.clear();
- BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders) {
+ BOOST_FOREACH(ElementLoaderMap::value_type l, objLoaders()) {
l.second->onIteration();
}
}
@@ -123,7 +114,7 @@ LoaderBase::onIteration()
void
LoaderBase::onPeriodic()
{
- BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders) {
+ BOOST_FOREACH(ElementLoaderMap::value_type l, objLoaders()) {
l.second->onPeriodic();
}
}