summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-02-18 20:50:35 +0000
committerrandomdan <randomdan@localhost>2011-02-18 20:50:35 +0000
commit3e8b88da1e18d504ec0388166fb374483a07e735 (patch)
tree4c7d81249b37aa74c81c3f9b9b42fdc408a6a3c5
parentDon't convert everything to a string to print it, use boost apply_visitor and... (diff)
downloadproject2-3e8b88da1e18d504ec0388166fb374483a07e735.tar.bz2
project2-3e8b88da1e18d504ec0388166fb374483a07e735.tar.xz
project2-3e8b88da1e18d504ec0388166fb374483a07e735.zip
Fix behaviour of stream rows with blank rows
Add support for default values of blank columns in stream rows
-rw-r--r--project2/streamRows.cpp38
-rw-r--r--project2/streamRows.h2
-rw-r--r--project2/variables.cpp9
-rw-r--r--project2/variables.h1
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<const xmlpp::Element *>(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<byColIdx>().end()) {
- *curCol++ = VariableType();
+ if (keepBlankRows || curCol != columns.get<byColIdx>().begin()) {
+ while (curCol != columns.get<byColIdx>().end()) {
+ *curCol++ = curCol->defValue;
+ }
+ rp->rowReady();
+ rowNum += 1;
+ }
+ else if (countBlankRows) {
+ rowNum += 1;
}
- rp->rowReady();
- rowNum += 1;
- curCol = columns.get<byColIdx>().begin();
}
else {
+ if (!tok->empty()) {
+ addColumn(*tok);
+ }
mkCols = false;
}
+ curCol = columns.get<byColIdx>().begin();
}
tok = StringPtr(new Glib::ustring());
}
@@ -180,13 +196,17 @@ StreamRows::end(const RowProcessor * rp) const
}
}
}
- if (curCol != columns.get<byColIdx>().begin()) {
+ if (keepBlankRows || curCol != columns.get<byColIdx>().begin()) {
while (curCol != columns.get<byColIdx>().end()) {
- *curCol++ = VariableType();
+ *curCol++ = curCol->defValue;
}
rp->rowReady();
rowNum += 1;
}
+ else if (countBlankRows) {
+ rowNum += 1;
+ }
+ curCol = columns.get<byColIdx>().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<VariableImpl> 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);