From fb985d981bf3126545903a2e11df3a026bae8d53 Mon Sep 17 00:00:00 2001 From: randomdan Date: Sun, 18 Mar 2012 17:04:26 +0000 Subject: Centralise variable null checking --- project2/common/rowSet.cpp | 6 +++--- project2/common/variables.cpp | 6 ++++++ project2/common/variables.h | 1 + project2/xml/xmlPresenter.cpp | 2 +- project2/xml/xpathRows.cpp | 2 +- 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::type::iterator di = columns.get().find(col); if (di != columns.get().end()) { - if (!boost::get(&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()); +} + 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 T as() const { return *this; } template const T * get() const { return boost::get(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()) { + 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()) { const FilterViewColumn * xp = static_cast(_xp.get()); const VariableType & path(xp->path); - if (boost::get(&path)) { + if (path.isNull()) { continue; } xmlXPathObjectSPtr xpathObjI = xmlXPathObjectSPtr(xmlXPathEvalExpression(path, xpathCtx.get()), xmlXPathFreeObject); -- cgit v1.2.3