summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2012-03-18 17:04:26 +0000
committerrandomdan <randomdan@localhost>2012-03-18 17:04:26 +0000
commitfb985d981bf3126545903a2e11df3a026bae8d53 (patch)
tree9d60a5babb299701c294fe7e430f0e136fd7e02a
parentRowProcessor level record filtering (diff)
downloadproject2-fb985d981bf3126545903a2e11df3a026bae8d53.tar.bz2
project2-fb985d981bf3126545903a2e11df3a026bae8d53.tar.xz
project2-fb985d981bf3126545903a2e11df3a026bae8d53.zip
Centralise variable null checking
-rw-r--r--project2/common/rowSet.cpp6
-rw-r--r--project2/common/variables.cpp6
-rw-r--r--project2/common/variables.h1
-rw-r--r--project2/xml/xmlPresenter.cpp2
-rw-r--r--project2/xml/xpathRows.cpp2
5 files changed, 12 insertions, 5 deletions
diff --git a/project2/common/rowSet.cpp b/project2/common/rowSet.cpp
index cc397d1..0378b51 100644
--- a/project2/common/rowSet.cpp
+++ b/project2/common/rowSet.cpp
@@ -75,10 +75,10 @@ RowState::getCurrentValue(const Glib::ustring & col) const
const Columns & columns = getColumns();
Columns::index<byColName>::type::iterator di = columns.get<byColName>().find(col);
if (di != columns.get<byColName>().end()) {
- if (!boost::get<Null>(&fields[(*di)->idx])) {
- return fields[(*di)->idx];
+ if (fields[(*di)->idx].isNull()) {
+ return (*di)->defValue;
}
- return (*di)->defValue;
+ return fields[(*di)->idx];
}
throw RowSet::FieldDoesNotExist(col);
}
diff --git a/project2/common/variables.cpp b/project2/common/variables.cpp
index de0690b..7455e2c 100644
--- a/project2/common/variables.cpp
+++ b/project2/common/variables.cpp
@@ -200,6 +200,12 @@ VariableType::operator<(const VariableType & b) const
return false;
}
+bool
+VariableType::isNull() const
+{
+ return (get<Null>());
+}
+
VariableImplDyn::VariableImplDyn(ScriptNodePtr e)
{
if (e) {
diff --git a/project2/common/variables.h b/project2/common/variables.h
index 2757ade..ca2cdc7 100644
--- a/project2/common/variables.h
+++ b/project2/common/variables.h
@@ -88,6 +88,7 @@ class VariableType : public _VT {
operator double() const;
operator const boost::posix_time::ptime &() const;
operator bool() const;
+ bool isNull() const;
template <typename T> T as() const { return *this; }
template <typename T> const T * get() const { return boost::get<T>(this); }
diff --git a/project2/xml/xmlPresenter.cpp b/project2/xml/xmlPresenter.cpp
index 37239fa..2650186 100644
--- a/project2/xml/xmlPresenter.cpp
+++ b/project2/xml/xmlPresenter.cpp
@@ -140,7 +140,7 @@ XmlPresenter::pushSub(const Glib::ustring & name, const Glib::ustring & ns) cons
void
XmlPresenter::addAttribute(const Glib::ustring & name, const Glib::ustring & ns, const VariableType & value) const
{
- if (!value.get<Null>()) {
+ if (!value.isNull()) {
nodeStack.back()->set_attribute(name, value, ns);
}
}
diff --git a/project2/xml/xpathRows.cpp b/project2/xml/xpathRows.cpp
index c4fde3b..2d8ea8a 100644
--- a/project2/xml/xpathRows.cpp
+++ b/project2/xml/xpathRows.cpp
@@ -82,7 +82,7 @@ XPathRows::execute(const Glib::ustring & filter, const RowProcessor * rp) const
BOOST_FOREACH(const Columns::value_type & _xp, fv->columns.get<byColIdx>()) {
const FilterViewColumn * xp = static_cast<const FilterViewColumn *>(_xp.get());
const VariableType & path(xp->path);
- if (boost::get<Null>(&path)) {
+ if (path.isNull()) {
continue;
}
xmlXPathObjectSPtr xpathObjI = xmlXPathObjectSPtr(xmlXPathEvalExpression(path, xpathCtx.get()), xmlXPathFreeObject);