diff options
author | randomdan <randomdan@localhost> | 2012-04-24 22:44:13 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2012-04-24 22:44:13 +0000 |
commit | 8ccecfaac2f28dec1a34d20b744917126be1e27b (patch) | |
tree | 3fc2c2eda00b224640c7d681e74dcb56952e6666 | |
parent | Include content length when serving static content (diff) | |
download | project2-8ccecfaac2f28dec1a34d20b744917126be1e27b.tar.bz2 project2-8ccecfaac2f28dec1a34d20b744917126be1e27b.tar.xz project2-8ccecfaac2f28dec1a34d20b744917126be1e27b.zip |
Handy little lazy pointer class for last minute default initialisation
-rw-r--r-- | project2/cgi/cgiAppEngine.h | 3 | ||||
-rw-r--r-- | project2/cgi/cgiStagePresent.cpp | 6 | ||||
-rw-r--r-- | project2/common/scriptStorage.h | 24 |
3 files changed, 12 insertions, 21 deletions
diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index 854013a..66d5a69 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -8,6 +8,7 @@ #include "taskHost.h" #include "viewHost.h" #include "transform.h" +#include "lazyPointer.h" #include "xmlPresenter.h" #include "presenterCache.h" #include "sessionContainer.h" @@ -104,7 +105,7 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink virtual HttpHeaderPtr getHeader() const; protected: HttpHeaderPtr header; - mutable MultiRowSetPresenterPtr presenter; + LazyPointer<MultiRowSetPresenter> presenter; }; /// Stage to return previous cached output diff --git a/project2/cgi/cgiStagePresent.cpp b/project2/cgi/cgiStagePresent.cpp index 98031e4..9574e84 100644 --- a/project2/cgi/cgiStagePresent.cpp +++ b/project2/cgi/cgiStagePresent.cpp @@ -9,7 +9,8 @@ CgiApplicationEngine::PresentStage::PresentStage(ScriptReaderPtr s) : CgiApplicationEngine::ResponseStage(s->root()), CommonObjects(s->root()), CheckHost(s->root()), - ViewHost(s->root()) + ViewHost(s->root()), + presenter([root,this] { return PresenterLoader::getFor(this->env()->defaultPresenter)->create(root); }) { s->loader.addLoadTarget(s->root(), Storer::into<OutputOptionsLoader>(&outputOptions)); s->loader.addLoadTarget(s->root(), Storer::into<PresenterLoader>(&presenter)); @@ -51,9 +52,6 @@ CgiApplicationEngine::PresentStage::run() MultiRowSetPresenterPtr CgiApplicationEngine::PresentStage::getPresenter() const { - if (!presenter) { - presenter = PresenterLoader::getFor(env()->defaultPresenter)->create(root); - } return presenter; } diff --git a/project2/common/scriptStorage.h b/project2/common/scriptStorage.h index 63ee71c..12cf3a6 100644 --- a/project2/common/scriptStorage.h +++ b/project2/common/scriptStorage.h @@ -14,8 +14,6 @@ SimpleMessageException(StoreFailed); -#define SINGLE(X) \ - boost::intrusive_ptr<X> #define STORAGEOF(X) \ std::map<std::string, boost::intrusive_ptr<X> > #define ANONORDEREDSTORAGEOF(X) \ @@ -29,8 +27,8 @@ class StorerBase; typedef boost::intrusive_ptr<Storer> StorerPtr; class Storer : public virtual IntrusivePtrBase { public: - template <class L, class X, typename... C> - static boost::intrusive_ptr<StorerBase<X, L> > into(SINGLE(X) * obj, const C & ... c); + template <class L, typename PtrOfX, typename... C> + static boost::intrusive_ptr<StorerBase<typename PtrOfX::element_type, L> > into(PtrOfX * obj, const C & ... c); template <class L, class X, typename... C> static boost::intrusive_ptr<StorerBase<X, L> > into(STORAGEOF(X) * map, const C & ... c); template <class L, class X, typename... C> @@ -70,14 +68,8 @@ class StorerBase : public Storer { template <class X, class M, class L> class StorerImpl : public StorerBase<X, L> { public: - StorerImpl(M * m); - bool insert(boost::intrusive_ptr<X> O); -}; -template <class X, class L> -class StorerImpl<X, SINGLE(X), L> : public StorerBase<X, L> { - public: - typedef SINGLE(X) Obj; - StorerImpl(SINGLE(X) * o, const typename StorerBase<X, L>::Creator & c) : StorerBase<X, L>(c), obj(o) + typedef M Obj; + StorerImpl(M * o, const typename StorerBase<X, L>::Creator & c) : StorerBase<X, L>(c), obj(o) { } bool insert(boost::intrusive_ptr<X> O) @@ -129,10 +121,10 @@ class StorerImpl<X, ANONORDEREDSTORAGEOF(X), L> : public StorerBase<X, L> { Map * map; }; -template <class L, class X, typename... C> -boost::intrusive_ptr<StorerBase<X, L> > -Storer::into(SINGLE(X) * obj, const C & ... c) { - return new StorerImpl<X, SINGLE(X), L>(obj, boost::bind(&L::create, _1, _2, c...)); +template <class L, class PtrOfX, typename... C> +boost::intrusive_ptr<StorerBase<typename PtrOfX::element_type, L> > +Storer::into(PtrOfX * obj, const C & ... c) { + return new StorerImpl<typename PtrOfX::element_type, PtrOfX, L>(obj, boost::bind(&L::create, _1, _2, c...)); } template <class L, class X, typename... C> |