summaryrefslogtreecommitdiff
path: root/project2/variables.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/variables.cpp')
-rw-r--r--project2/variables.cpp56
1 files changed, 28 insertions, 28 deletions
diff --git a/project2/variables.cpp b/project2/variables.cpp
index b0aecea..2267e8b 100644
--- a/project2/variables.cpp
+++ b/project2/variables.cpp
@@ -5,6 +5,7 @@
#include "rowUser.h"
#include <libxml++/nodes/textnode.h>
#include <stdexcept>
+#include <syslog.h>
#include <boost/tokenizer.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/predicate.hpp>
@@ -22,7 +23,6 @@ class VariableLiteral : public VariableImpl {
class VariableImplDyn : public VariableImpl {
public:
VariableImplDyn(const Glib::ustring & src) : VariableImpl(src), cacheValid(false) { }
- VariableImplDyn(const Glib::ustring & src, boost::optional<Glib::ustring> def) : VariableImpl(src, def), cacheValid(false) { }
virtual const Glib::ustring & value() const = 0;
protected:
@@ -90,23 +90,38 @@ class VariableUri : public VariableImplDyn {
}
};
+template <class T>
+static void assignHelper(Glib::ustring & dest, const T & src) {
+ const Glib::ustring * srcp = boost::get<const Glib::ustring>(&src);
+ if (srcp) {
+ dest = *srcp;
+ }
+ else {
+ dest = boost::lexical_cast<Glib::ustring>(src);
+ }
+}
+template <>
+void assignHelper(Glib::ustring & dest, const Glib::ustring & src) {
+ dest = src;
+}
+
class VariableParent : public VariableImplDyn, public RowUser {
public:
VariableParent(const Glib::ustring & src, const RowUser * d) :
- VariableImplDyn(Glib::ustring(std::find_if(src.begin(), src.end(), isalpha), src.end())),
+ VariableImplDyn(src),
row(NULL),
- depth(src.length() - source.length()),
+ depth(src.find_first_not_of('^')),
+ attr(src[depth] == '!'),
dep(d)
{
- bind();
}
VariableParent(const Glib::ustring & name, unsigned int d) :
- VariableImplDyn(name, NULL),
+ VariableImplDyn(name),
row(NULL),
depth(d),
+ attr(name[0] == '!'),
dep(NULL)
{
- bind();
}
~VariableParent()
{
@@ -132,6 +147,7 @@ class VariableParent : public VariableImplDyn, public RowUser {
if (dep) {
row->use(dep);
}
+ bind();
}
getValue(cache, row);
}
@@ -156,31 +172,22 @@ class VariableParent : public VariableImplDyn, public RowUser {
cacheValid = false;
}
protected:
- static void assignHelper(Glib::ustring & dest, const Glib::ustring & src) {
- dest = src;
- }
- void bind()
+ void bind() const
{
- if (name[0] == '!') {
- if (name == "!rownum") {
- getValue = boost::bind(&assignHelper, _1,
- boost::bind(&boost::lexical_cast<Glib::ustring, unsigned int>,
- boost::bind(&RowSet::getRowNum, _2)));
- }
- else {
- throw RowSet::FieldDoesNotExist();
- }
+ if (attr) {
+ getValue = boost::bind(&assignHelper<VariableType>, _1, boost::bind(row->resolveAttr(name)));
}
else {
typedef const Glib::ustring & (RowSet::*gCV)(const Glib::ustring &) const;
- getValue = boost::bind(&assignHelper, _1,
+ getValue = boost::bind(&assignHelper<Glib::ustring>, _1,
boost::bind((gCV)&RowSet::getCurrentValue, _2, name));
}
}
mutable const RowSet * row;
const size_t depth;
+ const bool attr;
const RowUser * dep;
- boost::function2<void, Glib::ustring &, const RowSet *> getValue;
+ mutable boost::function2<void, Glib::ustring &, const RowSet *> getValue;
};
class VariableParse : public VariableImplDyn, public RowUser {
@@ -270,13 +277,6 @@ Variable::makeParent(const Glib::ustring & n, unsigned int d)
return Variable(new VariableParent(n, d));
}
-VariableImpl::VariableImpl(const Glib::ustring & src, boost::optional<Glib::ustring> def) :
- source(src),
- name(src),
- defaultValue(def)
-{
-}
-
VariableImpl::VariableImpl(const Glib::ustring & src) :
source(src)
{