summaryrefslogtreecommitdiff
path: root/project2/sql/sqlWriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/sql/sqlWriter.cpp')
-rw-r--r--project2/sql/sqlWriter.cpp67
1 files changed, 33 insertions, 34 deletions
diff --git a/project2/sql/sqlWriter.cpp b/project2/sql/sqlWriter.cpp
index 90de82f..867e1bd 100644
--- a/project2/sql/sqlWriter.cpp
+++ b/project2/sql/sqlWriter.cpp
@@ -11,25 +11,33 @@ DynamicSql::SqlWriter::~SqlWriter()
{
}
-DynamicSql::SqlCommand::SqlCommand(const xmlpp::Element * N)
+template <typename Type, typename Cons>
+static
+void
+appendNew(DynamicSql::Writers * w, const Cons & cons)
{
- BOOST_FOREACH(xmlpp::Node * n, N->get_children()) {
- const xmlpp::TextNode * t = dynamic_cast<const xmlpp::TextNode *>(n);
- if (t) {
- writers.push_back(new SqlText(t));
- }
- const xmlpp::Element * e = dynamic_cast<const xmlpp::Element *>(n);
- if (e) {
- if (e->get_name() == "filter") {
- SqlFilterPtr f = new SqlFilter(e);
- writers.push_back(f);
- filters.insert(Filters::value_type(f->name, f));
- }
- else if (e->get_name() == "param") {
- writers.push_back(new SqlParameter(e));
- }
- }
+ w->push_back(new Type(cons));
+}
+
+static
+void
+appendNewFromNode(DynamicSql::Writers * w, DynamicSql::SqlCommand::Filters * fs, ScriptNodePtr p)
+{
+ if (fs && p->get_name() == "filter") {
+ DynamicSql::SqlFilterPtr f = new DynamicSql::SqlFilter(p);
+ w->push_back(f);
+ fs->insert(DynamicSql::SqlCommand::Filters::value_type(f->name, f));
}
+ else if (p->get_name() == "param") {
+ w->push_back(new DynamicSql::SqlParameter(p));
+ }
+}
+
+DynamicSql::SqlCommand::SqlCommand(ScriptNodePtr s)
+{
+ s->composeWithCallbacks(
+ boost::bind(&appendNew<SqlText, Glib::ustring>, &writers, _1),
+ boost::bind(&appendNewFromNode, &writers, &filters, _1));
}
Glib::ustring
@@ -59,22 +67,13 @@ DynamicSql::SqlCommand::bindParams(DB::Command * cmd, unsigned int & offset) con
}
}
-DynamicSql::SqlFilter::SqlFilter(const xmlpp::Element * N) :
- name(N->get_attribute_value("name")),
+DynamicSql::SqlFilter::SqlFilter(ScriptNodePtr p) :
+ name(p->value("name").as<Glib::ustring>()),
active(false)
{
- BOOST_FOREACH(xmlpp::Node * n, N->get_children()) {
- const xmlpp::TextNode * t = dynamic_cast<const xmlpp::TextNode *>(n);
- if (t) {
- writers.push_back(new SqlText(t));
- }
- const xmlpp::Element * e = dynamic_cast<const xmlpp::Element *>(n);
- if (e) {
- if (e->get_name() == "param") {
- writers.push_back(new SqlParameter(e));
- }
- }
- }
+ p->composeWithCallbacks(
+ boost::bind(&appendNew<SqlText, Glib::ustring>, &writers, _1),
+ boost::bind(&appendNewFromNode, &writers, (DynamicSql::SqlCommand::Filters *)NULL, _1));
}
void
@@ -97,7 +96,7 @@ DynamicSql::SqlFilter::bindParams(DB::Command * cmd, unsigned int & offset) cons
}
}
-DynamicSql::SqlParameter::SqlParameter(const xmlpp::Element * n) :
+DynamicSql::SqlParameter::SqlParameter(ScriptNodePtr n) :
Variable(n, boost::optional<Glib::ustring>("local"))
{
}
@@ -114,8 +113,8 @@ DynamicSql::SqlParameter::bindParams(DB::Command * cmd, unsigned int & offset) c
boost::apply_visitor<const SqlVariableBinder, const VariableType>(SqlVariableBinder(cmd, offset++), (*this));
}
-DynamicSql::SqlText::SqlText(const xmlpp::TextNode * n) :
- text(n->get_content())
+DynamicSql::SqlText::SqlText(const Glib::ustring & n) :
+ text(n)
{
}