summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-06-12 15:43:18 +0000
committerrandomdan <randomdan@localhost>2011-06-12 15:43:18 +0000
commitfd42e0cd8ef97eb845dc6e1f3d47ebe94116c86a (patch)
tree3365add5210d2b198d83ea270ed9bea9b0298e69
parentMake named types code totally generic (diff)
downloadproject2-fd42e0cd8ef97eb845dc6e1f3d47ebe94116c86a.tar.bz2
project2-fd42e0cd8ef97eb845dc6e1f3d47ebe94116c86a.tar.xz
project2-fd42e0cd8ef97eb845dc6e1f3d47ebe94116c86a.zip
Allow callbacks into any component loader type
-rw-r--r--project2/xmlObjectLoader.cpp23
-rw-r--r--project2/xmlObjectLoader.h16
2 files changed, 31 insertions, 8 deletions
diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp
index 372081b..b33bf85 100644
--- a/project2/xmlObjectLoader.cpp
+++ b/project2/xmlObjectLoader.cpp
@@ -11,6 +11,7 @@ unsigned int LoaderBase::depth = 0;
std::set<SourceObjectPtr> LoaderBase::loadedObjects;
typedef std::map<std::string, boost::shared_ptr<ElementLoader> > ElementLoaderMap;
+typedef std::set<boost::shared_ptr<ComponentLoader> > ComponentLoaderSet;
LoaderBase::LoaderBase(bool r) :
recursive(r),
@@ -30,6 +31,16 @@ LoaderBase::~LoaderBase()
{
}
+std::set<boost::shared_ptr<ComponentLoader> > * &
+LoaderBase::componentLoaders()
+{
+ static std::set<boost::shared_ptr<ComponentLoader> > * _compLoaders = NULL;
+ if (!_compLoaders) {
+ _compLoaders = new std::set<boost::shared_ptr<ComponentLoader> >();
+ }
+ return _compLoaders;
+}
+
void
LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly, UnsupportedHandling uh) const
{
@@ -82,8 +93,8 @@ LoaderBase::collectAll(const CommonObjects * co, const xmlpp::Element * node, bo
void
LoaderBase::onIdle()
{
- BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders<ElementLoader>()) {
- l.second->onIdle();
+ BOOST_FOREACH(ComponentLoaderSet::value_type l, *componentLoaders()) {
+ l->onIdle();
}
}
@@ -94,16 +105,16 @@ LoaderBase::onIteration()
depth = 0;
loadedObjects.clear();
- BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders<ElementLoader>()) {
- l.second->onIteration();
+ BOOST_FOREACH(ComponentLoaderSet::value_type l, *componentLoaders()) {
+ l->onIteration();
}
}
void
LoaderBase::onPeriodic()
{
- BOOST_FOREACH(ElementLoaderMap::value_type l, *objLoaders<ElementLoader>()) {
- l.second->onPeriodic();
+ BOOST_FOREACH(ComponentLoaderSet::value_type l, *componentLoaders()) {
+ l->onPeriodic();
}
}
diff --git a/project2/xmlObjectLoader.h b/project2/xmlObjectLoader.h
index e68a390..c86720d 100644
--- a/project2/xmlObjectLoader.h
+++ b/project2/xmlObjectLoader.h
@@ -16,6 +16,7 @@ Glib::ustring xmlChildText(const xmlpp::Node * p, const Glib::ustring & n);
enum UnsupportedHandling { ErrorOnUnsupported, WarnOnUnsupported, IgnoreUnsupported };
class ElementLoader;
+class ComponentLoader;
class CommonObjects;
class Storer;
@@ -35,6 +36,8 @@ class LoaderBase {
static void onIteration();
static void onPeriodic();
+ static std::set<boost::shared_ptr<ComponentLoader> > * & componentLoaders();
+
template <class T>
static std::map<std::string, boost::shared_ptr<T> > * & objLoaders()
{
@@ -48,18 +51,27 @@ class LoaderBase {
template <class T>
static void newLoader(const std::string & n, T * l)
{
- objLoaders<T>()->insert(std::pair<std::string, boost::shared_ptr<T> >(n, boost::shared_ptr<T>(l)));
+ boost::shared_ptr<T> p = boost::shared_ptr<T>(l);
+ objLoaders<T>()->insert(std::pair<std::string, boost::shared_ptr<T> >(n, p));
+ componentLoaders()->insert(boost::shared_ptr<T>(p));
}
template <class T>
static void removeLoader(const std::string & n)
{
std::map<std::string, boost::shared_ptr<T> > * & o = objLoaders<T>();
- o->erase(n);
+ std::set<boost::shared_ptr<ComponentLoader> > * & c = componentLoaders();
+ typename std::map<std::string, boost::shared_ptr<T> >::iterator i = o->find(n);
+ c->erase(i->second);
+ o->erase(i);
if (o->empty()) {
delete o;
o = NULL;
}
+ if (c->empty()) {
+ delete c;
+ c = NULL;
+ }
}
template <class L, class E>