diff options
author | randomdan <randomdan@localhost> | 2011-08-14 22:27:20 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-08-14 22:27:20 +0000 |
commit | 5143aef7ad1f4a0aa9cd45dace81afd6bb0a3942 (patch) | |
tree | 190d1de7a3f10cdf42ffe9d102a1e674bbee669d | |
parent | Don't use parameters in sqlCheck anymore... just like sqlTask yesterday (diff) | |
download | project2-5143aef7ad1f4a0aa9cd45dace81afd6bb0a3942.tar.bz2 project2-5143aef7ad1f4a0aa9cd45dace81afd6bb0a3942.tar.xz project2-5143aef7ad1f4a0aa9cd45dace81afd6bb0a3942.zip |
Extend literal variables to support composing strings from other variables and literals like sqlWriter does
-rw-r--r-- | project2/variables.cpp | 64 |
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); |