From 3e8b88da1e18d504ec0388166fb374483a07e735 Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 18 Feb 2011 20:50:35 +0000 Subject: Fix behaviour of stream rows with blank rows Add support for default values of blank columns in stream rows --- project2/streamRows.cpp | 38 +++++++++++++++++++++++++++++--------- project2/streamRows.h | 2 ++ project2/variables.cpp | 9 ++++++++- project2/variables.h | 1 + 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/project2/streamRows.cpp b/project2/streamRows.cpp index d214e01..47832ac 100644 --- a/project2/streamRows.cpp +++ b/project2/streamRows.cpp @@ -21,7 +21,7 @@ StreamRows::StreamRows(const xmlpp::Element * p) : BOOST_FOREACH(const xmlpp::Node * node, p->find("columns/column")) { const xmlpp::Element * elem = dynamic_cast(node); if (elem) { - columns.insert(Column(colNo++, elem->get_child_text()->get_content())); + columns.insert(Column(colNo++, elem)); } } mkCols = columns.empty(); @@ -95,7 +95,15 @@ StreamRows::addColumn(Glib::ustring & tok) const StreamRows::Column::Column(unsigned int i, const Glib::ustring & c) : idx(i), - col(c) + col(c), + defValue(VariableType()) +{ +} + +StreamRows::Column::Column(unsigned int i, const xmlpp::Element * p) : + idx(i), + col(p->get_child_text()->get_content()), + defValue(p, "default", false) { } @@ -125,16 +133,24 @@ StreamRows::pushChar(gunichar c, const RowProcessor * rp) const if (!tok->empty()) { *curCol++ = VariableType(tok); } - while (curCol != columns.get().end()) { - *curCol++ = VariableType(); + if (keepBlankRows || curCol != columns.get().begin()) { + while (curCol != columns.get().end()) { + *curCol++ = curCol->defValue; + } + rp->rowReady(); + rowNum += 1; + } + else if (countBlankRows) { + rowNum += 1; } - rp->rowReady(); - rowNum += 1; - curCol = columns.get().begin(); } else { + if (!tok->empty()) { + addColumn(*tok); + } mkCols = false; } + curCol = columns.get().begin(); } tok = StringPtr(new Glib::ustring()); } @@ -180,13 +196,17 @@ StreamRows::end(const RowProcessor * rp) const } } } - if (curCol != columns.get().begin()) { + if (keepBlankRows || curCol != columns.get().begin()) { while (curCol != columns.get().end()) { - *curCol++ = VariableType(); + *curCol++ = curCol->defValue; } rp->rowReady(); rowNum += 1; } + else if (countBlankRows) { + rowNum += 1; + } + curCol = columns.get().begin(); tok = StringPtr(new Glib::ustring()); } diff --git a/project2/streamRows.h b/project2/streamRows.h index ffe2dc6..6187f12 100644 --- a/project2/streamRows.h +++ b/project2/streamRows.h @@ -29,12 +29,14 @@ class StreamRows : public RowSet { class Column { public: Column(unsigned int idx, const Glib::ustring &); + Column(unsigned int idx, const xmlpp::Element * p); void operator=(const VariableType &) const; const unsigned int idx; const Glib::ustring col; mutable VariableType value; + const Variable defValue; }; struct byColIdx {}; struct byColName {}; diff --git a/project2/variables.cpp b/project2/variables.cpp index 5514638..2e08b1b 100644 --- a/project2/variables.cpp +++ b/project2/variables.cpp @@ -135,7 +135,9 @@ class VariableImplDyn : public VariableImpl { cacheValid(false) { try { - defaultValue = Variable(e, "default"); + if (e) { + defaultValue = Variable(e, "default"); + } } catch (NoVariableDefinition) { // That's cool... no default @@ -352,6 +354,11 @@ class VariableConfig : public VariableImplDyn { const Glib::ustring name; }; +Variable::Variable(VariableType def) : + var(new VariableFixed(def)) +{ +} + Variable::Variable(const xmlpp::Element * e, const Glib::ustring & n, bool required, VariableType def) { xmlpp::Attribute * a = e->get_attribute(n); diff --git a/project2/variables.h b/project2/variables.h index ecb8268..71171b3 100644 --- a/project2/variables.h +++ b/project2/variables.h @@ -69,6 +69,7 @@ class Variable { typedef boost::intrusive_ptr VariableImplPtr; Variable(const xmlpp::Element *, const Glib::ustring & n, bool required = true, VariableType def = VariableType()); + Variable(VariableType def); static Variable makeFromCode(const Glib::ustring & s); static Variable makeParent(const Glib::ustring & name, bool attr, unsigned int depth); -- cgit v1.2.3