Class Poco::Data::Row
Author: Applied Informatics Software Engineering GmbH and Contributors

# Poco::Data

# class Row

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

## Description

Row class provides a data type for RecordSet iteration purposes. Dereferencing a RowIterator returns Row. Rows are sortable. The sortability is maintained at all times (i.e. there is always at least one column specified as a sorting criteria) . The default and minimal sorting criteria is the first field (position 0). The default sorting criteria can be replaced with any other field by calling replaceSortField() member function. Additional fields can be added to sorting criteria, in which case the field precedence corresponds to addition order (i.e. later added fields have lower sorting precedence). These features make Row suitable for use with standard sorted containers and algorithms. The main constraint is that all the rows from a set that is being sorted must have the same sorting criteria (i.e., the same set of fields must be in sorting criteria in the same order). Since rows don't know about each other, it is the programmer's responsibility to ensure this constraint is satisfied. Field names are a shared pointer to a vector of strings. For efficiency sake, a constructor taking a shared pointer to names vector argument is provided. The stream operator is provided for Row data type as a free-standing function.

## Member Summary

Member Functions: addSortField, append, fieldCount, formatNames, formatValues, get, getFormatter, getSortMap, names, namesToString, operator !=, operator <, operator ==, operator [], removeSortField, replaceSortField, reset, resetSort, separator, set, setFormatter, setSortMap, values, valuesToString

## Types

### NameVec

typedef RowFormatter::NameVec NameVec;

### NameVecPtr

typedef RowFormatter::NameVecPtr NameVecPtr;

### SortMap

typedef std::vector < SortTuple > SortMap;

The type for map holding fields used for sorting criteria. Fields are added sequentially and have precedence that corresponds to field adding sequence order (rather than field's position in the row). This requirement rules out use of std::map due to its sorted nature.

### SortMapPtr

typedef SharedPtr < SortMap > SortMapPtr;

### SortTuple

typedef Tuple < std::size_t, ComparisonType > SortTuple;

### ValueVec

typedef RowFormatter::ValueVec ValueVec;

## Enumerations

### ComparisonType

COMPARE_AS_EMPTY

COMPARE_AS_INTEGER

COMPARE_AS_FLOAT

COMPARE_AS_STRING

## Constructors

### Row

Row();

Creates the Row.

### Row

Row(
NameVecPtr pNames,
const RowFormatter::Ptr & pFormatter = 0
);

Creates the Row.

### Row

Row(
NameVecPtr pNames,
const SortMapPtr & pSortMap,
const RowFormatter::Ptr & pFormatter = 0
);

Creates the Row.

## Destructor

### ~Row

~Row();

Destroys the Row.

## Member Functions

### addSortField

void addSortField(
std::size_t pos
);

Adds the field used for sorting.

### addSortField

void addSortField(
const std::string & name
);

Adds the field used for sorting.

### append

template < typename T > void append(
const std::string & name,
const T & val
);

Appends the value to the row.

### fieldCount

std::size_t fieldCount() const;

Returns the number of fields in this row.

### formatNames

void formatNames() const;

Fomats the column names.

### formatValues

void formatValues() const;

Fomats the row values.

### get

Poco::Dynamic::Var & get(
std::size_t col
);

Returns the reference to data value at column location.

### getFormatter

const RowFormatter & getFormatter() const;

Returns the reference to the formatter.

### getSortMap

const SortMapPtr & getSortMap() const;

Returns the reference to the sorting fields.

### names

const NameVecPtr names() const;

Returns the shared pointer to names vector.

### namesToString

const std::string & namesToString() const;

Converts the column names to string.

### operator !=

bool operator != (
const Row & other
) const;

Inequality operator.

### operator <

bool operator < (
const Row & other
) const;

Less-than operator.

### operator ==

bool operator == (
const Row & other
) const;

Equality operator.

### operator []

Poco::Dynamic::Var & operator[] (
std::size_t col
);

Returns the reference to data value at column location.

### operator []

Poco::Dynamic::Var & operator[] (
const std::string & name
);

Returns the reference to data value at named column location.

### removeSortField

void removeSortField(
std::size_t pos
);

Removes the field used for sorting.

### removeSortField

void removeSortField(
const std::string & name
);

Removes the field used for sorting.

### replaceSortField

void replaceSortField(
std::size_t oldPos,
std::size_t newPos
);

Replaces the field used for sorting.

### replaceSortField

void replaceSortField(
const std::string & oldName,
const std::string & newName
);

Replaces the field used for sorting.

### reset

void reset();

Resets the row by clearing all field names and values.

### resetSort

void resetSort();

Resets the sorting criteria to field 0 only.

### separator

void separator(
const std::string & sep
);

Sets the separator.

### set

template < typename T > void set(
std::size_t pos,
const T & val
);

Assigns the value to the row.

### set

template < typename T > void set(
const std::string & name,
const T & val
);

Assigns the value to the row.

### setFormatter

void setFormatter(
const RowFormatter::Ptr & pFormatter = 0
);

Sets the formatter for this row and takes the shared ownership of it.

### setSortMap

void setSortMap(
const SortMapPtr & pSortMap = 0
);

Adds the sorting fields entry and takes the shared ownership of it.

### values

const ValueVec & values() const;

Returns the const reference to values vector.

### valuesToString

const std::string & valuesToString() const;

Converts the row values to string and returns the formated string.