summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-08-14 22:27:20 +0000
committerrandomdan <randomdan@localhost>2011-08-14 22:27:20 +0000
commitb4f3b67b0c1f22d1fc50aecf9100f10a653b903e (patch)
tree190d1de7a3f10cdf42ffe9d102a1e674bbee669d
parentDon't use parameters in sqlCheck anymore... just like sqlTask yesterday (diff)
downloadproject2-b4f3b67b0c1f22d1fc50aecf9100f10a653b903e.tar.bz2
project2-b4f3b67b0c1f22d1fc50aecf9100f10a653b903e.tar.xz
project2-b4f3b67b0c1f22d1fc50aecf9100f10a653b903e.zip
Extend literal variables to support composing strings from other variables and literals like sqlWriter does
-rw-r--r--project2/variables.cpp64
1 files changed, 59 insertions, 5 deletions
diff --git a/project2/variables.cpp b/project2/variables.cpp
index 7e7ea2c..b866165 100644
--- a/project2/variables.cpp
+++ b/project2/variables.cpp
@@ -123,17 +123,71 @@ class VariableLiteral : public VariableImpl {
if (const xmlpp::Attribute * la = c->get_attribute("value")) {
val = makeVariableType(la->get_value(), getVariableTypeFromName(c->get_attribute_value("type")));
}
- else if (const xmlpp::TextNode * t = c->get_child_text()) {
- val = makeVariableType(t->get_content(), getVariableTypeFromName(c->get_attribute_value("type")));
- }
else {
- val = VariableType();
+ BOOST_FOREACH(const xmlpp::Node * n, c->get_children()) {
+ if (const xmlpp::Element * e = dynamic_cast<const xmlpp::Element *>(n)) {
+ vals.push_back(new VarPart(e));
+ }
+ else if (const xmlpp::TextNode * t = dynamic_cast<const xmlpp::TextNode *>(n)) {
+ vals.push_back(new TextPart(t));
+ }
+ }
}
}
- virtual VariableType value() const { return val; }
+ virtual VariableType value() const
+ {
+ if (vals.empty()) {
+ return val;
+ }
+ if (vals.size() == 1) {
+ return *vals.front();
+ }
+ Glib::ustring v;
+ BOOST_FOREACH(PartCPtr p, vals) {
+ p->appendTo(v);
+ }
+ return v;
+ }
private:
VariableType val;
+ class Part : public IntrusivePtrBase {
+ public:
+ virtual void appendTo(Glib::ustring & str) const = 0;
+ virtual operator VariableType() const = 0;
+ };
+ class TextPart : public Part {
+ public:
+ TextPart(const xmlpp::TextNode * e) :
+ txt(e->get_content())
+ {
+ }
+ void appendTo(Glib::ustring & str) const
+ {
+ str += txt;
+ }
+ operator VariableType() const
+ {
+ return txt;
+ }
+ const Glib::ustring txt;
+ };
+ class VarPart : public Part, public Variable {
+ public:
+ VarPart(const xmlpp::Element * e) : Variable(e, boost::optional<Glib::ustring>())
+ {
+ }
+ void appendTo(Glib::ustring & str) const
+ {
+ str += (*this)().operator const Glib::ustring &();
+ }
+ operator VariableType() const
+ {
+ return (*this)();
+ }
+ };
+ typedef boost::intrusive_ptr<Part> PartCPtr;
+ std::list<PartCPtr> vals;
};
DECLARE_COMPONENT_LOADER("literal", VariableLiteral, VariableLoader);
DECLARE_CUSTOM_COMPONENT_LOADER("", VariableLiteralDef, VariableLoaderImpl<VariableLiteral>, VariableLoader);