add column spacing to SimpleRowFormatter, can be specified in ctor

This commit is contained in:
Guenter Obiltschnig 2014-09-23 22:32:00 +02:00
Родитель 85fd968a1e
Коммит d663a6b570
1 изменённых файлов: 11 добавлений и 6 удалений

Просмотреть файл

@ -23,15 +23,17 @@ namespace Poco {
namespace Data { namespace Data {
SimpleRowFormatter::SimpleRowFormatter(std::streamsize columnWidth): SimpleRowFormatter::SimpleRowFormatter(std::streamsize columnWidth, std::streamsize spacing):
_colWidth(columnWidth), _rowCount(0) _colWidth(columnWidth), _spacing(spacing), _rowCount(0)
{ {
} }
SimpleRowFormatter::SimpleRowFormatter(const SimpleRowFormatter& other): SimpleRowFormatter::SimpleRowFormatter(const SimpleRowFormatter& other):
RowFormatter(other.prefix(), other.postfix()), RowFormatter(other.prefix(), other.postfix()),
_colWidth(other._colWidth) _colWidth(other._colWidth),
_spacing(other._spacing),
_rowCount(0)
{ {
} }
@ -56,6 +58,7 @@ void SimpleRowFormatter::swap(SimpleRowFormatter& other)
setPrefix(other.prefix()); setPrefix(other.prefix());
setPostfix(other.postfix()); setPostfix(other.postfix());
swap(_colWidth, other._colWidth); swap(_colWidth, other._colWidth);
swap(_spacing, other._spacing);
} }
@ -64,12 +67,13 @@ std::string& SimpleRowFormatter::formatNames(const NameVecPtr pNames, std::strin
_rowCount = 0; _rowCount = 0;
std::ostringstream str; std::ostringstream str;
std::string line(std::string::size_type(pNames->size() * _colWidth), '-'); std::string line(std::string::size_type(pNames->size()*_colWidth + (pNames->size() - 1)*_spacing), '-');
std::string space(_spacing, ' ');
NameVec::const_iterator it = pNames->begin(); NameVec::const_iterator it = pNames->begin();
NameVec::const_iterator end = pNames->end(); NameVec::const_iterator end = pNames->end();
for (; it != end; ++it) for (; it != end; ++it)
{ {
if (it != pNames->begin()) str << space;
str << std::left << std::setw(_colWidth) << *it; str << std::left << std::setw(_colWidth) << *it;
} }
str << std::endl << line << std::endl; str << std::endl << line << std::endl;
@ -81,11 +85,12 @@ std::string& SimpleRowFormatter::formatNames(const NameVecPtr pNames, std::strin
std::string& SimpleRowFormatter::formatValues(const ValueVec& vals, std::string& formattedValues) std::string& SimpleRowFormatter::formatValues(const ValueVec& vals, std::string& formattedValues)
{ {
std::ostringstream str; std::ostringstream str;
std::string space(_spacing, ' ');
ValueVec::const_iterator it = vals.begin(); ValueVec::const_iterator it = vals.begin();
ValueVec::const_iterator end = vals.end(); ValueVec::const_iterator end = vals.end();
for (; it != end; ++it) for (; it != end; ++it)
{ {
if (it != vals.begin()) str << space;
if (it->isNumeric()) if (it->isNumeric())
{ {
str << std::right str << std::right