summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-11-29 13:22:48 +0000
committerrandomdan <randomdan@localhost>2011-11-29 13:22:48 +0000
commit0fd4f3740a2581963643292e6b9f201ee0aa9466 (patch)
tree3a1c5ed7fbe6fd838ddae64e2575e9f08c22bf1f
parentSerialize JSON objects to a stream, removes need to temp string in transform (diff)
downloadproject2-0fd4f3740a2581963643292e6b9f201ee0aa9466.tar.bz2
project2-0fd4f3740a2581963643292e6b9f201ee0aa9466.tar.xz
project2-0fd4f3740a2581963643292e6b9f201ee0aa9466.zip
Allow specifying different loader classes when setting up script parsers (allows defining presenter modules from within a script)
-rw-r--r--project2/common/checkHost.cpp2
-rw-r--r--project2/common/commonObjects.cpp2
-rw-r--r--project2/common/if.cpp6
-rw-r--r--project2/common/iterate.cpp2
-rw-r--r--project2/common/rowProcessor.cpp2
-rw-r--r--project2/common/rowView.cpp2
-rw-r--r--project2/common/structExceptHandling.cpp2
-rw-r--r--project2/common/taskHost.cpp2
-rw-r--r--project2/common/variables-modlookup.cpp2
-rw-r--r--project2/common/viewHost.cpp4
-rw-r--r--project2/common/xmlObjectLoader.cpp12
-rw-r--r--project2/common/xmlObjectLoader.h4
-rw-r--r--project2/common/xmlScriptParser.cpp2
-rw-r--r--project2/common/xmlStorage.h68
-rw-r--r--project2/sql/sqlMergeTask.cpp2
-rw-r--r--project2/sql/sqlTask.cpp2
16 files changed, 62 insertions, 54 deletions
diff --git a/project2/common/checkHost.cpp b/project2/common/checkHost.cpp
index 7f908c0..343b255 100644
--- a/project2/common/checkHost.cpp
+++ b/project2/common/checkHost.cpp
@@ -6,7 +6,7 @@
CheckHost::CheckHost(const boost::filesystem::path & file) :
XmlScriptParser(file, false)
{
- loader.supportedStorers.insert(Storer::into(&parameterChecks));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&parameterChecks));
}
CheckHost::~CheckHost()
diff --git a/project2/common/commonObjects.cpp b/project2/common/commonObjects.cpp
index 8ad1a97..4ce8c82 100644
--- a/project2/common/commonObjects.cpp
+++ b/project2/common/commonObjects.cpp
@@ -22,7 +22,7 @@ CommonObjects::loadDataSource(const std::string & name) const
Environment::getCurrent()->datasourceRoot, name), true);
LoaderBase loader(true);
- loader.supportedStorers.insert(Storer::into(&datasources));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&datasources));
loader.collectAll(xml.get_document()->get_root_node(), false);
return safeMapFind<DataSourceNotFound>(datasources, name);
diff --git a/project2/common/if.cpp b/project2/common/if.cpp
index f3c7102..a810146 100644
--- a/project2/common/if.cpp
+++ b/project2/common/if.cpp
@@ -14,7 +14,7 @@ IfSet::IfSet(const xmlpp::Element * e) :
mode(e->get_attribute_value("mode") == "or" ? Or : And)
{
LoaderBase loader(true);
- loader.supportedStorers.insert(Storer::into(&checks));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&checks));
loader.collectAll(e, true, IgnoreUnsupported);
}
@@ -48,8 +48,8 @@ If::If(const xmlpp::Element * e) :
IfSet(e)
{
LoaderBase loader(true);
- loader.supportedStorers.insert(Storer::into(&normal));
- loader.supportedStorers.insert(Storer::into(&subViews));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&normal));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&subViews));
loader.collectAll(e, true, IgnoreUnsupported);
}
diff --git a/project2/common/iterate.cpp b/project2/common/iterate.cpp
index ddde42c..ba8a4b9 100644
--- a/project2/common/iterate.cpp
+++ b/project2/common/iterate.cpp
@@ -14,7 +14,7 @@ Iterate::Iterate(const xmlpp::Element * p) :
RowProcessor(p)
{
LoaderBase loader(true);
- loader.supportedStorers.insert(Storer::into(&normal));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&normal));
loader.collectAll(p, true, IgnoreUnsupported);
}
diff --git a/project2/common/rowProcessor.cpp b/project2/common/rowProcessor.cpp
index b2d3cbd..e186c43 100644
--- a/project2/common/rowProcessor.cpp
+++ b/project2/common/rowProcessor.cpp
@@ -13,7 +13,7 @@ RowProcessor::RowProcessor(const xmlpp::Element * p) :
IRSE(Variable(p, "ignoreRowSourceError", false, false)())
{
LoaderBase loader(true);
- loader.supportedStorers.insert(Storer::into(&caches));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&caches));
loader.collectAll(p, true, IgnoreUnsupported);
}
diff --git a/project2/common/rowView.cpp b/project2/common/rowView.cpp
index a35619d..6b0bbed 100644
--- a/project2/common/rowView.cpp
+++ b/project2/common/rowView.cpp
@@ -23,7 +23,7 @@ RowView::RowView(const xmlpp::Element * p) :
}
}
LoaderBase loader(true);
- loader.supportedStorers.insert(Storer::into(&subViews));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&subViews));
loader.collectAll(p, true, IgnoreUnsupported);
}
diff --git a/project2/common/structExceptHandling.cpp b/project2/common/structExceptHandling.cpp
index 5b5f1f5..0f176c9 100644
--- a/project2/common/structExceptHandling.cpp
+++ b/project2/common/structExceptHandling.cpp
@@ -10,7 +10,7 @@ static void
loadHelper(const char * name, const xmlpp::Element * root, ANONORDEREDSTORAGEOF(NoOutputExecute) * noes)
{
LoaderBase loader(true);
- loader.supportedStorers.insert(Storer::into(noes));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(noes));
BOOST_FOREACH(const xmlpp::Node * node, root->find(name)) {
const xmlpp::Element * elem = dynamic_cast<const xmlpp::Element *>(node);
if (elem) {
diff --git a/project2/common/taskHost.cpp b/project2/common/taskHost.cpp
index cecc883..98a1fa5 100644
--- a/project2/common/taskHost.cpp
+++ b/project2/common/taskHost.cpp
@@ -11,7 +11,7 @@ TaskHost::TaskHost(const boost::filesystem::path & file) :
CheckHost(file),
IHaveSubTasks(get_document()->get_root_node())
{
- loader.supportedStorers.insert(Storer::into(&tasks));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&tasks));
}
TaskHost::~TaskHost()
diff --git a/project2/common/variables-modlookup.cpp b/project2/common/variables-modlookup.cpp
index 408c98b..82c3539 100644
--- a/project2/common/variables-modlookup.cpp
+++ b/project2/common/variables-modlookup.cpp
@@ -36,7 +36,7 @@ class VariableLookup : public VariableImplDyn, public RowProcessor {
name(e->get_attribute_value("name"))
{
LoaderBase loader(true);
- loader.supportedStorers.insert(Storer::into(&rowSets));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&rowSets));
loader.collectAll(e, false);
}
VariableType value() const
diff --git a/project2/common/viewHost.cpp b/project2/common/viewHost.cpp
index 01cf966..9d3c14b 100644
--- a/project2/common/viewHost.cpp
+++ b/project2/common/viewHost.cpp
@@ -10,8 +10,8 @@ ViewHost::ViewHost(const boost::filesystem::path & file) :
XmlScriptParser(file, false),
CheckHost(file)
{
- loader.supportedStorers.insert(Storer::into(&views));
- loader.supportedStorers.insert(Storer::into(&presenter));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&views));
+ loader.supportedStorers.insert(Storer::into<PresenterLoader>(&presenter));
}
ViewHost::~ViewHost()
diff --git a/project2/common/xmlObjectLoader.cpp b/project2/common/xmlObjectLoader.cpp
index 6859f22..0e55cb4 100644
--- a/project2/common/xmlObjectLoader.cpp
+++ b/project2/common/xmlObjectLoader.cpp
@@ -30,14 +30,14 @@ LoaderBase::LoaderBase(bool r) :
recursive(r),
ns(Environment::getCurrent()->xmlNamespace)
{
- supportedStorers.insert(Storer::into(&libraries));
+ supportedStorers.insert(Storer::into<ElementLoader>(&libraries));
}
LoaderBase::LoaderBase(const Glib::ustring & n, bool r) :
recursive(r),
ns(n)
{
- supportedStorers.insert(Storer::into(&libraries));
+ supportedStorers.insert(Storer::into<ElementLoader>(&libraries));
}
LoaderBase::~LoaderBase()
@@ -65,11 +65,13 @@ LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly, Unsupport
if (!childrenOnly && node->get_namespace_uri() == ns) {
Glib::ustring name = node->get_name();
unsigned int stored = 0;
- SourceObjectPtr o = getLoader<ElementLoader, NotSupported>(name)->go(node);
created += 1;
- loadedObjects.insert(o);
BOOST_FOREACH(std::set<boost::intrusive_ptr<Storer> >::value_type s, supportedStorers) {
- if (s->save(o, node)) {
+ boost::intrusive_ptr<IntrusivePtrBase> o = s->save(node);
+ if (boost::intrusive_ptr<SourceObject> t = boost::dynamic_pointer_cast<SourceObject>(o)) {
+ loadedObjects.insert(t);
+ }
+ if (o) {
stored += 1;
}
}
diff --git a/project2/common/xmlObjectLoader.h b/project2/common/xmlObjectLoader.h
index 4795717..202dbeb 100644
--- a/project2/common/xmlObjectLoader.h
+++ b/project2/common/xmlObjectLoader.h
@@ -120,14 +120,14 @@ class ComponentLoader {
/// Helper for loading and maintaining Project2 script components
class ElementLoader : public ComponentLoader {
public:
- virtual SourceObjectPtr go(const xmlpp::Element * xml) const = 0;
+ virtual SourceObjectPtr createFrom(const xmlpp::Element * xml) const = 0;
};
/// Helper for loading and maintaining Project2 script components (typed implementation)
template <class X>
class ElementLoaderImpl : public ElementLoader {
public:
- SourceObjectPtr go(const xmlpp::Element * xml) const
+ SourceObjectPtr createFrom(const xmlpp::Element * xml) const
{
return new X(xml);
}
diff --git a/project2/common/xmlScriptParser.cpp b/project2/common/xmlScriptParser.cpp
index 762618a..1db1841 100644
--- a/project2/common/xmlScriptParser.cpp
+++ b/project2/common/xmlScriptParser.cpp
@@ -33,7 +33,7 @@ XmlScriptParser::loadDocument(const boost::filesystem::path & file)
throw IncludesError(file.string());
}
}
- loader.supportedStorers.insert(Storer::into(&rowSets));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&rowSets));
}
void
diff --git a/project2/common/xmlStorage.h b/project2/common/xmlStorage.h
index a700c64..ceae899 100644
--- a/project2/common/xmlStorage.h
+++ b/project2/common/xmlStorage.h
@@ -2,6 +2,7 @@
#define XMLSTORAGE_H
#include "sourceObject.h"
+#include "xmlObjectLoader.h"
#include "exceptions.h"
#include <set>
#include <list>
@@ -23,43 +24,48 @@ class Storer;
typedef boost::intrusive_ptr<Storer> StorerPtr;
class Storer : public virtual IntrusivePtrBase {
public:
- template <class X>
+ template <class L, class X>
static StorerPtr into(SINGLE(X) * obj);
- template <class X>
+ template <class L, class X>
static StorerPtr into(STORAGEOF(X) * map);
- template <class X>
+ template <class L, class X>
static StorerPtr into(ANONSTORAGEOF(X) * set);
- template <class X>
+ template <class L, class X>
static StorerPtr into(ANONORDEREDSTORAGEOF(X) * list);
- virtual bool save(SourceObjectPtr o, const xmlpp::Element *) = 0;
+ virtual boost::intrusive_ptr<IntrusivePtrBase> save(const xmlpp::Element *) = 0;
};
-template <class X, class M = STORAGEOF(X)>
+template <class X, class M, class L>
class StorerBase : public Storer {
public:
typedef M * Map;
- bool save(SourceObjectPtr obj, const xmlpp::Element * p) {
- boost::intrusive_ptr<X> O = boost::dynamic_pointer_cast<X>(obj);
- if (O) {
- if (insert(p, O)) {
- return true;
+ boost::intrusive_ptr<IntrusivePtrBase> save(const xmlpp::Element * p) {
+ try {
+ boost::intrusive_ptr<X> O = boost::dynamic_pointer_cast<X>(
+ LoaderBase::getLoader<L, NotSupported>(p->get_name())->createFrom(p));
+ if (O) {
+ if (!insert(p, O)) {
+ throw StoreFailed(p->get_attribute_value("name"));
+ }
}
- throw StoreFailed(obj->name);
+ return O;
+ }
+ catch (NotSupported) {
+ return NULL;
}
- return false;
}
virtual bool insert(const xmlpp::Element *, boost::intrusive_ptr<X>) = 0;
};
-template <class X, class M = STORAGEOF(X)>
-class StorerImpl : public StorerBase<X, M> {
+template <class X, class M, class L>
+class StorerImpl : public StorerBase<X, M, L> {
public:
StorerImpl(M * m);
bool insert(const xmlpp::Element *, boost::intrusive_ptr<X> O);
};
-template <class X>
-class StorerImpl<X, SINGLE(X)> : public StorerBase<X, SINGLE(X)> {
+template <class X, class L>
+class StorerImpl<X, SINGLE(X), L> : public StorerBase<X, SINGLE(X), L> {
public:
typedef SINGLE(X) Obj;
StorerImpl(SINGLE(X) * o) : obj(o)
@@ -72,8 +78,8 @@ class StorerImpl<X, SINGLE(X)> : public StorerBase<X, SINGLE(X)> {
}
Obj * obj;
};
-template <class X>
-class StorerImpl<X, STORAGEOF(X)> : public StorerBase<X, STORAGEOF(X)> {
+template <class X, class L>
+class StorerImpl<X, STORAGEOF(X), L> : public StorerBase<X, STORAGEOF(X), L> {
public:
typedef STORAGEOF(X) Map;
StorerImpl(STORAGEOF(X) * m) : map(m)
@@ -85,8 +91,8 @@ class StorerImpl<X, STORAGEOF(X)> : public StorerBase<X, STORAGEOF(X)> {
}
Map * map;
};
-template <class X>
-class StorerImpl<X, ANONSTORAGEOF(X)> : public StorerBase<X, ANONSTORAGEOF(X)> {
+template <class X, class L>
+class StorerImpl<X, ANONSTORAGEOF(X), L> : public StorerBase<X, ANONSTORAGEOF(X), L> {
public:
typedef ANONSTORAGEOF(X) Map;
StorerImpl(ANONSTORAGEOF(X) * m) : map(m)
@@ -99,8 +105,8 @@ class StorerImpl<X, ANONSTORAGEOF(X)> : public StorerBase<X, ANONSTORAGEOF(X)> {
}
Map * map;
};
-template <class X>
-class StorerImpl<X, ANONORDEREDSTORAGEOF(X)> : public StorerBase<X, ANONORDEREDSTORAGEOF(X)> {
+template <class X, class L>
+class StorerImpl<X, ANONORDEREDSTORAGEOF(X), L> : public StorerBase<X, ANONORDEREDSTORAGEOF(X), L> {
public:
typedef ANONORDEREDSTORAGEOF(X) Map;
StorerImpl(ANONORDEREDSTORAGEOF(X) * m) : map(m)
@@ -114,28 +120,28 @@ class StorerImpl<X, ANONORDEREDSTORAGEOF(X)> : public StorerBase<X, ANONORDEREDS
Map * map;
};
-template <class X>
+template <class L, class X>
StorerPtr
Storer::into(SINGLE(X) * obj) {
- return new StorerImpl<X, SINGLE(X)>(obj);
+ return new StorerImpl<X, SINGLE(X), L>(obj);
}
-template <class X>
+template <class L, class X>
StorerPtr
Storer::into(STORAGEOF(X) * map) {
- return new StorerImpl<X, STORAGEOF(X)>(map);
+ return new StorerImpl<X, STORAGEOF(X), L>(map);
}
-template <class X>
+template <class L, class X>
StorerPtr
Storer::into(ANONSTORAGEOF(X) * set) {
- return new StorerImpl<X, ANONSTORAGEOF(X)>(set);
+ return new StorerImpl<X, ANONSTORAGEOF(X), L>(set);
}
-template <class X>
+template <class L, class X>
StorerPtr
Storer::into(ANONORDEREDSTORAGEOF(X) * list) {
- return new StorerImpl<X, ANONORDEREDSTORAGEOF(X)>(list);
+ return new StorerImpl<X, ANONORDEREDSTORAGEOF(X), L>(list);
}
#endif
diff --git a/project2/sql/sqlMergeTask.cpp b/project2/sql/sqlMergeTask.cpp
index f98d57e..96a895a 100644
--- a/project2/sql/sqlMergeTask.cpp
+++ b/project2/sql/sqlMergeTask.cpp
@@ -58,7 +58,7 @@ SqlMergeTask::SqlMergeTask(const xmlpp::Element * p) :
dtablet(stringf("tmp_%s_%d", dtable.c_str(), getpid()))
{
LoaderBase loader(true);
- loader.supportedStorers.insert(Storer::into(&sources));
+ loader.supportedStorers.insert(Storer::into<ElementLoader>(&sources));
loader.collectAll(p, true);
if (!sources.empty() && useView()) {
diff --git a/project2/sql/sqlTask.cpp b/project2/sql/sqlTask.cpp
index 63f73a9..9f881de 100644
--- a/project2/sql/sqlTask.cpp
+++ b/project2/sql/sqlTask.cpp
@@ -10,7 +10,7 @@
DECLARE_LOADER("sqltask", SqlTask);
StaticMessageException(RunOnNotSpecified, "runon attribute must be specified");
-class SqlIfChangesStorer : public StorerBase<NoOutputExecute, ANONORDEREDSTORAGEOF(NoOutputExecute)> {
+class SqlIfChangesStorer : public StorerBase<NoOutputExecute, ANONORDEREDSTORAGEOF(NoOutputExecute), ElementLoader> {
public:
SqlIfChangesStorer(Map c, Map nc) :
changes(c),