diff options
Diffstat (limited to 'project2/xmlObjectLoader.cpp')
-rw-r--r-- | project2/xmlObjectLoader.cpp | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp index 1eb85f9..71f1b53 100644 --- a/project2/xmlObjectLoader.cpp +++ b/project2/xmlObjectLoader.cpp @@ -1,32 +1,57 @@ #include "xmlObjectLoader.h" +#include <stdexcept> +#include <stdio.h> -_LoaderBase::_LoaderBase() -{ -} -_LoaderBase::~_LoaderBase() +unsigned int LoaderBase::depth = 0; +std::set<Project2SourceObject> LoaderBase::loadedObjects; + +LoaderBase::ElementLoaderMap & +LoaderBase::getMap() { + static ElementLoaderMap loaders; + return loaders; } void -_LoaderBase::collectAll(const Loaders & ls, const Glib::ustring & ns, const xmlpp::Element * node, bool recursive, bool childrenOnly) +LoaderBase::collectAll(const Glib::ustring & ns, const xmlpp::Element * node, bool recursive, bool childrenOnly) const { if (!node) { return; } + depth += 1; if (!childrenOnly && ns == node->get_namespace_prefix()) { Glib::ustring name = node->get_name(); unsigned int created = 0; - for(Loaders::const_iterator i = ls.lower_bound(name); i != ls.upper_bound(name); i++) { - i->second->go(node); + unsigned int stored = 0; + for(ElementLoaderMap::const_iterator i = getMap().lower_bound(name); i != getMap().upper_bound(name); i++) { + Project2SourceObject 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)) { + stored += 1; + } + } } if (created < 1) { fprintf(stderr, "Didn't create any objects for %s:%s\n", ns.c_str(), name.c_str()); + throw std::runtime_error("Unknown object"); + } + if (stored < 1) { + throw std::runtime_error("Unsupported object"); } } else if (recursive || childrenOnly) { BOOST_FOREACH(xmlpp::Node * child, node->get_children()) { - collectAll(ls, ns, dynamic_cast<const xmlpp::Element *>(child), recursive, false); + collectAll(ns, dynamic_cast<const xmlpp::Element *>(child), recursive, false); } } + depth -= 1; + if (depth == 0) { + BOOST_FOREACH(Project2SourceObject o, loadedObjects) { + o->loadComplete(); + } + loadedObjects.clear(); + } } + |