summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-12-22 17:25:41 +0000
committerrandomdan <randomdan@localhost>2011-12-22 17:25:41 +0000
commit313c4560ed8a12db4517da1fc0946bce0fff6310 (patch)
tree1525121e36055c4a176e3d4f9b277cebc9b72824
parentStore options set name (diff)
downloadproject2-313c4560ed8a12db4517da1fc0946bce0fff6310.tar.bz2
project2-313c4560ed8a12db4517da1fc0946bce0fff6310.tar.xz
project2-313c4560ed8a12db4517da1fc0946bce0fff6310.zip
Generalise code from structuredExceptionHandler for loaded sub component sets and use it to standardise sqlTask's conditional children
-rw-r--r--project2/common/scriptLoader.cpp29
-rw-r--r--project2/common/scriptLoader.h3
-rw-r--r--project2/common/scriptStorage.h20
-rw-r--r--project2/common/structExceptHandling.cpp32
-rw-r--r--project2/sql/sqlTask.cpp22
5 files changed, 44 insertions, 62 deletions
diff --git a/project2/common/scriptLoader.cpp b/project2/common/scriptLoader.cpp
index 42f826e..6a0f0b3 100644
--- a/project2/common/scriptLoader.cpp
+++ b/project2/common/scriptLoader.cpp
@@ -41,7 +41,32 @@ LoaderBase::addLoadTarget(ScriptNodePtr src, boost::intrusive_ptr<Storer> target
targets[src].push_back(target);
}
- std::set<boost::shared_ptr<ComponentLoader> > * &
+void
+LoaderBase::addLoadTargetSub(ScriptNodePtr src, const Glib::ustring & name, bool required, boost::intrusive_ptr<Storer> target)
+{
+ if (ScriptNodePtr c = getSub(src, name, required)) {
+ src->script->loader.addLoadTarget(c, target);
+ }
+}
+
+ScriptNodePtr
+LoaderBase::getSub(ScriptNodePtr root, const Glib::ustring & name, bool required)
+{
+ if (required) {
+ return root->child(name);
+ }
+ else {
+ try {
+ return root->child(name);
+ }
+ catch (const ValueNotFound &) {
+ return NULL;
+ }
+ }
+}
+
+
+std::set<boost::shared_ptr<ComponentLoader> > * &
LoaderBase::componentLoaders()
{
static std::set<boost::shared_ptr<ComponentLoader> > * _compLoaders = NULL;
@@ -73,7 +98,7 @@ LoaderBase::collectAll(ScriptNodePtr node, bool childrenOnly, const StorerPtrs &
throw NotSupported(name);
}
BOOST_FOREACH(const StorerPtr & s, sts) {
- if (s->save(o, node)) {
+ if (s->save(o, name)) {
stored += 1;
break;
}
diff --git a/project2/common/scriptLoader.h b/project2/common/scriptLoader.h
index d916821..6878983 100644
--- a/project2/common/scriptLoader.h
+++ b/project2/common/scriptLoader.h
@@ -13,7 +13,6 @@
#include <map>
#include <vector>
-enum UnsupportedHandling { ErrorOnUnsupported, WarnOnUnsupported, IgnoreUnsupported };
class ElementLoader;
class ComponentLoader;
class CommonObjects;
@@ -31,6 +30,7 @@ class LoaderBase {
void collectAll(const CommonObjects * co, bool childrenOnly, ScriptNodePtr script);
void addLoadTarget(ScriptNodePtr src, boost::intrusive_ptr<Storer> target);
+ void addLoadTargetSub(ScriptNodePtr src, const Glib::ustring & name, bool required, boost::intrusive_ptr<Storer> target);
static void onAllComponents(const boost::function1<void, ComponentLoader *> &);
@@ -86,6 +86,7 @@ class LoaderBase {
private:
void collectAll(ScriptNodePtr script, bool childrenOnly, const StorerPtrs & sts) const;
+ static ScriptNodePtr getSub(ScriptNodePtr root, const Glib::ustring & name, bool required);
Targets targets;
static unsigned int depth;
template <class X> friend class ElementLoaderImpl;
diff --git a/project2/common/scriptStorage.h b/project2/common/scriptStorage.h
index d5daf95..0187cb4 100644
--- a/project2/common/scriptStorage.h
+++ b/project2/common/scriptStorage.h
@@ -35,7 +35,7 @@ class Storer : public virtual IntrusivePtrBase {
static StorerPtr into(ANONORDEREDSTORAGEOF(X) * list);
virtual boost::intrusive_ptr<IntrusivePtrBase> create(ScriptNodePtr) const = 0;
- virtual bool save(boost::intrusive_ptr<IntrusivePtrBase>, ScriptNodePtr) = 0;
+ virtual bool save(boost::intrusive_ptr<IntrusivePtrBase>, const Glib::ustring &) = 0;
};
template <class X, class M, class L>
@@ -45,23 +45,23 @@ class StorerBase : public Storer {
boost::intrusive_ptr<IntrusivePtrBase> create(ScriptNodePtr p) const {
return LoaderBase::getLoader<L, NotSupported>(p->get_name())->createFrom(p);
}
- bool save(boost::intrusive_ptr<IntrusivePtrBase> o, ScriptNodePtr p) {
+ bool save(boost::intrusive_ptr<IntrusivePtrBase> o, const Glib::ustring & name) {
boost::intrusive_ptr<X> O = boost::dynamic_pointer_cast<X>(o);
if (O) {
- if (!insert(p, O)) {
- throw StoreFailed(p->get_name());
+ if (!insert(O)) {
+ throw StoreFailed(name);
}
}
return O;
}
- virtual bool insert(ScriptNodePtr, boost::intrusive_ptr<X>) = 0;
+ virtual bool insert(boost::intrusive_ptr<X>) = 0;
};
template <class X, class M, class L>
class StorerImpl : public StorerBase<X, M, L> {
public:
StorerImpl(M * m);
- bool insert(ScriptNodePtr, boost::intrusive_ptr<X> O);
+ bool insert(boost::intrusive_ptr<X> O);
};
template <class X, class L>
class StorerImpl<X, SINGLE(X), L> : public StorerBase<X, SINGLE(X), L> {
@@ -70,7 +70,7 @@ class StorerImpl<X, SINGLE(X), L> : public StorerBase<X, SINGLE(X), L> {
StorerImpl(SINGLE(X) * o) : obj(o)
{
}
- bool insert(ScriptNodePtr, boost::intrusive_ptr<X> O)
+ bool insert(boost::intrusive_ptr<X> O)
{
*obj = O;
return true;
@@ -84,7 +84,7 @@ class StorerImpl<X, STORAGEOF(X), L> : public StorerBase<X, STORAGEOF(X), L> {
StorerImpl(STORAGEOF(X) * m) : map(m)
{
}
- bool insert(ScriptNodePtr, boost::intrusive_ptr<X> O)
+ bool insert(boost::intrusive_ptr<X> O)
{
return map->insert(typename Map::value_type(O->name, O)).second;
}
@@ -97,7 +97,7 @@ class StorerImpl<X, ANONSTORAGEOF(X), L> : public StorerBase<X, ANONSTORAGEOF(X)
StorerImpl(ANONSTORAGEOF(X) * m) : map(m)
{
}
- bool insert(ScriptNodePtr, boost::intrusive_ptr<X> O)
+ bool insert(boost::intrusive_ptr<X> O)
{
map->insert(O);
return true;
@@ -111,7 +111,7 @@ class StorerImpl<X, ANONORDEREDSTORAGEOF(X), L> : public StorerBase<X, ANONORDER
StorerImpl(ANONORDEREDSTORAGEOF(X) * m) : map(m)
{
}
- bool insert(ScriptNodePtr, boost::intrusive_ptr<X> O)
+ bool insert(boost::intrusive_ptr<X> O)
{
map->push_back(O);
return true;
diff --git a/project2/common/structExceptHandling.cpp b/project2/common/structExceptHandling.cpp
index 3820ce8..0881d6d 100644
--- a/project2/common/structExceptHandling.cpp
+++ b/project2/common/structExceptHandling.cpp
@@ -7,39 +7,13 @@
DECLARE_LOADER("handler", StructuredExceptionHandler);
-static
-ScriptNodePtr
-loadHelperSub(const char * name, bool required, ScriptNodePtr root)
-{
- if (required) {
- return root->child(name);
- }
- else {
- try {
- return root->child(name);
- }
- catch (const ValueNotFound &) {
- return NULL;
- }
- }
-}
-static
-void
-loadHelper(const char * name, bool required, ScriptNodePtr root, ANONORDEREDSTORAGEOF(NoOutputExecute) * noes)
-{
- ScriptNodePtr c = loadHelperSub(name, required, root);
- if (c) {
- root->script->loader.addLoadTarget(c, Storer::into<ElementLoader>(noes));
- }
-}
-
StructuredExceptionHandler::StructuredExceptionHandler(ScriptNodePtr e) :
SourceObject(e),
IHaveSubTasks(e)
{
- loadHelper("try", true, e, &normal);
- loadHelper("catch", false, e, &catches);
- loadHelper("finally", false, e, &finallies);
+ e->script->loader.addLoadTargetSub(e, "try", true, Storer::into<ElementLoader>(&normal));
+ e->script->loader.addLoadTargetSub(e, "catch", false, Storer::into<ElementLoader>(&catches));
+ e->script->loader.addLoadTargetSub(e, "finally", false, Storer::into<ElementLoader>(&finallies));
}
void
diff --git a/project2/sql/sqlTask.cpp b/project2/sql/sqlTask.cpp
index 6855cc0..852069d 100644
--- a/project2/sql/sqlTask.cpp
+++ b/project2/sql/sqlTask.cpp
@@ -10,25 +10,6 @@
DECLARE_LOADER("sqltask", SqlTask);
StaticMessageException(RunOnNotSpecified, "runon attribute must be specified");
-class SqlIfChangesStorer : public StorerBase<NoOutputExecute, ANONORDEREDSTORAGEOF(NoOutputExecute), ElementLoader> {
- public:
- SqlIfChangesStorer(Map c, Map nc) :
- changes(c),
- noChanges(nc)
- {
- }
- bool insert(ScriptNodePtr p, NoOutputExecutePtr O) {
- try {
- ((p->value("runon").as<std::string>() == "changes") ? changes : noChanges)->push_back(O);
- return true;
- }
- catch (const ValueNotFound &) {
- throw RunOnNotSpecified();
- }
- }
- Map changes, noChanges;
-};
-
SqlTask::SqlTask(ScriptNodePtr p) :
SourceObject(p),
Task(p),
@@ -36,7 +17,8 @@ SqlTask::SqlTask(ScriptNodePtr p) :
filter(p, "filter", ""),
sqlCommand(p->child("sql"))
{
- p->script->loader.addLoadTarget(p, new SqlIfChangesStorer(&changesNOEs, &noChangesNOEs));
+ p->script->loader.addLoadTargetSub(p, "changes", false, Storer::into<ElementLoader>(&changesNOEs));
+ p->script->loader.addLoadTargetSub(p, "nochanges", false, Storer::into<ElementLoader>(&noChangesNOEs));
}
SqlTask::~SqlTask()