summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-03-23 14:19:49 +0000
committerrandomdan <randomdan@localhost>2013-03-23 14:19:49 +0000
commit1878bbaf78d0ef582d79b880aaa96f44e32d91c2 (patch)
tree2fe4de3aa9c710583a20a1998642fba45dd58927
parentReally dirty hack to make libxmlpp not crash with HTML docs (diff)
downloadproject2-1878bbaf78d0ef582d79b880aaa96f44e32d91c2.tar.bz2
project2-1878bbaf78d0ef582d79b880aaa96f44e32d91c2.tar.xz
project2-1878bbaf78d0ef582d79b880aaa96f44e32d91c2.zip
Allow script components to declare themselves uncacheable
-rw-r--r--project2/common/scriptLoader.cpp9
-rw-r--r--project2/common/scriptLoader.h1
-rw-r--r--project2/common/scriptStorage.h4
3 files changed, 11 insertions, 3 deletions
diff --git a/project2/common/scriptLoader.cpp b/project2/common/scriptLoader.cpp
index bd6495b..1f5243e 100644
--- a/project2/common/scriptLoader.cpp
+++ b/project2/common/scriptLoader.cpp
@@ -99,18 +99,21 @@ LoaderBase::collectAll(ScriptNodePtr node, bool childrenOnly, const StorerPtrs &
catch (const NotSupported &) {
}
}
+ if (!node->obj) {
+ throw NotSupported(node->get_name());
+ }
}
else {
if (SourceObjectPtr p = boost::dynamic_pointer_cast<SourceObject>(node->obj)) {
LoaderBase::loadedObjects.insert(p.get());
}
}
- if (!node->obj) {
- throw NotSupported(node->get_name());
- }
BOOST_FOREACH(const StorerPtr & s, sts) {
if (s->save(node->obj, node)) {
stored += 1;
+ if (!s->cacheable(node)) {
+ node->obj.reset();
+ }
break;
}
}
diff --git a/project2/common/scriptLoader.h b/project2/common/scriptLoader.h
index 2582a52..2b1057b 100644
--- a/project2/common/scriptLoader.h
+++ b/project2/common/scriptLoader.h
@@ -131,6 +131,7 @@ class ComponentLoader {
virtual void onPeriodic(); // When the app engine feels like it
virtual void onConfigLoad(); // When the environment reloads the configuration
virtual const Options * options() const; // Options to be populated from the common config file/env/etc
+ virtual bool cacheable() const { return true; } // The component can be cached for next run
};
template <class Impl, typename... Params>
diff --git a/project2/common/scriptStorage.h b/project2/common/scriptStorage.h
index 12cf3a6..2859a28 100644
--- a/project2/common/scriptStorage.h
+++ b/project2/common/scriptStorage.h
@@ -38,6 +38,7 @@ class Storer : public virtual IntrusivePtrBase {
virtual boost::intrusive_ptr<IntrusivePtrBase> create(ScriptNodePtr) const = 0;
virtual bool save(boost::intrusive_ptr<IntrusivePtrBase>, ScriptNodePtr) = 0;
+ virtual bool cacheable(ScriptNodePtr) const { return true; }
};
template <class X, class L>
@@ -51,6 +52,9 @@ class StorerBase : public Storer {
boost::intrusive_ptr<IntrusivePtrBase> create(ScriptNodePtr p) const {
return creator(LoaderBase::getLoader<L, NotSupported>(p->get_name()).get(), p);
}
+ bool cacheable(ScriptNodePtr p) const {
+ return LoaderBase::getLoader<L, NotSupported>(p->get_name())->cacheable();
+ }
bool save(boost::intrusive_ptr<IntrusivePtrBase> o, ScriptNodePtr name) {
boost::intrusive_ptr<X> O = boost::dynamic_pointer_cast<X>(o);
if (O) {