summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-11-26 17:01:15 +0000
committerrandomdan <randomdan@localhost>2011-11-26 17:01:15 +0000
commit0b54e5fdf09fee145d20dbf931bd8d54ad97d39f (patch)
tree236d3cc720b5dddfe83e1387c79663809d472b1d
parentDon't needlessly write empty sessions (diff)
downloadproject2-0b54e5fdf09fee145d20dbf931bd8d54ad97d39f.tar.bz2
project2-0b54e5fdf09fee145d20dbf931bd8d54ad97d39f.tar.xz
project2-0b54e5fdf09fee145d20dbf931bd8d54ad97d39f.zip
Get rid of the multi presenter mess in viewHost and replace it with a single presenter
-rw-r--r--project2/cgi/cgiStagePresent.cpp4
-rw-r--r--project2/common/viewHost.cpp72
-rw-r--r--project2/common/viewHost.h18
-rw-r--r--project2/common/xmlStorage.h24
-rw-r--r--project2/console/consoleAppEngine.cpp2
5 files changed, 35 insertions, 85 deletions
diff --git a/project2/cgi/cgiStagePresent.cpp b/project2/cgi/cgiStagePresent.cpp
index df05465..f1fd5e3 100644
--- a/project2/cgi/cgiStagePresent.cpp
+++ b/project2/cgi/cgiStagePresent.cpp
@@ -19,7 +19,7 @@ CgiApplicationEngine::PresentStage::run()
runChecks();
try {
executeViews(boost::bind(&PresenterLoader::createFrom, LoaderBase::getLoader<PresenterLoader, NotSupported>(e->defaultPresenter), _1));
- return NextStage(NULL, this, boost::dynamic_pointer_cast<TransformSource>(headPresenter()), headPresenter());
+ return NextStage(NULL, this, boost::dynamic_pointer_cast<TransformSource>(presenter), presenter);
}
catch (ResponseStagePtr p) {
return NextStage(NULL, p, boost::dynamic_pointer_cast<TransformSource>(p), boost::dynamic_pointer_cast<Presenter>(p));
@@ -37,7 +37,7 @@ CgiApplicationEngine::ResponseStage::ResponseStage(const CgiEnvironment * e) :
CgiApplicationEngine::HttpHeaderPtr
CgiApplicationEngine::PresentStage::getHeader() const
{
- ContentPresenter * cp = boost::dynamic_pointer_cast<ContentPresenter>(headPresenter()).get();
+ ContentPresenter * cp = boost::dynamic_pointer_cast<ContentPresenter>(presenter).get();
Project2HttpHeader * header = new Project2HttpHeader("200 OK", cp ? cp->contentType : "text/plain");
header->addHeader("Cache-control", "no-cache");
return HttpHeaderPtr(header);
diff --git a/project2/common/viewHost.cpp b/project2/common/viewHost.cpp
index 7f7d6c7..01cf966 100644
--- a/project2/common/viewHost.cpp
+++ b/project2/common/viewHost.cpp
@@ -11,7 +11,7 @@ ViewHost::ViewHost(const boost::filesystem::path & file) :
CheckHost(file)
{
loader.supportedStorers.insert(Storer::into(&views));
- loader.supportedStorers.insert(Storer::into(&pmp.presenters));
+ loader.supportedStorers.insert(Storer::into(&presenter));
}
ViewHost::~ViewHost()
@@ -22,12 +22,12 @@ void
ViewHost::executeViews(const DefaultPresenterProvider & dpp) const
{
parseDocument();
- if (pmp.presenters.empty()) {
- pmp.presenters.insert(dpp(get_document()->get_root_node()));
+ if (!presenter) {
+ presenter = dpp(get_document()->get_root_node());
}
BOOST_FOREACH(const Views::value_type & s, views) {
- s->execute(&pmp);
+ s->execute(presenter.get());
}
// Caches might open transactions
BOOST_FOREACH(const DataSources::value_type & ds, datasources) {
@@ -38,68 +38,10 @@ ViewHost::executeViews(const DefaultPresenterProvider & dpp) const
void
ViewHost::doTransforms() const
{
- BOOST_FOREACH (const PresenterPtr & p, pmp.presenters) {
- TransformSourcePtr ts = boost::dynamic_pointer_cast<TransformSource>(p);
- if (ts) {
- ts->doTransforms();
- }
+ TransformSourcePtr ts = boost::dynamic_pointer_cast<TransformSource>(presenter);
+ if (ts) {
+ ts->doTransforms();
}
}
-PresenterPtr
-ViewHost::headPresenter() const
-{
- return *pmp.presenters.begin();
-}
-
-void
-ViewHost::PresenterMultiplexer::declareNamespace(const Glib::ustring & prefix, const Glib::ustring & ns) const
-{
- FOREACH_PRESENTER { p->declareNamespace(prefix, ns); }
-}
-void
-ViewHost::PresenterMultiplexer::setNamespace(const Glib::ustring & prefix, const Glib::ustring & ns) const
-{
- FOREACH_PRESENTER { p->setNamespace(prefix, ns); }
-}
-void
-ViewHost::PresenterMultiplexer::pushSub(const Glib::ustring & name) const
-{
- FOREACH_PRESENTER { p->pushSub(name); }
-}
-void
-ViewHost::PresenterMultiplexer::pushSub(const Glib::ustring & name, const Glib::ustring & ns) const
-{
- FOREACH_PRESENTER { p->pushSub(name, ns); }
-}
-void
-ViewHost::PresenterMultiplexer::addAttribute(const Glib::ustring & name, const VariableType & value) const
-{
- FOREACH_PRESENTER { p->addAttribute(name, value); }
-}
-void
-ViewHost::PresenterMultiplexer::addAttribute(const Glib::ustring & name, const Glib::ustring & ns, const VariableType & value) const
-{
- FOREACH_PRESENTER { p->addAttribute(name, ns, value); }
-}
-void
-ViewHost::PresenterMultiplexer::addNamedValue(const Glib::ustring & name, const VariableType & value) const
-{
- FOREACH_PRESENTER { p->addNamedValue(name, value); }
-}
-void
-ViewHost::PresenterMultiplexer::addNamedValue(const Glib::ustring & name, const Glib::ustring & ns, const VariableType & value) const
-{
- FOREACH_PRESENTER { p->addNamedValue(name, ns, value); }
-}
-void
-ViewHost::PresenterMultiplexer::addText(const VariableType & value) const
-{
- FOREACH_PRESENTER { p->addText(value); }
-}
-void
-ViewHost::PresenterMultiplexer::popSub() const
-{
- FOREACH_PRESENTER { p->popSub(); }
-}
diff --git a/project2/common/viewHost.h b/project2/common/viewHost.h
index d5e8695..920bef0 100644
--- a/project2/common/viewHost.h
+++ b/project2/common/viewHost.h
@@ -11,21 +11,6 @@
class ViewHost : virtual public XmlScriptParser, virtual public CheckHost {
public:
- class PresenterMultiplexer : public Presenter {
- public:
- typedef std::set<PresenterPtr> Presenters;
- void declareNamespace(const Glib::ustring & prefix, const Glib::ustring & ns) const;
- void setNamespace(const Glib::ustring & prefix, const Glib::ustring & ns) const;
- void pushSub(const Glib::ustring & name) const;
- void pushSub(const Glib::ustring & name, const Glib::ustring & ns) const;
- void addAttribute(const Glib::ustring & name, const VariableType & value) const;
- void addAttribute(const Glib::ustring & name, const Glib::ustring & ns, const VariableType & value) const;
- void addNamedValue(const Glib::ustring & name, const VariableType & value) const;
- void addNamedValue(const Glib::ustring & name, const Glib::ustring & ns, const VariableType & value) const;
- void addText(const VariableType & value) const;
- void popSub() const;
- Presenters presenters;
- };
typedef boost::function1<PresenterPtr, const xmlpp::Element *> DefaultPresenterProvider;
ViewHost(const boost::filesystem::path & file);
@@ -33,10 +18,9 @@ class ViewHost : virtual public XmlScriptParser, virtual public CheckHost {
void executeViews(const DefaultPresenterProvider &) const;
void doTransforms() const;
- PresenterPtr headPresenter() const;
+ mutable PresenterPtr presenter;
private:
- mutable PresenterMultiplexer pmp;
typedef ANONORDEREDSTORAGEOF(View) Views;
Views views;
};
diff --git a/project2/common/xmlStorage.h b/project2/common/xmlStorage.h
index 73fce0a..a700c64 100644
--- a/project2/common/xmlStorage.h
+++ b/project2/common/xmlStorage.h
@@ -10,6 +10,8 @@
SimpleMessageException(StoreFailed);
+#define SINGLE(X) \
+ boost::intrusive_ptr<X>
#define STORAGEOF(X) \
std::map<std::string, boost::intrusive_ptr<X> >
#define ANONORDEREDSTORAGEOF(X) \
@@ -22,6 +24,8 @@ typedef boost::intrusive_ptr<Storer> StorerPtr;
class Storer : public virtual IntrusivePtrBase {
public:
template <class X>
+ static StorerPtr into(SINGLE(X) * obj);
+ template <class X>
static StorerPtr into(STORAGEOF(X) * map);
template <class X>
static StorerPtr into(ANONSTORAGEOF(X) * set);
@@ -55,6 +59,20 @@ class StorerImpl : public StorerBase<X, M> {
bool insert(const xmlpp::Element *, boost::intrusive_ptr<X> O);
};
template <class X>
+class StorerImpl<X, SINGLE(X)> : public StorerBase<X, SINGLE(X)> {
+ public:
+ typedef SINGLE(X) Obj;
+ StorerImpl(SINGLE(X) * o) : obj(o)
+ {
+ }
+ bool insert(const xmlpp::Element *, boost::intrusive_ptr<X> O)
+ {
+ *obj = O;
+ return true;
+ }
+ Obj * obj;
+};
+template <class X>
class StorerImpl<X, STORAGEOF(X)> : public StorerBase<X, STORAGEOF(X)> {
public:
typedef STORAGEOF(X) Map;
@@ -98,6 +116,12 @@ class StorerImpl<X, ANONORDEREDSTORAGEOF(X)> : public StorerBase<X, ANONORDEREDS
template <class X>
StorerPtr
+Storer::into(SINGLE(X) * obj) {
+ return new StorerImpl<X, SINGLE(X)>(obj);
+}
+
+template <class X>
+StorerPtr
Storer::into(STORAGEOF(X) * map) {
return new StorerImpl<X, STORAGEOF(X)>(map);
}
diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp
index ef1a04f..cf0548d 100644
--- a/project2/console/consoleAppEngine.cpp
+++ b/project2/console/consoleAppEngine.cpp
@@ -41,7 +41,7 @@ ConsoleApplicationEngine::process() const
runChecks();
execute();
executeViews(boost::bind(&PresenterLoader::createFrom, LoaderBase::getLoader<PresenterLoader, NotSupported>("console"), _1));
- addAppData(headPresenter().get());
+ addAppData(presenter.get());
}
catch (const std::exception & e) {
char * buf = __cxxabiv1::__cxa_demangle(typeid(e).name(), NULL, NULL, NULL);