From 2988566cc30f84761b2a8dc9e7d1a90ddcc94c1b Mon Sep 17 00:00:00 2001 From: randomdan Date: Tue, 23 Aug 2011 18:38:07 +0000 Subject: Allow specifying extra or replacement key parameters for a cache instance Don't crash when trying to clear an non-existant cache directory --- project2/cache.cpp | 4 +++- project2/cache.h | 5 +++-- project2/xmlCache.cpp | 11 +++++++++-- project2/xmlObjectLoader.cpp | 6 +++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/project2/cache.cpp b/project2/cache.cpp index 0db108b..bdf012b 100644 --- a/project2/cache.cpp +++ b/project2/cache.cpp @@ -4,7 +4,9 @@ #include "logger.h" Cache::Cache(const xmlpp::Element * p) : - SourceObject(p) + IHaveParameters(p), + SourceObject(p), + inherit(p->get_attribute_value("inherit") != "false") { } diff --git a/project2/cache.h b/project2/cache.h index 358d933..9678356 100644 --- a/project2/cache.h +++ b/project2/cache.h @@ -3,14 +3,14 @@ #include "sourceObject.h" #include "presenter.h" +#include "iHaveParameters.h" class RowProcessor; -class IHaveParameters; class RowSet; class RowState; typedef boost::intrusive_ptr RowSetCPtr; -class Cache : public SourceObject { +class Cache : public IHaveParameters, public SourceObject { public: Cache(const xmlpp::Element * p); @@ -20,6 +20,7 @@ class Cache : public SourceObject { protected: virtual RowSetCPtr getCachedRowSet(const Glib::ustring &, const Glib::ustring &, const IHaveParameters *) const = 0; + const bool inherit; }; typedef boost::intrusive_ptr CachePtr; diff --git a/project2/xmlCache.cpp b/project2/xmlCache.cpp index 0a166e8..22937d6 100644 --- a/project2/xmlCache.cpp +++ b/project2/xmlCache.cpp @@ -61,13 +61,20 @@ class XmlCache : public Cache { boost::filesystem::path getCacheFile(const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps) const { boost::filesystem::path cache = Store / n.raw() / f.raw(); + appendPath(cache, this); + if (inherit) { + appendPath(cache, ps); + } + cache /= FileName; + return cache; + } + static void appendPath(boost::filesystem::path & cache, const IHaveParameters * ps) + { BOOST_FOREACH(const IHaveParameters::Parameters::value_type & p, ps->allParameters()) { std::string v = p.second->value(); cache /= p.first.raw(); cache /= v; } - cache /= FileName; - return cache; } XmlPresenterPtr writeTo; diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp index 5cc28f0..14d2972 100644 --- a/project2/xmlObjectLoader.cpp +++ b/project2/xmlObjectLoader.cpp @@ -106,7 +106,11 @@ void LoaderBase::onAllComponents(const boost::function1 & func) { BOOST_FOREACH(ComponentLoaderSet::value_type l, *componentLoaders()) { - func(l.get()); + try { + func(l.get()); + } + catch (...) { + } } } -- cgit v1.2.3