summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-02-11 00:55:50 +0000
committerrandomdan <randomdan@localhost>2011-02-11 00:55:50 +0000
commitd03abba364c8b7c53557f6daaed35b21641845dd (patch)
tree5404c2e9944b0c5d84fe55e5955ac12d35264008
parentAdd an 'if' component that works with views and iterators (diff)
downloadproject2-d03abba364c8b7c53557f6daaed35b21641845dd.tar.bz2
project2-d03abba364c8b7c53557f6daaed35b21641845dd.tar.xz
project2-d03abba364c8b7c53557f6daaed35b21641845dd.zip
Less copying and more native storage in fileRows
-rw-r--r--project2/fileRows.cpp32
-rw-r--r--project2/fileRows.h7
2 files changed, 19 insertions, 20 deletions
diff --git a/project2/fileRows.cpp b/project2/fileRows.cpp
index 78a61a5..4a3c58b 100644
--- a/project2/fileRows.cpp
+++ b/project2/fileRows.cpp
@@ -20,7 +20,7 @@ FileRows::FileRows(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.push_back(elem->get_child_text()->get_content());
+ columns.push_back(boost::shared_ptr<Glib::ustring>(new Glib::ustring(elem->get_child_text()->get_content())));
}
}
}
@@ -49,7 +49,7 @@ FileRows::columnCount() const
const Glib::ustring &
FileRows::getColumnName(unsigned int col) const
{
- return columns[col];
+ return *columns[col];
}
void
@@ -68,11 +68,12 @@ FileRows::execute(const RowProcessor * rp) const
bool mkCols = columns.empty();
bool inQuotes = false;
bool prevWasQuote = false;
- Glib::ustring tok;
+ typedef boost::shared_ptr<Glib::ustring> StringPtr;
+ StringPtr tok(new Glib::ustring());
BOOST_FOREACH(gunichar c, line) {
if (c == quoteChar) {
if (prevWasQuote) {
- tok += c;
+ *tok += c;
prevWasQuote = false;
inQuotes = !inQuotes;
}
@@ -87,29 +88,29 @@ FileRows::execute(const RowProcessor * rp) const
addColumn(tok);
}
else {
- values.push_back(ValPtr(new Glib::ustring(tok)));
+ values.push_back(tok);
curCol++;
}
- tok.clear();
+ tok = StringPtr(new Glib::ustring());
}
else {
prevWasQuote = false;
- tok += c;
+ *tok += c;
}
}
- if (tok.length()) {
+ if (tok->length()) {
if (mkCols) {
addColumn(tok);
}
else {
- values.push_back(ValPtr(new Glib::ustring(tok)));
+ values.push_back(tok);
curCol++;
}
}
if (!mkCols) {
if (keepBlankRows || !values.empty()) {
while (values.size() < columns.size()) {
- values.push_back(ValPtr(new Glib::ustring()));
+ values.push_back(VariableType());
curCol++;
}
rp->rowReady();
@@ -146,7 +147,7 @@ FileRows::getCurrentValue(const Glib::ustring & id) const
{
Values::const_iterator v = values.begin();
for (Columns::const_iterator i = columns.begin(); i != columns.end(); i++, v++) {
- if (*i == id) {
+ if (**i == id) {
return *v;
}
}
@@ -154,13 +155,12 @@ FileRows::getCurrentValue(const Glib::ustring & id) const
}
void
-FileRows::addColumn(const Glib::ustring & rawtok) const
+FileRows::addColumn(boost::shared_ptr<Glib::ustring> tok) const
{
- columns.push_back(rawtok);
- Glib::ustring & tok(columns.back());
- for (Glib::ustring::iterator i = tok.begin(); i != tok.end(); ) {
+ columns.push_back(tok);
+ for (Glib::ustring::iterator i = tok->begin(); i != tok->end(); ) {
if (!isalnum(*i)) {
- tok.erase(i);
+ tok->erase(i);
}
else {
i++;
diff --git a/project2/fileRows.h b/project2/fileRows.h
index 1edff0b..1a4b7ed 100644
--- a/project2/fileRows.h
+++ b/project2/fileRows.h
@@ -31,9 +31,8 @@ class FileRows : public RowSet {
protected:
virtual FileStarChannel doOpen() const;
- void addColumn(const Glib::ustring & rawtok) const;
- typedef boost::shared_ptr<Glib::ustring> ValPtr;
- typedef std::vector<ValPtr> Values;
+ void addColumn(boost::shared_ptr<Glib::ustring> rawtok) const;
+ typedef std::vector<VariableType> Values;
mutable Values values;
private:
@@ -43,7 +42,7 @@ class FileRows : public RowSet {
bool countBlankRows;
std::string newline;
std::string encoding;
- typedef std::vector<Glib::ustring> Columns;
+ typedef std::vector<boost::shared_ptr<Glib::ustring> > Columns;
mutable Columns columns;
};