Library: Data
Package: DataCore
Header: Poco/Data/Row.h
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 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
typedef RowFormatter::NameVec NameVec;
typedef RowFormatter::NameVecPtr NameVecPtr;
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.
typedef SharedPtr < SortMap > SortMapPtr;
typedef Tuple < std::size_t, ComparisonType > SortTuple;
typedef RowFormatter::ValueVec ValueVec;
Row();
Creates the Row.
Row(
NameVecPtr pNames,
const RowFormatter::Ptr & pFormatter = 0
);
Creates the Row.
Row(
NameVecPtr pNames,
const SortMapPtr & pSortMap,
const RowFormatter::Ptr & pFormatter = 0
);
Creates the Row.
~Row();
Destroys the Row.
void addSortField(
std::size_t pos
);
Adds the field used for sorting.
void addSortField(
const std::string & name
);
Adds the field used for sorting.
template < typename T > void append(
const std::string & name,
const T & val
);
Appends the value to the row.
std::size_t fieldCount() const;
Returns the number of fields in this row.
void formatNames() const;
Fomats the column names.
void formatValues() const;
Fomats the row values.
Poco::Dynamic::Var & get(
std::size_t col
);
Returns the reference to data value at column location.
const RowFormatter & getFormatter() const;
Returns the reference to the formatter.
const SortMapPtr & getSortMap() const;
Returns the reference to the sorting fields.
const NameVecPtr names() const;
Returns the shared pointer to names vector.
const std::string & namesToString() const;
Converts the column names to string.
bool operator != (
const Row & other
) const;
Inequality operator.
bool operator < (
const Row & other
) const;
Less-than operator.
bool operator == (
const Row & other
) const;
Equality operator.
Poco::Dynamic::Var & operator[] (
std::size_t col
);
Returns the reference to data value at column location.
Poco::Dynamic::Var & operator[] (
const std::string & name
);
Returns the reference to data value at named column location.
void removeSortField(
std::size_t pos
);
Removes the field used for sorting.
void removeSortField(
const std::string & name
);
Removes the field used for sorting.
void replaceSortField(
std::size_t oldPos,
std::size_t newPos
);
Replaces the field used for sorting.
void replaceSortField(
const std::string & oldName,
const std::string & newName
);
Replaces the field used for sorting.
void reset();
Resets the row by clearing all field names and values.
void resetSort();
Resets the sorting criteria to field 0 only.
void separator(
const std::string & sep
);
Sets the separator.
template < typename T > void set(
std::size_t pos,
const T & val
);
Assigns the value to the row.
template < typename T > void set(
const std::string & name,
const T & val
);
Assigns the value to the row.
void setFormatter(
const RowFormatter::Ptr & pFormatter = 0
);
Sets the formatter for this row and takes the shared ownership of it.
void setSortMap(
const SortMapPtr & pSortMap = 0
);
Adds the sorting fields entry and takes the shared ownership of it.
const ValueVec & values() const;
Returns the const reference to values vector.
const std::string & valuesToString() const;
Converts the row values to string and returns the formated string.