Nebula
|
#include <attributetable.h>
A table of attributes with a compact memory footprint and fast random access.
Table columns are defined by attribute ids which associate a name, a fourcc code, a datatype and an access mode (ReadWrite, ReadOnly) to the table. Attribute values are stored in one big chunk of memory without additional overhead. Table cells can have the NULL status, which means the cell contains no value.
The table's value buffer consists of 16-byte aligned rows, each row consists of a bitfield with 2 bits per row (one bit is set if a column/row value is valid, the other is used as modified-marker).
Rows are allocated contigously in memory, which means padding might be inserted "between columns/values" to fulfill memory alignment requirements
The AttributeTable object keeps track of all changes (added columns, added rows, modified rows, modified values).
Inherits Core::RefCounted.
Inherited by Db::ValueTable.
Classes | |
struct | ColumnInfo |
Public Member Functions | |
AttributeTable () | |
constructor | |
AttributeTable (std::initializer_list< Attr::AttrId > columns, bool recordColumns=false) | |
construct with initializer list | |
virtual | ~AttributeTable () |
destructor | |
void | SetModifiedTracking (bool b) |
enable/disable modified tracking (default is on) | |
bool | GetModifiedTracking () const |
get modified tracking flag | |
bool | IsModified () const |
return true if the object has been modified since the last ResetModifiedState() | |
void | ResetModifiedState () |
reset all the modified bits in the table | |
void | Clear () |
clear the table object | |
void | PrintDebug () |
print the contents of the table for debugging reasons | |
void | BeginAddColumns (bool recordNewColumns=true) |
optional: call before adding columns, speeds up adding many columns at once | |
void | AddColumn (const AttrId &id, bool recordNewColumn=true) |
add a column | |
void | EndAddColumns () |
optional: call after adding columns, speeds up adding many columns at once | |
bool | HasColumn (const AttrId &id) const |
return true if a column exists | |
IndexT | GetColumnIndex (const AttrId &id) const |
return index of column by id | |
SizeT | GetNumColumns () const |
get number of columns | |
const AttrId & | GetColumnId (IndexT colIndex) const |
get column definition at index | |
const Util::String & | GetColumnName (IndexT colIndex) const |
get a column's name | |
const Util::FourCC & | GetColumnFourCC (IndexT colIndex) const |
get column FourCC | |
AccessMode | GetColumnAccessMode (IndexT colIndex) const |
get a column's access mode | |
ValueType | GetColumnValueType (IndexT colIndex) const |
get a column's value type | |
const Util::Array< IndexT > & | GetNewColumnIndices () const |
return indices of columns added since the last ResetModifiedState() | |
const Util::Array< IndexT > & | GetReadWriteColumnIndices () const |
return indices of all ReadWrite columns | |
IndexT | AddRow () |
add a row to the table, returns index of new row | |
void | ClearNewRowFlags () |
clear the new row flags, so that new rows are treated like updated rows | |
void | ClearDeletedRowsFlags () |
clear deleted rows flags | |
void | DeleteRow (IndexT rowIndex) |
mark a row as deleted from the table | |
void | DeleteAllRows () |
mark all rows as deleted | |
bool | IsRowDeleted (IndexT rowIndex) const |
return true if row has been marked as deleted | |
IndexT | CopyRow (IndexT rowIndex) |
create a new row as copy of another row | |
void | CopyRow (IndexT srcRowIndex, IndexT dstRowIndex) |
Copy contents of one row into another. | |
IndexT | CopyExtRow (AttributeTable *other, IndexT otherRowIndex, bool createMissingRows=false) |
create a new row as copy of a row from another value table | |
SizeT | GetNumRows () const |
get number of rows in table | |
bool | HasNewRows () const |
return true if table has new rows | |
bool | HasModifiedRows () const |
return true if table has modified rows | |
bool | HasDeletedRows () const |
return true if table has deleted rows | |
bool | IsRowModified (IndexT rowIndex) const |
return true if a row has been modified since the last ResetModifiedState() | |
const Util::Array< IndexT > & | GetNewRowIndices () const |
return indices of rows added since the last ResetModfiedState() | |
const Util::Array< IndexT > & | GetDeletedRowIndices () const |
return indices of rows deleted since the last ResetModifiedState() | |
Util::Array< IndexT > | GetModifiedRowsExcludeNewAndDeletedRows () const |
return array of modified rows, exclude rows marked as rows | |
void | ReserveRows (SizeT numRows) |
reserve rows to reduce re-allocation overhead | |
Util::Array< IndexT > | FindRowIndicesByAttr (const Attribute &attr, bool firstMatchOnly) const |
find all matching row indices by attribute value | |
Util::Array< IndexT > | FindRowIndicesByAttrs (const Util::Array< Attribute > &attrs, bool firstMatchOnly) const |
find all matching row indices by multiple attribute values | |
IndexT | FindRowIndexByAttr (const Attribute &attr) const |
find all matching row indices by attribute value | |
IndexT | FindRowIndexByAttrs (const Util::Array< Attribute > &attrs) const |
find all matching row indices by multiple attribute values | |
void | SetRowUserData (IndexT rowIndex, void *p) |
set an optional row user data pointer | |
void * | GetRowUserData (IndexT rowIndex) const |
get optional row user data pointer | |
void | SetAttr (const Attr::Attribute &attr, IndexT rowIndex) |
set a generic attribute (slow!) | |
Attr::Attribute | GetAttr (IndexT rowIndex, IndexT colIndex) const |
get a generic attribute | |
void | SetVariant (const Attr::AttrId &attrId, IndexT rowIndex, const Util::Variant &val) |
set variant value | |
void | SetBool (const BoolAttrId &colAttrId, IndexT rowIndex, bool val) |
set bool value | |
bool | GetBool (const BoolAttrId &colAttrId, IndexT rowIndex) const |
get bool value | |
void | SetFloat (const FloatAttrId &colAttrId, IndexT rowIndex, float val) |
set float value | |
float | GetFloat (const FloatAttrId &colAttrId, IndexT rowIndex) const |
get float value | |
void | SetInt (const IntAttrId &colAttrId, IndexT rowIndex, int val) |
set int value | |
int | GetInt (const IntAttrId &colAttrId, IndexT rowIndex) const |
get int value | |
void | SetString (const StringAttrId &colAttrId, IndexT rowIndex, const Util::String &val) |
set string value | |
const Util::String & | GetString (const StringAttrId &colAttrId, IndexT rowIndex) const |
get string value | |
void | SetVec4 (const Vec4AttrId &colAttrId, IndexT rowIndex, const Math::vec4 &val) |
set float4 value | |
Math::vec4 | GetVec4 (const Vec4AttrId &colAttrId, IndexT rowIndex) const |
get float4 value | |
void | SetMat4 (const Mat4AttrId &colAttrId, IndexT rowIndex, const Math::mat4 &val) |
set mat4 value | |
Math::mat4 | GetMat4 (const Mat4AttrId &colAttrId, IndexT rowIndex) const |
get mat4 value | |
void | SetGuid (const GuidAttrId &colAttrId, IndexT rowIndex, const Util::Guid &guid) |
set guid value | |
const Util::Guid & | GetGuid (const GuidAttrId &colAttrId, IndexT rowIndex) const |
get guid value | |
void | SetBlob (const BlobAttrId &colAttrId, IndexT rowIndex, const Util::Blob &blob) |
set blob value | |
const Util::Blob & | GetBlob (const BlobAttrId &colAttrId, IndexT rowIndex) const |
get blob value | |
void | SetVariant (IndexT colIndex, IndexT rowIndex, const Util::Variant &val) |
set variant value | |
void | SetBool (IndexT colIndex, IndexT rowIndex, bool val) |
set bool value by column index | |
bool | GetBool (IndexT colIndex, IndexT rowIndex) const |
get bool value by column index | |
void | SetFloat (IndexT colIndex, IndexT rowIndex, float val) |
set float value by column index | |
float | GetFloat (IndexT colIndex, IndexT rowIndex) const |
get float value by column index | |
void | SetInt (IndexT colIndex, IndexT rowIndex, int val) |
set int value by column index | |
int | GetInt (IndexT colIndex, IndexT rowIndex) const |
get int value by column index | |
void | SetUInt (IndexT colIndex, IndexT rowIndex, uint val) |
set uint value by column index | |
uint | GetUInt (IndexT colIndex, IndexT rowIndex) const |
get uint value by column index | |
void | SetString (IndexT colIndex, IndexT rowIndex, const Util::String &val) |
set string value by column index | |
const Util::String & | GetString (IndexT colIndex, IndexT rowIndex) const |
get string value by column index | |
void | SetVec4 (IndexT colIndex, IndexT rowIndex, const Math::vec4 &val) |
set float4 value by column index | |
Math::vec4 | GetVec4 (IndexT colIndex, IndexT rowIndex) const |
get float4 value by column index | |
void | SetMat4 (IndexT colIndex, IndexT rowIndex, const Math::mat4 &val) |
set mat4 value by column index | |
Math::mat4 | GetMat4 (IndexT colIndex, IndexT rowIndex) const |
get mat4 value by column index | |
void | SetGuid (IndexT colIndex, IndexT rowIndex, const Util::Guid &guid) |
set guid value by column index | |
const Util::Guid & | GetGuid (IndexT colIndex, IndexT rowIndex) const |
get guid value by column index | |
void | SetBlob (IndexT colIndex, IndexT rowIndex, const Util::Blob &blob) |
set blob value by column index | |
const Util::Blob & | GetBlob (IndexT colIndex, IndexT rowIndex) const |
get blob value by column index | |
bool | LoadXmlTable (const Util::String &fileName) |
load xml table | |
Public Member Functions inherited from Core::RefCounted | |
RefCounted () | |
constructor | |
int | GetRefCount () const |
get the current refcount | |
void | AddRef () |
increment refcount by one | |
void | Release () |
decrement refcount and destroy object if refcount is zero | |
bool | IsInstanceOf (const Rtti &rtti) const |
return true if this object is instance of given class | |
bool | IsInstanceOf (const Util::String &className) const |
return true if this object is instance of given class by string | |
bool | IsInstanceOf (const Util::FourCC &classFourCC) const |
return true if this object is instance of given class by fourcc | |
bool | IsA (const Rtti &rtti) const |
return true if this object is instance of given class, or a derived class | |
bool | IsA (const Util::String &rttiName) const |
return true if this object is instance of given class, or a derived class, by string | |
bool | IsA (const Util::FourCC &rttiFourCC) const |
return true if this object is instance of given class, or a derived class, by fourcc | |
const Util::String & | GetClassName () const |
get the class name | |
Util::FourCC | GetClassFourCC () const |
get the class FourCC code | |
Private Member Functions | |
__DeclareClass (AttributeTable) | |
void | Realloc (SizeT newPitch, SizeT newAllocRows) |
(re-)allocate the current buffer | |
SizeT | UpdateColumnOffsets () |
update the column byte offset and return new pitch | |
SizeT | GetValueTypeSize (ValueType type) const |
returns the byte size of the given value type | |
void * | GetValuePtr (IndexT colIndex, IndexT rowIndex) const |
returns pointer to a value's memory location | |
void | Delete () |
delete all externally allocated data of this object | |
void | DeleteRowData (IndexT rowIndex) |
delete row data, frees all memory used in one row | |
void | DeleteString (IndexT colIndex, IndexT rowIndex) |
delete a string from the table | |
void | CopyString (IndexT colIndex, IndexT rowIndex, const Util::String &val) |
copy a string into the table | |
void | DeleteBlob (IndexT colIndex, IndexT rowIndex) |
delete a blob from the table | |
void | CopyBlob (IndexT colIndex, IndexT rowIndex, const Util::Blob &val) |
copy a blob into the table | |
void | DeleteGuid (IndexT colIndex, IndexT rowIndex) |
delete a guid from the table | |
void | CopyGuid (IndexT colIndex, IndexT rowIndex, const Util::Guid &val) |
copy a guid into the table | |
Util::Array< IndexT > | InternalFindRowIndicesByAttr (const Attr::Attribute &attr, bool firstMatchOnly) const |
internal row-indices-by-attr find method | |
Util::Array< IndexT > | InternalFindRowIndicesByAttrs (const Util::Array< Attr::Attribute > &attr, bool firstMatchOnly) const |
internal row-indices-by-multiple-attrs find method | |
void | InternalAddColumnHelper (const AttrId &id, bool recordAsNewColumn) |
internal helper method for adding a column | |
void | SetColumnToDefaultValues (IndexT colIndex) |
set entire column to its default values | |
void | SetRowToDefaultValues (IndexT rowIndex) |
set a row to its default values | |
void | SetColumnBool (const BoolAttrId &attrId, bool val) |
set entire column float value | |
void | SetColumnFloat (const FloatAttrId &attrId, float val) |
set entire column float value | |
void | SetColumnInt (const IntAttrId &attrId, int val) |
set entire column to int value | |
void | SetColumnString (const StringAttrId &attrId, const Util::String &val) |
set entire column to string value | |
void | SetColumnVec4 (const Vec4AttrId &attrId, const Math::vec4 &val) |
set entire column vec4 value | |
void | SetColumnMat4 (const Mat4AttrId &attrId, const Math::mat4 &val) |
set entire column to mat4 value | |
void | SetColumnGuid (const GuidAttrId &attrId, const Util::Guid &guid) |
set entire column to guid value | |
void | SetColumnBlob (const BlobAttrId &attrId, const Util::Blob &blob) |
set entire column to blob value | |
Private Attributes | |
Util::Array< ColumnInfo > | columns |
Util::Dictionary< AttrId, IndexT > | indexMap |
Util::Array< IndexT > | readWriteColumnIndices |
Util::Array< IndexT > | newColumnIndices |
Util::Array< IndexT > | newRowIndices |
Util::Array< IndexT > | deletedRowIndices |
Util::Array< void * > | userData |
SizeT | rowPitch |
SizeT | numRows |
SizeT | allocatedRows |
void * | valueBuffer |
uchar * | rowModifiedBuffer |
uchar * | rowDeletedBuffer |
uchar * | rowNewBuffer |
bool | trackModifications |
bool | isModified |
bool | rowsModified |
bool | inBeginAddColumns |
bool | addColumnsRecordAsNewColumns |
IndexT | firstNewColumnIndex |
Additional Inherited Members | |
Static Public Member Functions inherited from Core::RefCounted | |
static void | DumpRefCountingLeaks () |
dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!) | |
Protected Member Functions inherited from Core::RefCounted | |
virtual | ~RefCounted () |
destructor (called when refcount reaches zero) | |
Attr::AttributeTable::AttributeTable | ( | ) |
constructor
Attr::AttributeTable::AttributeTable | ( | std::initializer_list< Attr::AttrId > | columns, |
bool | recordColumns = false ) |
construct with initializer list
|
virtual |
destructor
|
private |
void Attr::AttributeTable::AddColumn | ( | const AttrId & | id, |
bool | recordAsNewColumn = true ) |
add a column
Add a column to the attribute table.
If the attribute table already contains data, this will reallocate the existing data buffer. The name, data type, access mode, etc of the column is all defined by the given attribute id. The new column will be filled with the attribute id's default value.
IndexT Attr::AttributeTable::AddRow | ( | ) |
add a row to the table, returns index of new row
Adds an empty row at the end of the value buffer.
The row will be marked invalid until the first value is set in the row. This will re-allocate the existing value buffer. If you know beforehand how many rows will exist in the table it is more efficient to use one SetNumRows(N) instead of N times AddRow()! The method returns the index of the newly added row. The row will be filled with the row attribute's default values.
void Attr::AttributeTable::BeginAddColumns | ( | bool | recordAsNewColumns = true | ) |
optional: call before adding columns, speeds up adding many columns at once
Begin adding columns.
Columns can be added at any time, but it will be much more efficient when called between BeginAddColumns() and EndAddColumns(), since this will save a lot of re-allocations.
void Attr::AttributeTable::Clear | ( | ) |
clear the table object
Clear all rows data and reset the number of rows.
void Attr::AttributeTable::ClearDeletedRowsFlags | ( | ) |
clear deleted rows flags
Clears the deleted row flags.
void Attr::AttributeTable::ClearNewRowFlags | ( | ) |
clear the new row flags, so that new rows are treated like updated rows
Clears the new row flags.
After this, new rows are treated just like updated rows, which may be useful for some database operations (when an UPDATE is wanted instead of an INSERT).
|
private |
copy a blob into the table
IndexT Attr::AttributeTable::CopyExtRow | ( | AttributeTable * | other, |
IndexT | otherRowIndex, | ||
bool | createMissingRows = false ) |
create a new row as copy of a row from another value table
Create a new row as a copy of a row in another value table.
The layouts of the value tables must not match, since only matching columns will be considered. NOTE: the user data will be initialised to 0 for the new row.
|
private |
copy a guid into the table
create a new row as copy of another row
This creates a new row as a copy of an existing row.
Returns the index of the new row. NOTE: the user data will be initialized to 0 for the new row!
Copy contents of one row into another.
|
private |
copy a string into the table
|
private |
delete all externally allocated data of this object
This frees all allocated data associated with the table.
void Attr::AttributeTable::DeleteAllRows | ( | ) |
mark all rows as deleted
Marks all rows in the table as deleted.
delete a blob from the table
delete a guid from the table
void Attr::AttributeTable::DeleteRow | ( | IndexT | rowIndex | ) |
mark a row as deleted from the table
This marks a row for deletion.
Note that the row will only be marked for deletion, deleted row indices are returned with the GetDeletedRowIndices() call. The row will never be physically removed from memory!
|
private |
delete row data, frees all memory used in one row
Clears all data associated with cells of one row (string, blob and guid)
delete a string from the table
void Attr::AttributeTable::EndAddColumns | ( | ) |
optional: call after adding columns, speeds up adding many columns at once
End adding columns.
This will do the actual work.
find all matching row indices by attribute value
Finds single row index by matching attribute.
This method can be slow since it may search linearly (and vertically) through the table.
IndexT Attr::AttributeTable::FindRowIndexByAttrs | ( | const Util::Array< Attribute > & | attrs | ) | const |
find all matching row indices by multiple attribute values
Finds single row index by multiple matching attributes.
This method can be slow since it may search linearly (and vertically) through the table.
Util::Array< IndexT > Attr::AttributeTable::FindRowIndicesByAttr | ( | const Attribute & | attr, |
bool | firstMatchOnly ) const |
find all matching row indices by attribute value
Finds multiple row indices by matching attribute.
This method can be slow since it may search linearly (and vertically) through the table.
Util::Array< IndexT > Attr::AttributeTable::FindRowIndicesByAttrs | ( | const Util::Array< Attribute > & | attrs, |
bool | firstMatchOnly ) const |
find all matching row indices by multiple attribute values
Finds multiple row indices by multiple matching attribute.
This method can be slow since it may search linearly (and vertically) through the table.
Attr::Attribute Attr::AttributeTable::GetAttr | ( | IndexT | rowIndex, |
IndexT | colIndex ) const |
get a generic attribute
|
inline |
get blob value
|
inline |
get blob value by column index
|
inline |
get bool value
get bool value by column index
|
inline |
get a column's access mode
|
inline |
get column FourCC
get column definition at index
return index of column by id
|
inline |
get a column's name
get a column's value type
|
inline |
return indices of rows deleted since the last ResetModifiedState()
|
inline |
get float value
get float value by column index
|
inline |
get guid value
|
inline |
get guid value by column index
get int value
get int value by column index
|
inline |
get mat4 value
|
inline |
get mat4 value by column index
Util::Array< IndexT > Attr::AttributeTable::GetModifiedRowsExcludeNewAndDeletedRows | ( | ) | const |
return array of modified rows, exclude rows marked as rows
Returns an array of all modified rows, but excludes rows marked as new.
|
inline |
get modified tracking flag
|
inline |
return indices of columns added since the last ResetModifiedState()
|
inline |
return indices of rows added since the last ResetModfiedState()
|
inline |
get number of columns
|
inline |
get number of rows in table
|
inline |
return indices of all ReadWrite columns
void * Attr::AttributeTable::GetRowUserData | ( | IndexT | rowIndex | ) | const |
get optional row user data pointer
|
inline |
get string value
|
inline |
get string value by column index
get uint value by column index
returns pointer to a value's memory location
This returns a pointer to a value's memory location.
returns the byte size of the given value type
This returns the cell size for a value type.
The minimum size is 4 (even for Bools), for data alignment reasons. Strings are stored as char pointers, the rest takes as much memory as needed.
|
inline |
get float4 value
|
inline |
get float4 value by column index
|
inline |
return true if a column exists
|
inline |
return true if table has deleted rows
|
inline |
return true if table has modified rows
|
inline |
return true if table has new rows
|
private |
internal helper method for adding a column
Internal helper method to add a new column.
This is called by EndAddColumns() and AddColumn().
|
private |
internal row-indices-by-attr find method
Finds a row index by single attribute value.
This method can be slow since it may search linearly (and vertically) through the table.
FIXME: keep row indices for indexed rows in nDictionaries?
|
private |
internal row-indices-by-multiple-attrs find method
Finds a row index by multiple attribute values.
This method can be slow since it may search linearly (and vertically) through the table. Also, for one attribute this method is slower then InternalFindRowIndicesByAttr()!
FIXME: keep row indices for indexed rows in nDictionaries?
|
inline |
return true if the object has been modified since the last ResetModifiedState()
|
inline |
return true if row has been marked as deleted
Return true if a row has been marked as deleted.
|
inline |
return true if a row has been modified since the last ResetModifiedState()
Quickly check if a row is modified.
bool Attr::AttributeTable::LoadXmlTable | ( | const Util::String & | fileName | ) |
load xml table
void Attr::AttributeTable::PrintDebug | ( | ) |
print the contents of the table for debugging reasons
Print contents of the table for debugging.
(re-)allocate the current buffer
Reallocate the value and modified row buffer, and copy contents over into the new buffer.
void Attr::AttributeTable::ReserveRows | ( | SizeT | numRows | ) |
reserve rows to reduce re-allocation overhead
Reserve N more rows beforehand to reduce re-allocation overhead during AddRow().
void Attr::AttributeTable::ResetModifiedState | ( | ) |
reset all the modified bits in the table
This method resets the object to the unmodified state, which means the new-row and new-column index arrays are reset, and all modified bits are cleared.
void Attr::AttributeTable::SetAttr | ( | const Attr::Attribute & | attr, |
IndexT | rowIndex ) |
set a generic attribute (slow!)
Set a generic attribute, this is a slow method!
|
inline |
set blob value
|
inline |
set blob value by column index
|
inline |
set bool value
set bool value by column index
|
private |
set entire column to blob value
|
private |
set entire column float value
|
private |
set entire column float value
|
private |
set entire column to guid value
|
private |
set entire column to int value
|
private |
set entire column to mat4 value
|
private |
set entire column to string value
|
private |
set entire column to its default values
This sets all attributes in a column to its default values.
|
private |
set entire column vec4 value
|
inline |
set float value
set float value by column index
|
inline |
set guid value
|
inline |
set guid value by column index
set int value
set int value by column index
|
inline |
set mat4 value
|
inline |
set mat4 value by column index
|
inline |
enable/disable modified tracking (default is on)
|
private |
set a row to its default values
This sets all attributes in a row to its default values.
void Attr::AttributeTable::SetRowUserData | ( | IndexT | rowIndex, |
void * | p ) |
set an optional row user data pointer
|
inline |
set string value
|
inline |
set string value by column index
set uint value by column index
void Attr::AttributeTable::SetVariant | ( | const Attr::AttrId & | attrId, |
IndexT | rowIndex, | ||
const Util::Variant & | val ) |
set variant value
void Attr::AttributeTable::SetVariant | ( | IndexT | colIndex, |
IndexT | rowIndex, | ||
const Util::Variant & | val ) |
set variant value
|
inline |
set float4 value
|
inline |
set float4 value by column index
|
private |
update the column byte offset and return new pitch
This updates the byte offsets for the current column configuration.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |