![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
Holds a set of columns, a set of rows, and rows times columns cells. More...
#include <DS_Table.h>
Classes | |
| struct | Cell |
| Holds the actual data in the table. More... | |
| struct | ColumnDescriptor |
| struct | FilterQuery |
| struct | Row |
| Stores the list of cells for this row, and a special flag used for internal sorting. More... | |
| struct | SortQuery |
Public Types | |
| enum | ColumnType { NUMERIC, STRING, BINARY, POINTER } |
| enum | FilterQueryType { QF_EQUAL, QF_NOT_EQUAL, QF_GREATER_THAN, QF_GREATER_THAN_EQ, QF_LESS_THAN, QF_LESS_THAN_EQ, QF_IS_EMPTY, QF_NOT_EMPTY } |
| enum | SortQueryType { QS_INCREASING_ORDER, QS_DECREASING_ORDER } |
| Increasing or decreasing sort order. More... | |
Public Member Functions | |
| unsigned | AddColumn (const char columnName[64], ColumnType columnType) |
| Adds a column to the table. | |
| Table::Row * | AddRow (unsigned rowId) |
| Adds a row to the table. | |
| Table::Row * | AddRow (unsigned rowId, DataStructures::List< Cell > &initialCellValues) |
| Table::Row * | AddRow (unsigned rowId, DataStructures::List< Cell * > &initialCellValues, bool copyCells=false) |
| void | Clear (void) |
| Frees all memory in the table. | |
| unsigned | ColumnIndex (char columnName[64]) const |
| Gets the index of a column by name. | |
| unsigned | ColumnIndex (const char *columnName) const |
| char * | ColumnName (unsigned index) const |
| Gives the string name of the column at a certain index. | |
| unsigned | GetAvailableRowId (void) const |
| Get the first free row id. This could be made more efficient. | |
| void | GetCellValueByIndex (unsigned rowIndex, unsigned columnIndex, int *output) |
| Note this is much less efficient to call than GetRow, then working with the cells directly. Numeric, string, binary. | |
| void | GetCellValueByIndex (unsigned rowIndex, unsigned columnIndex, char *output) |
| void | GetCellValueByIndex (unsigned rowIndex, unsigned columnIndex, char *output, int *outputLength) |
| unsigned | GetColumnCount (void) const |
| const DataStructures::List < ColumnDescriptor > & | GetColumns (void) const |
| Direct access to make things easier. | |
| ColumnType | GetColumnType (unsigned index) const |
| Returns the type of a column, referenced by index. | |
| DataStructures::Page< unsigned, Row *, 16 > * | GetListHead (void) |
| Get the head of a linked list containing all the row data. | |
| Row * | GetRowByID (unsigned rowId) const |
| Gets a row. More efficient to do this and access Row::cells than to repeatedly call GetCell. You can also update cells in rows from this function. | |
| Row * | GetRowByIndex (unsigned rowIndex, unsigned *key) const |
| Gets a row at a specific index. rowIndex should be less than GetRowCount() | |
| unsigned | GetRowCount (void) const |
| const DataStructures::BPlusTree < unsigned, Row *, 16 > & | GetRows (void) const |
| Direct access to make things easier. | |
| Table & | operator= (const Table &input) |
| void | PrintColumnHeaders (char *out, int outLength, char columnDelineator) const |
| Prints out the names of all the columns. | |
| void | PrintRow (char *out, int outLength, char columnDelineator, bool printDelineatorForBinary, Table::Row *inputRow) const |
| Writes a text representation of the row to out. | |
| void | QueryTable (unsigned *columnIndicesSubset, unsigned numColumnSubset, FilterQuery *inclusionFilters, unsigned numInclusionFilters, unsigned *rowIds, unsigned numRowIDs, Table *result) |
| Queries the table, optionally returning only a subset of columns and rows. | |
| void | RemoveColumn (unsigned columnIndex) |
| Removes a column by index. | |
| bool | RemoveRow (unsigned rowId) |
| Removes a row specified by rowId. | |
| void | RemoveRows (Table *tableContainingRowIDs) |
| Removes all the rows with IDs that the specified table also has. | |
| void | SortTable (Table::SortQuery *sortQueries, unsigned numSortQueries, Table::Row **out) |
| Sorts the table by rows. | |
| Table () | |
| bool | UpdateCell (unsigned rowId, unsigned columnIndex, int value) |
| Updates a particular cell in the table. | |
| bool | UpdateCell (unsigned rowId, unsigned columnIndex, int byteLength, char *data) |
| bool | UpdateCell (unsigned rowId, unsigned columnIndex, char *str) |
| bool | UpdateCellByIndex (unsigned rowIndex, unsigned columnIndex, char *str) |
| bool | UpdateCellByIndex (unsigned rowIndex, unsigned columnIndex, int value) |
| bool | UpdateCellByIndex (unsigned rowIndex, unsigned columnIndex, int byteLength, char *data) |
| ~Table () | |
Protected Member Functions | |
| Table::Row * | AddRowColumns (unsigned rowId, Row *row, DataStructures::List< unsigned > columnIndices) |
| void | DeleteRow (Row *row) |
| void | QueryRow (DataStructures::List< unsigned > &inclusionFilterColumnIndices, DataStructures::List< unsigned > &columnIndicesToReturn, unsigned key, Table::Row *row, FilterQuery *inclusionFilters, Table *result) |
Protected Attributes | |
| DataStructures::List < ColumnDescriptor > | columns |
| DataStructures::BPlusTree < unsigned, Row *, 16 > | rows |
The table data structure is useful if you want to store a set of structures and perform queries on those structures.
This is a relatively simple and fast implementation of the types of tables commonly used in databases.
See TableSerializer to serialize data members of the table.
See LightweightDatabaseClient and LightweightDatabaseServer to transmit the table over the network.
Definition at line 33 of file DS_Table.h.
Definition at line 37 of file DS_Table.h.
| QF_EQUAL | |
| QF_NOT_EQUAL | |
| QF_GREATER_THAN | |
| QF_GREATER_THAN_EQ | |
| QF_LESS_THAN | |
| QF_LESS_THAN_EQ | |
| QF_IS_EMPTY | |
| QF_NOT_EMPTY |
Definition at line 132 of file DS_Table.h.
Definition at line 160 of file DS_Table.h.
| DataStructures::Table::Table | ( | ) |
| DataStructures::Table::~Table | ( | ) |
| unsigned DataStructures::Table::AddColumn | ( | const char | columnName[64], |
| ColumnType | columnType | ||
| ) |
| [in] | columnName | The name of the column |
| [in] | columnType | What type of data this column will hold |
| Table::Row* DataStructures::Table::AddRow | ( | unsigned | rowId | ) |
New rows are added with empty values for all cells. However, if you specify initialCelLValues you can specify initial values It's up to you to ensure that the values in the specific cells match the type of data used by that row rowId can be considered the primary key for the row. It is much faster to lookup a row by its rowId than by searching keys. rowId must be unique Rows are stored in sorted order in the table, using rowId as the sort key
| [in] | rowId | The UNIQUE primary key for the row. This can never be changed. |
| [in] | initialCellValues | Initial values to give the row (optional) |
| Table::Row* DataStructures::Table::AddRow | ( | unsigned | rowId, |
| DataStructures::List< Cell > & | initialCellValues | ||
| ) |
| Table::Row* DataStructures::Table::AddRow | ( | unsigned | rowId, |
| DataStructures::List< Cell * > & | initialCellValues, | ||
| bool | copyCells = false |
||
| ) |
| Table::Row* DataStructures::Table::AddRowColumns | ( | unsigned | rowId, |
| Row * | row, | ||
| DataStructures::List< unsigned > | columnIndices | ||
| ) | [protected] |
| void DataStructures::Table::Clear | ( | void | ) |
| unsigned DataStructures::Table::ColumnIndex | ( | const char * | columnName | ) | const |
| unsigned DataStructures::Table::ColumnIndex | ( | char | columnName[64] | ) | const |
Column indices are stored in the order they are added.
| [in] | columnName | The name of the column |
| char* DataStructures::Table::ColumnName | ( | unsigned | index | ) | const |
| [in] | index | The index of the column |
| void DataStructures::Table::DeleteRow | ( | Row * | row | ) | [protected] |
| unsigned DataStructures::Table::GetAvailableRowId | ( | void | ) | const |
| void DataStructures::Table::GetCellValueByIndex | ( | unsigned | rowIndex, |
| unsigned | columnIndex, | ||
| int * | output | ||
| ) |
| void DataStructures::Table::GetCellValueByIndex | ( | unsigned | rowIndex, |
| unsigned | columnIndex, | ||
| char * | output | ||
| ) |
| void DataStructures::Table::GetCellValueByIndex | ( | unsigned | rowIndex, |
| unsigned | columnIndex, | ||
| char * | output, | ||
| int * | outputLength | ||
| ) |
| unsigned DataStructures::Table::GetColumnCount | ( | void | ) | const |
Returns the number of columns
| const DataStructures::List<ColumnDescriptor>& DataStructures::Table::GetColumns | ( | void | ) | const |
| ColumnType DataStructures::Table::GetColumnType | ( | unsigned | index | ) | const |
| [in] | index | The index of the column |
| DataStructures::Page<unsigned, Row*, 16 >* DataStructures::Table::GetListHead | ( | void | ) |
| Row* DataStructures::Table::GetRowByID | ( | unsigned | rowId | ) | const |
| [in] | rowId | The ID of the row |
| Row* DataStructures::Table::GetRowByIndex | ( | unsigned | rowIndex, |
| unsigned * | key | ||
| ) | const |
| [in] | rowIndex | The index of the row |
| [out] | key | The ID of the row returned |
| unsigned DataStructures::Table::GetRowCount | ( | void | ) | const |
Returns the number of rows
| const DataStructures::BPlusTree<unsigned, Row*, 16 >& DataStructures::Table::GetRows | ( | void | ) | const |
| void DataStructures::Table::PrintColumnHeaders | ( | char * | out, |
| int | outLength, | ||
| char | columnDelineator | ||
| ) | const |
| [out] | out | A pointer to an array of bytes which will hold the output. |
| [in] | outLength | The size of the out array |
| [in] | columnDelineator | What character to print to delineate columns |
| void DataStructures::Table::PrintRow | ( | char * | out, |
| int | outLength, | ||
| char | columnDelineator, | ||
| bool | printDelineatorForBinary, | ||
| Table::Row * | inputRow | ||
| ) | const |
| [out] | out | A pointer to an array of bytes which will hold the output. |
| [in] | outLength | The size of the out array |
| [in] | columnDelineator | What character to print to delineate columns |
| [in] | printDelineatorForBinary | Binary output is not printed. True to still print the delineator. |
| [in] | inputRow | The row to print |
| void DataStructures::Table::QueryRow | ( | DataStructures::List< unsigned > & | inclusionFilterColumnIndices, |
| DataStructures::List< unsigned > & | columnIndicesToReturn, | ||
| unsigned | key, | ||
| Table::Row * | row, | ||
| FilterQuery * | inclusionFilters, | ||
| Table * | result | ||
| ) | [protected] |
| void DataStructures::Table::QueryTable | ( | unsigned * | columnIndicesSubset, |
| unsigned | numColumnSubset, | ||
| FilterQuery * | inclusionFilters, | ||
| unsigned | numInclusionFilters, | ||
| unsigned * | rowIds, | ||
| unsigned | numRowIDs, | ||
| Table * | result | ||
| ) |
| [in] | columnSubset | An array of column indices. Only columns in this array are returned. Pass 0 for all columns |
| [in] | numColumnSubset | The number of elements in columnSubset |
| [in] | inclusionFilters | An array of FilterQuery. All filters must pass for the row to be returned. |
| [in] | numInclusionFilters | The number of elements in inclusionFilters |
| [in] | rowIds | An arrow of row IDs. Only these rows with these IDs are returned. Pass 0 for all rows. |
| [in] | numRowIDs | The number of elements in rowIds |
| [out] | result | The result of the query. If no rows are returned, the table will only have columns. |
| void DataStructures::Table::RemoveColumn | ( | unsigned | columnIndex | ) |
| [in] | columnIndex | The index of the column to remove |
| bool DataStructures::Table::RemoveRow | ( | unsigned | rowId | ) |
| [in] | rowId | The ID of the row |
| void DataStructures::Table::RemoveRows | ( | Table * | tableContainingRowIDs | ) |
| [in] | tableContainingRowIDs | The IDs of the rows |
| void DataStructures::Table::SortTable | ( | Table::SortQuery * | sortQueries, |
| unsigned | numSortQueries, | ||
| Table::Row ** | out | ||
| ) |
You can sort the table in ascending or descending order on one or more columns Columns have precedence in the order they appear in the sortQueries array If a row cell on column n has the same value as a a different row on column n, then the row will be compared on column n+1
| [in] | sortQueries | A list of SortQuery structures, defining the sorts to perform on the table |
| [in] | numColumnSubset | The number of elements in numSortQueries |
| [out] | out | The address of an array of Rows, which will receive the sorted output. The array must be long enough to contain all returned rows, up to GetRowCount() |
| bool DataStructures::Table::UpdateCell | ( | unsigned | rowId, |
| unsigned | columnIndex, | ||
| char * | str | ||
| ) |
| bool DataStructures::Table::UpdateCell | ( | unsigned | rowId, |
| unsigned | columnIndex, | ||
| int | value | ||
| ) |
| [in] | rowId | The ID of the row |
| [in] | columnIndex | The column of the cell |
| [in] | value | The data to set |
| bool DataStructures::Table::UpdateCell | ( | unsigned | rowId, |
| unsigned | columnIndex, | ||
| int | byteLength, | ||
| char * | data | ||
| ) |
| bool DataStructures::Table::UpdateCellByIndex | ( | unsigned | rowIndex, |
| unsigned | columnIndex, | ||
| char * | str | ||
| ) |
| bool DataStructures::Table::UpdateCellByIndex | ( | unsigned | rowIndex, |
| unsigned | columnIndex, | ||
| int | value | ||
| ) |
| bool DataStructures::Table::UpdateCellByIndex | ( | unsigned | rowIndex, |
| unsigned | columnIndex, | ||
| int | byteLength, | ||
| char * | data | ||
| ) |
Definition at line 335 of file DS_Table.h.
DataStructures::BPlusTree<unsigned, Row*, 16 > DataStructures::Table::rows [protected] |
Definition at line 332 of file DS_Table.h.
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.