1 #ifndef UTIL_NCBITABLE__HPP
2 #define UTIL_NCBITABLE__HPP
64 template<
class TValue,
class TRow,
class TColumn>
78 CNcbiTable(
unsigned int rows,
unsigned int cols);
92 unsigned int Rows()
const;
94 unsigned int Cols()
const;
99 void AddRow(
const TRow& row);
102 void AssociateRow(
const TRow& row,
unsigned int row_idx);
107 void Resize(
unsigned int rows,
111 void Resize(
unsigned int rows,
128 const TValue&
operator()(
const TRow& row,
const TColumn& col)
const
139 unsigned int ColumnIdx(
const TColumn& col)
const;
141 unsigned int RowIdx(
const TRow& row)
const;
144 const TColumn&
Column(
unsigned int idx)
const;
146 const TRow&
Row(
unsigned int idx)
const;
176 template<
class TValue,
class TRow,
class TColumn>
183 template<
class TValue,
class TRow,
class TColumn>
190 for (
unsigned int i = 0;
i <
m_Rows; ++
i) {
196 template<
class TValue,
class TRow,
class TColumn>
203 template<
class TValue,
class TRow,
class TColumn>
206 m_Rows =
table.Rows();
207 m_Cols =
table.Cols();
210 m_Table.reserve(m_Rows);
211 for (
unsigned int i = 0;
i < m_Rows; ++
i) {
214 m_Table.push_back(
r);
217 m_RowMap =
table.m_RowMap;
218 m_ColumnMap =
table.m_ColumnMap;
222 template<
class TValue,
class TRow,
class TColumn>
228 template<
class TValue,
class TRow,
class TColumn>
239 template<
class TValue,
class TRow,
class TColumn>
245 template<
class TValue,
class TRow,
class TColumn>
251 template<
class TValue,
class TRow,
class TColumn>
254 unsigned int cidx = m_Cols;
255 AssociateColumn(col, cidx);
258 r->push_back(TValue());
263 template<
class TValue,
class TRow,
class TColumn>
266 unsigned int ridx = m_Rows;
268 m_Table.push_back(
r);
270 AssociateRow(row, ridx);
274 template<
class TValue,
class TRow,
class TColumn>
276 unsigned int row_idx)
279 if (it == m_RowMap.end()) {
280 m_RowMap.insert(pair<TRow, unsigned int>(row, row_idx));
284 eRowAlreadyExists,
"Cannot assign row key (already assigned).");
288 template<
class TValue,
class TRow,
class TColumn>
290 unsigned int col_idx)
293 if (it == m_ColumnMap.end()) {
294 m_ColumnMap.insert(pair<TColumn, unsigned int>(col, col_idx));
298 eRowAlreadyExists,
"Cannot assign column key (already assigned).");
303 template<
class TValue,
class TRow,
class TColumn>
310 m_Table.resize(rows);
314 m_Table.resize(rows, 0);
325 if (
r->size() != cols) {
332 template<
class TValue,
class TRow,
class TColumn>
340 m_Table.resize(rows);
344 m_Table.resize(rows, 0);
355 if (
r->size() != cols) {
363 template<
class TValue,
class TRow,
class TColumn>
368 if (it == m_RowMap.end()) {
371 eRowNotFound,
"Row not found.");
373 unsigned int idx = it->second;
374 return *(m_Table[idx]);
377 template<
class TValue,
class TRow,
class TColumn>
381 return *(m_Table[row_idx]);
384 template<
class TValue,
class TRow,
class TColumn>
388 return *(m_Table[row_idx]);
392 template<
class TValue,
class TRow,
class TColumn>
396 unsigned int ridx = RowIdx(row);
397 unsigned int cidx = ColumnIdx(col);
399 return GetCell(ridx, cidx);
402 template<
class TValue,
class TRow,
class TColumn>
406 unsigned int ridx = RowIdx(row);
407 unsigned int cidx = ColumnIdx(col);
409 return GetCell(ridx, cidx);
413 template<
class TValue,
class TRow,
class TColumn>
418 if (it == m_ColumnMap.end()) {
421 eColumnNotFound,
"Column not found.");
426 template<
class TValue,
class TRow,
class TColumn>
431 if (it == m_RowMap.end()) {
434 eRowNotFound,
"Row not found.");
439 template<
class TValue,
class TRow,
class TColumn>
444 for(it=m_ColumnMap.begin(); it!=m_ColumnMap.end(); ++it) {
445 if ( (*it).second == idx )
452 template<
class TValue,
class TRow,
class TColumn>
457 for(it=m_RowMap.begin(); it!=m_RowMap.end(); ++it) {
458 if ( (*it).second == idx )
465 template<
class TValue,
class TRow,
class TColumn>
468 unsigned int col_idx)
const
474 template<
class TValue,
class TRow,
class TColumn>
477 unsigned int col_idx)
@ eRowNotFound
Row not found.
@ eColumnNotFound
Column not found.
@ eRowAlreadyExists
Row id has been assigned before.
NCBI_EXCEPTION_DEFAULT(CNcbiTable_Exception, CException)
Template class to create a table with custom row-column access.
map< TRow, unsigned int > TRowMap
const TColumn & Column(unsigned int idx) const
Get column name.
void AssociateColumn(const TColumn &col, unsigned int col_idx)
Set up column name.
TValue & operator()(const TRow &row, const TColumn &col)
Get table element.
void AddColumn(const TColumn &col)
Add column to the table, column recieves name "col".
unsigned int m_Rows
Number of rows.
void x_Copy(const CNcbiTable &table)
unsigned int ColumnIdx(const TColumn &col) const
Get column index.
const TValue & operator()(const TRow &row, const TColumn &col) const
Get table element.
unsigned int RowIdx(const TRow &row) const
Get row index.
void Resize(unsigned int rows, unsigned int cols)
Change table size.
TRowMap m_RowMap
Row name to index.
const TValueType & GetCell(unsigned int row_idx, unsigned int col_idx) const
Access table element by index.
const TRow & Row(unsigned int idx) const
Get row name.
const TRowType & GetRow(const TRow &row) const
Get table row.
unsigned int m_Cols
Number of columns.
map< TColumn, unsigned int > TColumnMap
void AddRow(const TRow &row)
Add row to the table, column recieves name "row".
unsigned int Rows() const
Number of rows.
const TValueType & GetElement(const TRow &row, const TColumn &col) const
Get table element.
unsigned int Cols() const
Number of column.
TColumnMap m_ColumnMap
Column name to index.
CNcbiTable & operator=(const CNcbiTable &table)
const TRowType & GetRowVector(unsigned int row_idx) const
Get table row by row index.
vector< TRowType * > TRowCollection
vector< TValue > TRowType
void AssociateRow(const TRow &row, unsigned int row_idx)
Set up row name.
container_type::const_iterator const_iterator
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
#define EXCEPTION_VIRTUAL_BASE
Do not use virtual base classes in exception declaration at all, because in this case derived class s...
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
Defines NCBI C++ exception handling.
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
NCBI_XUTIL_EXPORT
Parameter to control printing diagnostic message about conversion of static array data from a differe...