From 65ad81c36353117b86b0e408d9f6ab4888277c60 Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Thu, 29 Oct 2009 17:45:02 +0000 Subject: [PATCH] - made prefix() and postfix() virtual - avoid stream operator calls when copying empty strings --- Data/include/Poco/Data/RecordSet.h | 7 ------- Data/include/Poco/Data/RowFormatter.h | 6 +++--- Data/src/RecordSet.cpp | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Data/include/Poco/Data/RecordSet.h b/Data/include/Poco/Data/RecordSet.h index 1266af406..410755be3 100644 --- a/Data/include/Poco/Data/RecordSet.h +++ b/Data/include/Poco/Data/RecordSet.h @@ -616,13 +616,6 @@ inline RecordSet::Iterator RecordSet::end() } -inline std::ostream& RecordSet::copyNames(std::ostream& os) const -{ - os << (*_pBegin)->namesToString(); - return os; -} - - inline const RowFilter* RecordSet::getFilter() const { return _pFilter; diff --git a/Data/include/Poco/Data/RowFormatter.h b/Data/include/Poco/Data/RowFormatter.h index 58327d44c..cd0708ee7 100644 --- a/Data/include/Poco/Data/RowFormatter.h +++ b/Data/include/Poco/Data/RowFormatter.h @@ -103,10 +103,10 @@ public: void setTotalRowCount(int count); /// Sets total row count. - const std::string& prefix() const; + virtual const std::string& prefix() const; /// Returns prefix string; - const std::string& postfix() const; + virtual const std::string& postfix() const; /// Returns postfix string; void reset(); @@ -116,7 +116,7 @@ public: protected: void setPrefix(const std::string& prefix) const; - /// Sets the p[refix for the formatter. + /// Sets the prefix for the formatter. void setPostfix(const std::string& postfix) const; /// Sets the postfix for the formatter diff --git a/Data/src/RecordSet.cpp b/Data/src/RecordSet.cpp index 6a75c57d3..a1f69e744 100644 --- a/Data/src/RecordSet.cpp +++ b/Data/src/RecordSet.cpp @@ -319,11 +319,24 @@ void RecordSet::setRowFormatter(RowFormatter* pRowFormatter) } +std::ostream& RecordSet::copyNames(std::ostream& os) const +{ + std::string names = (*_pBegin)->namesToString(); + if (!names.empty()) os << names; + return os; +} + + std::ostream& RecordSet::copyValues(std::ostream& os, std::size_t offset, std::size_t length) const { RowIterator itBegin = *_pBegin + offset; RowIterator itEnd = (RowIterator::POSITION_END != length) ? itBegin + length : *_pEnd; - std::copy(itBegin, itEnd, std::ostream_iterator(os)); + std::string val; + for (; itBegin != itEnd; ++itBegin) + { + val = itBegin->valuesToString(); + if (!val.empty()) os << val; + } return os; }