# Poco::Data

# class RowFormatter

Library: Data
Package: DataCore
Header: Poco/Data/RowFormatter.h

## Description

Row formatter is an abstract class providing definition for row formatting functionality. For custom formatting strategies, inherit from this class and override formatNames() and formatValues() member functions.

Row formatter can be either passed to the RecordSet at construction time, like in the following example:

RecordSet rs(session. "SELECT * FROM Table", new MyRowFormater);

or it can be supplied to the statement as in the following example:

MyRowFormatter rf session << "SELECT * FROM Table", format(rf);

If no formatter is externally supplied to the statement, the SimpleRowFormatter is used. Statement always has the ownership of the row formatter and shares it with rows through RecordSet.

To accomodate for various formatting needs, a formatter can operate in two modes:

- progressive: formatted individual row strings are gemerated and returned from each call to formatValues; std::string& formatNames(const NameVecPtr, std::string&) and std::string& formatValues(const ValueVec&, std::string&) member calls should be used in this case; this is the default mode

- bulk: formatted resulting string is accumulated internally and obtained at the end of iteration via toString() member function; void formatNames(const NameVecPtr) and void formatValues(const ValueVec&) member calls should be used in this case

When formatter is used in conjunction with Row/RecordSet, the formatting members corresponding to the formater mode are expected to be implemented. If a call is propagated to this parent class, the functions do nothing or silently return empty string respectively.

## Inheritance

Known Derived Classes: SimpleRowFormatter

## Member Summary

Member Functions: formatNames, formatValues, getMode, getTotalRowCount, postfix, prefix, reset, rowCount, setMode, setPostfix, setPrefix, setTotalRowCount, toString

## Types

### NameVec

typedef std::vector < std::string > NameVec;

### NameVecPtr

typedef SharedPtr < std::vector < std::string > > NameVecPtr;

### Ptr

typedef SharedPtr < RowFormatter > Ptr;

### ValueVec

typedef std::vector < Poco::Dynamic::Var > ValueVec;

## Enumerations

### Mode

FORMAT_PROGRESSIVE

FORMAT_BULK

## Constructors

### RowFormatter

RowFormatter(
const std::string & prefix = "",
const std::string & postfix = "",
Mode mode = FORMAT_PROGRESSIVE
);

Creates the RowFormatter and sets the prefix and postfix to specified values.

## Destructor

### ~RowFormatter

virtual ~RowFormatter();

Destroys the RowFormatter.

## Member Functions

### formatNames

virtual std::string & formatNames(
const NameVecPtr pNames,
std::string & formattedNames
);

Should be implemented to format the row fields names and return the formatted string. The default implementation clears the names string and returns it.

### formatNames

virtual void formatNames(
const NameVecPtr pNames
);

Should be implemented to format the row fields names. The default implementation does nothing.

### formatValues

virtual std::string & formatValues(
const ValueVec & vals,
std::string & formattedValues
);

Should be implemented to format the row fields values and return the formatted string. The default implementation clears the values string and returns it.

### formatValues

virtual void formatValues(
const ValueVec & vals
);

Should be implemented to format the row fields values. The default implementation does nothing.

### getMode

Mode getMode() const;

Returns the formater mode.

### getTotalRowCount

int getTotalRowCount() const;

Returns zero. Must be implemented by inheriting classes. Typically, total row count shall be set up front through setTotalRowCount() call.

### postfix

virtual const std::string & postfix() const;

Returns postfix string;

### prefix

virtual const std::string & prefix() const;

Returns prefix string;

### reset

void reset();

Resets the formatter by setting prefix and postfix to empty strings and row count to INVALID_ROW_COUNT.

### rowCount

virtual int rowCount() const;

Returns INVALID_ROW_COUNT. Must be implemented by inheriting classes which maintain count of processed rows.

### setMode

void setMode(
Mode mode
);

Sets the fromatter mode.

### setTotalRowCount

void setTotalRowCount(
int count
);

Sets total row count.

### toString

virtual const std::string & toString();

Throws NotImplementedException. Formatters operating in bulk mode should implement this member function to return valid pointer to the formatted result.

### setPostfix

void setPostfix(
const std::string & postfix
);

Sets the postfix for the formatter

### setPrefix

void setPrefix(
const std::string & prefix
);

Sets the prefix for the formatter.

## Variables

### INVALID_ROW_COUNT

static const int INVALID_ROW_COUNT = - 1;