RowFormatter - progressive and bulk formatting modes

This commit is contained in:
Aleksandar Fabijanic
2009-11-01 15:58:32 +00:00
parent 65ad81c363
commit 05131182b8
9 changed files with 182 additions and 37 deletions

View File

@@ -329,26 +329,40 @@ std::ostream& RecordSet::copyNames(std::ostream& os) const
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::string val;
for (; itBegin != itEnd; ++itBegin)
{
val = itBegin->valuesToString();
if (!val.empty()) os << val;
}
RowIterator it = *_pBegin + offset;
RowIterator end = (RowIterator::POSITION_END != length) ? it + length : *_pEnd;
std::copy(it, end, std::ostream_iterator<Row>(os));
return os;
}
void RecordSet::formatValues(std::size_t offset, std::size_t length) const
{
RowIterator it = *_pBegin + offset;
RowIterator end = (RowIterator::POSITION_END != length) ? it + length : *_pEnd;
std::string val;
for (; it != end; ++it) it->formatValues();
}
std::ostream& RecordSet::copy(std::ostream& os, std::size_t offset, std::size_t length) const
{
RowFormatter& rf = const_cast<RowFormatter&>((*_pBegin)->getFormatter());
rf.setTotalRowCount(getTotalRowCount());
os << rf.prefix();
copyNames(os);
copyValues(os, offset, length);
os << rf.postfix();
if (RowFormatter::FORMAT_PROGRESSIVE == rf.getMode())
{
os << rf.prefix();
copyNames(os);
copyValues(os, offset, length);
os << rf.postfix();
}
else
{
formatNames();
formatValues(offset, length);
os << rf.toString();
}
return os;
}

View File

@@ -398,4 +398,13 @@ const std::string& Row::namesToString() const
}
void Row::formatNames() const
{
if (!_pNames)
throw NullPointerException();
return _pFormatter->formatNames(names());
}
} } // namespace Poco::Data

View File

@@ -43,9 +43,12 @@ namespace Poco {
namespace Data {
RowFormatter::RowFormatter(const std::string& prefix, const std::string& postfix):
RowFormatter::RowFormatter(const std::string& prefix,
const std::string& postfix,
Mode mode):
_prefix(prefix),
_postfix(postfix),
_mode(mode),
_totalRowCount(0)
{
}
@@ -56,6 +59,38 @@ RowFormatter::~RowFormatter()
}
std::string& RowFormatter::formatNames(const NameVecPtr pNames, std::string& formattedNames)
{
formattedNames.clear();
return formattedNames;
}
void RowFormatter::formatNames(const NameVecPtr pNames)
{
return;
}
std::string& RowFormatter::formatValues(const ValueVec& vals, std::string& formattedValues)
{
formattedValues.clear();
return formattedValues;
}
void RowFormatter::formatValues(const ValueVec& vals)
{
return;
}
const std::string& RowFormatter::toString()
{
throw NotImplementedException("RowFormatter::toString()");
}
void RowFormatter::reset()
{
_prefix = "";

View File

@@ -79,7 +79,7 @@ void SimpleRowFormatter::swap(SimpleRowFormatter& other)
}
std::string& SimpleRowFormatter::formatNames(const NameVecPtr pNames, std::string& formattedNames) const
std::string& SimpleRowFormatter::formatNames(const NameVecPtr pNames, std::string& formattedNames)
{
_rowCount = 0;
@@ -98,7 +98,7 @@ std::string& SimpleRowFormatter::formatNames(const NameVecPtr pNames, std::strin
}
std::string& SimpleRowFormatter::formatValues(const ValueVec& vals, std::string& formattedValues) const
std::string& SimpleRowFormatter::formatValues(const ValueVec& vals, std::string& formattedValues)
{
std::ostringstream str;