Nebula
Loading...
Searching...
No Matches
attributetable.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
27#include "core/refcounted.h"
28#include "attribute.h"
29
30//------------------------------------------------------------------------------
31namespace Attr
32{
34{
36public:
40 AttributeTable(std::initializer_list<Attr::AttrId> columns, bool recordColumns = false);
42 virtual ~AttributeTable();
43
45 void SetModifiedTracking(bool b);
47 bool GetModifiedTracking() const;
49 bool IsModified() const;
51 void ResetModifiedState();
53 void Clear();
55 void PrintDebug();
56
58 void BeginAddColumns(bool recordNewColumns=true);
60 void AddColumn(const AttrId& id, bool recordNewColumn=true);
62 void EndAddColumns();
64 bool HasColumn(const AttrId& id) const;
66 IndexT GetColumnIndex(const AttrId& id) const;
68 SizeT GetNumColumns() const;
70 const AttrId& GetColumnId(IndexT colIndex) const;
72 const Util::String& GetColumnName(IndexT colIndex) const;
74 const Util::FourCC& GetColumnFourCC(IndexT colIndex) const;
78 ValueType GetColumnValueType(IndexT colIndex) const;
83
85 IndexT AddRow();
87 void ClearNewRowFlags();
91 void DeleteRow(IndexT rowIndex);
93 void DeleteAllRows();
95 bool IsRowDeleted(IndexT rowIndex) const;
97 IndexT CopyRow(IndexT rowIndex);
99 void CopyRow(IndexT srcRowIndex, IndexT dstRowIndex);
101 IndexT CopyExtRow(AttributeTable* other, IndexT otherRowIndex, bool createMissingRows = false);
103 SizeT GetNumRows() const;
105 bool HasNewRows() const;
107 bool HasModifiedRows() const;
109 bool HasDeletedRows() const;
111 bool IsRowModified(IndexT rowIndex) const;
121 Util::Array<IndexT> FindRowIndicesByAttr(const Attribute& attr, bool firstMatchOnly) const;
123 Util::Array<IndexT> FindRowIndicesByAttrs(const Util::Array<Attribute>& attrs, bool firstMatchOnly) const;
125 IndexT FindRowIndexByAttr(const Attribute& attr) const;
129 void SetRowUserData(IndexT rowIndex, void* p);
131 void* GetRowUserData(IndexT rowIndex) const;
132
134 void SetAttr(const Attr::Attribute& attr, IndexT rowIndex);
136 Attr::Attribute GetAttr(IndexT rowIndex, IndexT colIndex) const;
138 void SetVariant(const Attr::AttrId& attrId, IndexT rowIndex, const Util::Variant& val);
140 void SetBool(const BoolAttrId& colAttrId, IndexT rowIndex, bool val);
142 bool GetBool(const BoolAttrId& colAttrId, IndexT rowIndex) const;
144 void SetFloat(const FloatAttrId& colAttrId, IndexT rowIndex, float val);
146 float GetFloat(const FloatAttrId& colAttrId, IndexT rowIndex) const;
148 void SetInt(const IntAttrId& colAttrId, IndexT rowIndex, int val);
150 int GetInt(const IntAttrId& colAttrId, IndexT rowIndex) const;
152 void SetString(const StringAttrId& colAttrId, IndexT rowIndex, const Util::String& val);
154 const Util::String& GetString(const StringAttrId& colAttrId, IndexT rowIndex) const;
156 void SetVec4(const Vec4AttrId& colAttrId, IndexT rowIndex, const Math::vec4& val);
158 Math::vec4 GetVec4(const Vec4AttrId& colAttrId, IndexT rowIndex) const;
160 void SetMat4(const Mat4AttrId& colAttrId, IndexT rowIndex, const Math::mat4& val);
162 Math::mat4 GetMat4(const Mat4AttrId& colAttrId, IndexT rowIndex) const;
164 void SetGuid(const GuidAttrId& colAttrId, IndexT rowIndex, const Util::Guid& guid);
166 const Util::Guid& GetGuid(const GuidAttrId& colAttrId, IndexT rowIndex) const;
168 void SetBlob(const BlobAttrId& colAttrId, IndexT rowIndex, const Util::Blob& blob);
170 const Util::Blob& GetBlob(const BlobAttrId& colAttrId, IndexT rowIndex) const;
171
173 void SetVariant(IndexT colIndex, IndexT rowIndex, const Util::Variant& val);
175 void SetBool(IndexT colIndex, IndexT rowIndex, bool val);
177 bool GetBool(IndexT colIndex, IndexT rowIndex) const;
179 void SetFloat(IndexT colIndex, IndexT rowIndex, float val);
181 float GetFloat(IndexT colIndex, IndexT rowIndex) const;
183 void SetInt(IndexT colIndex, IndexT rowIndex, int val);
185 int GetInt(IndexT colIndex, IndexT rowIndex) const;
187 void SetUInt(IndexT colIndex, IndexT rowIndex, uint val);
189 uint GetUInt(IndexT colIndex, IndexT rowIndex) const;
191 void SetString(IndexT colIndex, IndexT rowIndex, const Util::String& val);
193 const Util::String& GetString(IndexT colIndex, IndexT rowIndex) const;
195 void SetVec4(IndexT colIndex, IndexT rowIndex, const Math::vec4& val);
197 Math::vec4 GetVec4(IndexT colIndex, IndexT rowIndex) const;
199 void SetMat4(IndexT colIndex, IndexT rowIndex, const Math::mat4& val);
201 Math::mat4 GetMat4(IndexT colIndex, IndexT rowIndex) const;
203 void SetGuid(IndexT colIndex, IndexT rowIndex, const Util::Guid& guid);
205 const Util::Guid& GetGuid(IndexT colIndex, IndexT rowIndex) const;
207 void SetBlob(IndexT colIndex, IndexT rowIndex, const Util::Blob& blob);
209 const Util::Blob& GetBlob(IndexT colIndex, IndexT rowIndex) const;
210
212 bool LoadXmlTable(const Util::String& fileName);
213
214private:
216 void Realloc(SizeT newPitch, SizeT newAllocRows);
220 SizeT GetValueTypeSize(ValueType type) const;
222 void* GetValuePtr(IndexT colIndex, IndexT rowIndex) const;
224 void Delete();
226 void DeleteRowData(IndexT rowIndex);
228 void DeleteString(IndexT colIndex, IndexT rowIndex);
230 void CopyString(IndexT colIndex, IndexT rowIndex, const Util::String& val);
232 void DeleteBlob(IndexT colIndex, IndexT rowIndex);
234 void CopyBlob(IndexT colIndex, IndexT rowIndex, const Util::Blob& val);
236 void DeleteGuid(IndexT colIndex, IndexT rowIndex);
238 void CopyGuid(IndexT colIndex, IndexT rowIndex, const Util::Guid& val);
240 Util::Array<IndexT> InternalFindRowIndicesByAttr(const Attr::Attribute& attr, bool firstMatchOnly) const;
244 void InternalAddColumnHelper(const AttrId& id, bool recordAsNewColumn);
245
247 void SetColumnToDefaultValues(IndexT colIndex);
249 void SetRowToDefaultValues(IndexT rowIndex);
250
252 void SetColumnBool(const BoolAttrId& attrId, bool val);
254 void SetColumnFloat(const FloatAttrId& attrId, float val);
256 void SetColumnInt(const IntAttrId& attrId, int val);
258 void SetColumnString(const StringAttrId& attrId, const Util::String& val);
260 void SetColumnVec4(const Vec4AttrId& attrId, const Math::vec4& val);
262 void SetColumnMat4(const Mat4AttrId& attrId, const Math::mat4& val);
264 void SetColumnGuid(const GuidAttrId& attrId, const Util::Guid& guid);
266 void SetColumnBlob(const BlobAttrId& attrId, const Util::Blob& blob);
267
269 {
270 AttrId attrId; // attribute id of the column
271 IndexT byteOffset; // byte offset into a row
272 };
274 Util::Dictionary<AttrId,IndexT> indexMap; // map attribute id to column index
275 Util::Array<IndexT> readWriteColumnIndices; // indices of all columns that are read/writable
276 Util::Array<IndexT> newColumnIndices; // indices of new columns since last ResetModifiedState
277 Util::Array<IndexT> newRowIndices; // indices of new rows since last ResetModifiedState
278 Util::Array<IndexT> deletedRowIndices; // indices of rows that are marked for deletion
280 SizeT rowPitch; // pitch of a row in bytes
281 SizeT numRows; // number of rows
282 SizeT allocatedRows; // number of allocated rows
283 void* valueBuffer; // points to value buffer
284 uchar* rowModifiedBuffer; // 1 for a modified row, zero for not modified
285 uchar* rowDeletedBuffer; // 1 for a deleted row, zero for not deleted
286 uchar* rowNewBuffer; // 1 for a new row, zero for not new
287 bool trackModifications; // modified tracking on/off
288 bool isModified; // global modified flag
289 bool rowsModified; // return true if modified rows exist
290 bool inBeginAddColumns; // current inside BeginAddColumns()/EndAddColumns()
291 bool addColumnsRecordAsNewColumns; // recordAsNewColumns flag in BeginAddColumns
292 IndexT firstNewColumnIndex; // set in BeginAddColumns
293};
294
295//------------------------------------------------------------------------------
298inline
299void
304
305//------------------------------------------------------------------------------
308inline
309bool
311{
312 return this->trackModifications;
313}
314
315//------------------------------------------------------------------------------
318inline
319bool
321{
322 return this->newRowIndices.Size() > 0;
323}
324
325//------------------------------------------------------------------------------
328inline
329bool
331{
332 return this->deletedRowIndices.Size() > 0;
333}
334
335//------------------------------------------------------------------------------
338inline
339bool
341{
342 return this->rowsModified;
343}
344
345//------------------------------------------------------------------------------
348inline
354
355//------------------------------------------------------------------------------
359inline bool
361{
362 n_assert(rowIndex < this->numRows);
363 n_assert(0 != this->rowModifiedBuffer);
364 return (0 != this->rowModifiedBuffer[rowIndex]);
365}
366
367//------------------------------------------------------------------------------
371inline bool
373{
374 n_assert(rowIndex < this->numRows);
375 n_assert(0 != this->rowDeletedBuffer);
376 return (this->rowDeletedBuffer[rowIndex] == 1);
377}
378
379//------------------------------------------------------------------------------
382inline bool
384{
385 return this->isModified;
386}
387
388//------------------------------------------------------------------------------
391inline const Util::Array<IndexT>&
393{
394 return this->newRowIndices;
395}
396
397//------------------------------------------------------------------------------
400inline const Util::Array<IndexT>&
402{
403 return this->deletedRowIndices;
404}
405
406//------------------------------------------------------------------------------
409inline const Util::Array<IndexT>&
411{
412 return this->newColumnIndices;
413}
414
415//------------------------------------------------------------------------------
418inline bool
420{
421 return this->indexMap.Contains(id);
422}
423
424//------------------------------------------------------------------------------
427inline IndexT
429{
430 return this->indexMap[id];
431}
432
433//------------------------------------------------------------------------------
436inline SizeT
438{
439 return this->columns.Size();
440}
441
442//------------------------------------------------------------------------------
445inline const AttrId&
447{
448 return this->columns[colIndex].attrId;
449}
450
451//------------------------------------------------------------------------------
454inline const Util::String&
456{
457 return this->columns[colIndex].attrId.GetName();
458}
459
460//------------------------------------------------------------------------------
463inline const Util::FourCC&
465{
466 return this->columns[colIndex].attrId.GetFourCC();
467}
468
469//------------------------------------------------------------------------------
472inline AccessMode
474{
475 return this->columns[colIndex].attrId.GetAccessMode();
476}
477
478//------------------------------------------------------------------------------
481inline ValueType
483{
484 return this->columns[colIndex].attrId.GetValueType();
485}
486
487//------------------------------------------------------------------------------
490inline SizeT
492{
493 return this->numRows;
494}
495
496//------------------------------------------------------------------------------
500inline void*
502{
503 n_assert((colIndex < this->columns.Size()) && (rowIndex < this->numRows));
504 IndexT bufferOffset = (rowIndex * this->rowPitch) + this->columns[colIndex].byteOffset;
505 return (void*)((char*)this->valueBuffer + bufferOffset);
506}
507
508//------------------------------------------------------------------------------
511inline void
512AttributeTable::SetBool(IndexT colIndex, IndexT rowIndex, bool val)
513{
514 n_assert(this->GetColumnValueType(colIndex) == BoolType);
515 n_assert(!this->IsRowDeleted(rowIndex));
516 int* valuePtr = (int*) this->GetValuePtr(colIndex, rowIndex);
517 *valuePtr = val ? 1 : 0;
518 this->rowModifiedBuffer[rowIndex] = 1;
519 this->isModified = true;
520}
521
522//------------------------------------------------------------------------------
525inline bool
526AttributeTable::GetBool(IndexT colIndex, IndexT rowIndex) const
527{
528 n_assert(this->GetColumnValueType(colIndex) == BoolType);
529 int* valuePtr = (int*) this->GetValuePtr(colIndex, rowIndex);
530 return (*valuePtr != 0);
531}
532
533//------------------------------------------------------------------------------
536inline void
537AttributeTable::SetFloat(IndexT colIndex, IndexT rowIndex, float val)
538{
539 n_assert(this->GetColumnValueType(colIndex) == FloatType);
540 n_assert(!this->IsRowDeleted(rowIndex));
541 float* valuePtr = (float*) this->GetValuePtr(colIndex, rowIndex);
542 *valuePtr = val;
543 this->rowModifiedBuffer[rowIndex] = 1;
544 this->isModified = true;
545}
546
547//------------------------------------------------------------------------------
550inline float
551AttributeTable::GetFloat(IndexT colIndex, IndexT rowIndex) const
552{
553 n_assert(this->GetColumnValueType(colIndex) == FloatType);
554 float* valuePtr = (float*) this->GetValuePtr(colIndex, rowIndex);
555 return *valuePtr;
556}
557
558//------------------------------------------------------------------------------
561inline void
562AttributeTable::SetInt(IndexT colIndex, IndexT rowIndex, int val)
563{
564 n_assert(this->GetColumnValueType(colIndex) == IntType);
565 n_assert(!this->IsRowDeleted(rowIndex));
566 int* valuePtr = (int*) this->GetValuePtr(colIndex, rowIndex);
567 *valuePtr = val;
568 this->rowModifiedBuffer[rowIndex] = 1;
569 this->isModified = true;
570}
571
572//------------------------------------------------------------------------------
575inline int
576AttributeTable::GetInt(IndexT colIndex, IndexT rowIndex) const
577{
578 n_assert(this->GetColumnValueType(colIndex) == IntType);
579 int* valuePtr = (int*) this->GetValuePtr(colIndex, rowIndex);
580 return *valuePtr;
581}
582
583//------------------------------------------------------------------------------
586inline void
588{
589 n_assert(this->GetColumnValueType(colIndex) == UIntType);
590 n_assert(!this->IsRowDeleted(rowIndex));
591 uint* valuePtr = (uint*)this->GetValuePtr(colIndex, rowIndex);
592 *valuePtr = val;
593 this->rowModifiedBuffer[rowIndex] = 1;
594 this->isModified = true;
595}
596
597//------------------------------------------------------------------------------
600inline uint
601AttributeTable::GetUInt(IndexT colIndex, IndexT rowIndex) const
602{
603 n_assert(this->GetColumnValueType(colIndex) == UIntType);
604 uint* valuePtr = (uint*)this->GetValuePtr(colIndex, rowIndex);
605 return *valuePtr;
606}
607
608//------------------------------------------------------------------------------
611inline void
612AttributeTable::SetVec4(IndexT colIndex, IndexT rowIndex, const Math::vec4& val)
613{
614 n_assert(this->GetColumnValueType(colIndex) == Vec4Type);
615 n_assert(!this->IsRowDeleted(rowIndex));
616 Math::scalar* valuePtr = (Math::scalar*) this->GetValuePtr(colIndex, rowIndex);
617 val.storeu(valuePtr);
618 if (this->trackModifications)
619 {
620 this->rowModifiedBuffer[rowIndex] = 1;
621 this->isModified = true;
622 this->rowsModified = true;
623 }
624}
625
626//------------------------------------------------------------------------------
629inline Math::vec4
630AttributeTable::GetVec4(IndexT colIndex, IndexT rowIndex) const
631{
632 n_assert(this->GetColumnValueType(colIndex) == Vec4Type);
633 Math::scalar* valuePtr = (Math::scalar*) this->GetValuePtr(colIndex, rowIndex);
634 Math::vec4 vec;
635 vec.loadu(valuePtr);
636 return vec;
637}
638
639//------------------------------------------------------------------------------
642inline void
643AttributeTable::SetMat4(IndexT colIndex, IndexT rowIndex, const Math::mat4& val)
644{
645 n_assert(this->GetColumnValueType(colIndex) == Mat4Type);
646 n_assert(!this->IsRowDeleted(rowIndex));
647 Math::scalar* valuePtr = (Math::scalar*) this->GetValuePtr(colIndex, rowIndex);
648 val.storeu(valuePtr);
649 if (this->trackModifications)
650 {
651 this->rowModifiedBuffer[rowIndex] = 1;
652 this->isModified = true;
653 this->rowsModified = true;
654 }
655}
656
657//------------------------------------------------------------------------------
660inline Math::mat4
661AttributeTable::GetMat4(IndexT colIndex, IndexT rowIndex) const
662{
663 n_assert(this->GetColumnValueType(colIndex) == Mat4Type);
664 Math::scalar* valuePtr = (Math::scalar*) this->GetValuePtr(colIndex, rowIndex);
665 Math::mat4 mx;
666 mx.loadu(valuePtr);
667 return mx;
668}
669
670//------------------------------------------------------------------------------
673inline void
675{
676 n_assert(this->GetColumnValueType(colIndex) == StringType);
677 n_assert(!this->IsRowDeleted(rowIndex));
678 this->CopyString(colIndex, rowIndex, val);
679 if (this->trackModifications)
680 {
681 this->rowModifiedBuffer[rowIndex] = 1;
682 this->isModified = true;
683 this->rowsModified = true;
684 }
685}
686
687//------------------------------------------------------------------------------
690inline const Util::String&
691AttributeTable::GetString(IndexT colIndex, IndexT rowIndex) const
692{
693 n_assert(this->GetColumnValueType(colIndex) == StringType);
694 Util::String** valuePtr = (Util::String**) this->GetValuePtr(colIndex, rowIndex);
695 return **valuePtr;
696}
697
698//------------------------------------------------------------------------------
701inline void
702AttributeTable::SetGuid(IndexT colIndex, IndexT rowIndex, const Util::Guid& val)
703{
704 n_assert(this->GetColumnValueType(colIndex) == GuidType);
705 n_assert(!this->IsRowDeleted(rowIndex));
706 this->CopyGuid(colIndex, rowIndex, val);
707 if (this->trackModifications)
708 {
709 this->rowModifiedBuffer[rowIndex] = 1;
710 this->isModified = true;
711 this->rowsModified = true;
712 }
713}
714
715//------------------------------------------------------------------------------
718inline const Util::Guid&
719AttributeTable::GetGuid(IndexT colIndex, IndexT rowIndex) const
720{
721 n_assert(this->GetColumnValueType(colIndex) == GuidType);
722 Util::Guid** valuePtr = (Util::Guid**) this->GetValuePtr(colIndex, rowIndex);
723 return **valuePtr;
724}
725
726//------------------------------------------------------------------------------
729inline void
730AttributeTable::SetBlob(IndexT colIndex, IndexT rowIndex, const Util::Blob& val)
731{
732 n_assert(this->GetColumnValueType(colIndex) == BlobType);
733 n_assert(!this->IsRowDeleted(rowIndex));
734 this->CopyBlob(colIndex, rowIndex, val);
735 if (this->trackModifications)
736 {
737 this->rowModifiedBuffer[rowIndex] = 1;
738 this->isModified = true;
739 this->rowsModified = true;
740 }
741}
742
743//------------------------------------------------------------------------------
746inline const Util::Blob&
747AttributeTable::GetBlob(IndexT colIndex, IndexT rowIndex) const
748{
749 n_assert(this->GetColumnValueType(colIndex) == BlobType);
750 Util::Blob** valuePtr = (Util::Blob**) this->GetValuePtr(colIndex, rowIndex);
751 return **valuePtr;
752}
753
754//------------------------------------------------------------------------------
757inline void
758AttributeTable::SetBool(const BoolAttrId& colAttrId, IndexT rowIndex, bool val)
759{
760 this->SetBool(this->indexMap[colAttrId], rowIndex, val);
761}
762
763//------------------------------------------------------------------------------
766inline bool
767AttributeTable::GetBool(const BoolAttrId& colAttrId, IndexT rowIndex) const
768{
769 return this->GetBool(this->indexMap[colAttrId], rowIndex);
770}
771
772//------------------------------------------------------------------------------
775inline void
776AttributeTable::SetFloat(const FloatAttrId& colAttrId, IndexT rowIndex, float val)
777{
778 this->SetFloat(this->indexMap[colAttrId], rowIndex, val);
779}
780
781//------------------------------------------------------------------------------
784inline float
785AttributeTable::GetFloat(const FloatAttrId& colAttrId, IndexT rowIndex) const
786{
787 return this->GetFloat(this->indexMap[colAttrId], rowIndex);
788}
789
790//------------------------------------------------------------------------------
793inline void
794AttributeTable::SetInt(const IntAttrId& colAttrId, IndexT rowIndex, int val)
795{
796 this->SetInt(this->indexMap[colAttrId], rowIndex, val);
797}
798
799//------------------------------------------------------------------------------
802inline int
803AttributeTable::GetInt(const IntAttrId& colAttrId, IndexT rowIndex) const
804{
805 return this->GetInt(this->indexMap[colAttrId], rowIndex);
806}
807
808//------------------------------------------------------------------------------
811inline void
812AttributeTable::SetVec4(const Vec4AttrId& colAttrId, IndexT rowIndex, const Math::vec4& val)
813{
814 this->SetVec4(this->indexMap[colAttrId], rowIndex, val);
815}
816
817//------------------------------------------------------------------------------
820inline Math::vec4
821AttributeTable::GetVec4(const Vec4AttrId& colAttrId, IndexT rowIndex) const
822{
823 return this->GetVec4(this->indexMap[colAttrId], rowIndex);
824}
825
826//------------------------------------------------------------------------------
829inline void
830AttributeTable::SetMat4(const Mat4AttrId& colAttrId, IndexT rowIndex, const Math::mat4& val)
831{
832 this->SetMat4(this->indexMap[colAttrId], rowIndex, val);
833}
834
835//------------------------------------------------------------------------------
838inline Math::mat4
839AttributeTable::GetMat4(const Mat4AttrId& colAttrId, IndexT rowIndex) const
840{
841 return this->GetMat4(this->indexMap[colAttrId], rowIndex);
842}
843
844//------------------------------------------------------------------------------
847inline void
848AttributeTable::SetString(const StringAttrId& colAttrId, IndexT rowIndex, const Util::String& val)
849{
850 this->SetString(this->indexMap[colAttrId], rowIndex, val);
851}
852
853//------------------------------------------------------------------------------
856inline const Util::String&
857AttributeTable::GetString(const StringAttrId& colAttrId, IndexT rowIndex) const
858{
859 return this->GetString(this->indexMap[colAttrId], rowIndex);
860}
861
862//------------------------------------------------------------------------------
865inline void
866AttributeTable::SetGuid(const GuidAttrId& colAttrId, IndexT rowIndex, const Util::Guid& val)
867{
868 this->SetGuid(this->indexMap[colAttrId], rowIndex, val);
869}
870
871//------------------------------------------------------------------------------
874inline const Util::Guid&
875AttributeTable::GetGuid(const GuidAttrId& colAttrId, IndexT rowIndex) const
876{
877 return this->GetGuid(this->indexMap[colAttrId], rowIndex);
878}
879
880//------------------------------------------------------------------------------
883inline void
884AttributeTable::SetBlob(const BlobAttrId& colAttrId, IndexT rowIndex, const Util::Blob& val)
885{
886 this->SetBlob(this->indexMap[colAttrId], rowIndex, val);
887}
888
889//------------------------------------------------------------------------------
892inline const Util::Blob&
893AttributeTable::GetBlob(const BlobAttrId& colAttrId, IndexT rowIndex) const
894{
895 return this->GetBlob(this->indexMap[colAttrId], rowIndex);
896}
897
898} // namespace Db
899//------------------------------------------------------------------------------
An attribute ID is used to carry attribute types (no values) around.
Definition attrid.h:20
A compiletime-typesafe key/value pair.
Definition attribute.h:32
A table of attributes with a compact memory footprint and fast random access.
Definition attributetable.h:34
void ReserveRows(SizeT numRows)
reserve rows to reduce re-allocation overhead
Definition attributetable.cc:704
void SetRowToDefaultValues(IndexT rowIndex)
set a row to its default values
Definition attributetable.cc:1078
IndexT CopyRow(IndexT rowIndex)
create a new row as copy of another row
Definition attributetable.cc:572
SizeT allocatedRows
Definition attributetable.h:282
SizeT GetNumRows() const
get number of rows in table
Definition attributetable.h:491
void BeginAddColumns(bool recordNewColumns=true)
optional: call before adding columns, speeds up adding many columns at once
Definition attributetable.cc:412
ValueType GetColumnValueType(IndexT colIndex) const
get a column's value type
Definition attributetable.h:482
IndexT FindRowIndexByAttr(const Attribute &attr) const
find all matching row indices by attribute value
Definition attributetable.cc:1023
bool HasDeletedRows() const
return true if table has deleted rows
Definition attributetable.h:330
AttributeTable()
constructor
Definition attributetable.cc:19
IndexT GetColumnIndex(const AttrId &id) const
return index of column by id
Definition attributetable.h:428
bool HasNewRows() const
return true if table has new rows
Definition attributetable.h:320
Util::Array< IndexT > GetModifiedRowsExcludeNewAndDeletedRows() const
return array of modified rows, exclude rows marked as rows
Definition attributetable.cc:1265
bool addColumnsRecordAsNewColumns
Definition attributetable.h:291
void InternalAddColumnHelper(const AttrId &id, bool recordAsNewColumn)
internal helper method for adding a column
Definition attributetable.cc:426
uchar * rowDeletedBuffer
Definition attributetable.h:285
void SetBlob(const BlobAttrId &colAttrId, IndexT rowIndex, const Util::Blob &blob)
set blob value
Definition attributetable.h:884
void DeleteAllRows()
mark all rows as deleted
Definition attributetable.cc:556
void SetBool(const BoolAttrId &colAttrId, IndexT rowIndex, bool val)
set bool value
Definition attributetable.h:758
void SetColumnVec4(const Vec4AttrId &attrId, const Math::vec4 &val)
set entire column vec4 value
void SetModifiedTracking(bool b)
enable/disable modified tracking (default is on)
Definition attributetable.h:300
Math::mat4 GetMat4(const Mat4AttrId &colAttrId, IndexT rowIndex) const
get mat4 value
Definition attributetable.h:839
void DeleteString(IndexT colIndex, IndexT rowIndex)
delete a string from the table
Definition attributetable.cc:116
bool trackModifications
Definition attributetable.h:287
const Util::Array< IndexT > & GetReadWriteColumnIndices() const
return indices of all ReadWrite columns
Definition attributetable.h:350
void * GetRowUserData(IndexT rowIndex) const
get optional row user data pointer
Definition attributetable.cc:1068
Attr::Attribute GetAttr(IndexT rowIndex, IndexT colIndex) const
get a generic attribute
Definition attributetable.cc:1239
void SetColumnToDefaultValues(IndexT colIndex)
set entire column to its default values
Definition attributetable.cc:1107
SizeT UpdateColumnOffsets()
update the column byte offset and return new pitch
Definition attributetable.cc:389
void CopyBlob(IndexT colIndex, IndexT rowIndex, const Util::Blob &val)
copy a blob into the table
Definition attributetable.cc:166
__DeclareClass(AttributeTable)
bool inBeginAddColumns
Definition attributetable.h:290
SizeT GetValueTypeSize(ValueType type) const
returns the byte size of the given value type
Definition attributetable.cc:362
IndexT CopyExtRow(AttributeTable *other, IndexT otherRowIndex, bool createMissingRows=false)
create a new row as copy of a row from another value table
Definition attributetable.cc:638
uchar * rowModifiedBuffer
Definition attributetable.h:284
SizeT rowPitch
Definition attributetable.h:280
void SetColumnBool(const BoolAttrId &attrId, bool val)
set entire column float value
void SetVec4(const Vec4AttrId &colAttrId, IndexT rowIndex, const Math::vec4 &val)
set float4 value
Definition attributetable.h:812
void CopyGuid(IndexT colIndex, IndexT rowIndex, const Util::Guid &val)
copy a guid into the table
Definition attributetable.cc:131
void ClearNewRowFlags()
clear the new row flags, so that new rows are treated like updated rows
Definition attributetable.cc:770
Util::Dictionary< AttrId, IndexT > indexMap
Definition attributetable.h:274
virtual ~AttributeTable()
destructor
Definition attributetable.cc:59
IndexT AddRow()
add a row to the table, returns index of new row
Definition attributetable.cc:721
const Util::Blob & GetBlob(const BlobAttrId &colAttrId, IndexT rowIndex) const
get blob value
Definition attributetable.h:893
bool HasModifiedRows() const
return true if table has modified rows
Definition attributetable.h:340
uint GetUInt(IndexT colIndex, IndexT rowIndex) const
get uint value by column index
Definition attributetable.h:601
bool HasColumn(const AttrId &id) const
return true if a column exists
Definition attributetable.h:419
void CopyString(IndexT colIndex, IndexT rowIndex, const Util::String &val)
copy a string into the table
Definition attributetable.cc:96
bool IsRowModified(IndexT rowIndex) const
return true if a row has been modified since the last ResetModifiedState()
Definition attributetable.h:360
IndexT firstNewColumnIndex
Definition attributetable.h:292
const Util::Array< IndexT > & GetDeletedRowIndices() const
return indices of rows deleted since the last ResetModifiedState()
Definition attributetable.h:401
IndexT FindRowIndexByAttrs(const Util::Array< Attribute > &attrs) const
find all matching row indices by multiple attribute values
Definition attributetable.cc:1042
bool GetBool(const BoolAttrId &colAttrId, IndexT rowIndex) const
get bool value
Definition attributetable.h:767
Util::Array< IndexT > deletedRowIndices
Definition attributetable.h:278
Util::Array< IndexT > FindRowIndicesByAttr(const Attribute &attr, bool firstMatchOnly) const
find all matching row indices by attribute value
Definition attributetable.cc:1001
const AttrId & GetColumnId(IndexT colIndex) const
get column definition at index
Definition attributetable.h:446
void DeleteRow(IndexT rowIndex)
mark a row as deleted from the table
Definition attributetable.cc:533
Math::vec4 GetVec4(const Vec4AttrId &colAttrId, IndexT rowIndex) const
get float4 value
Definition attributetable.h:821
Util::Array< IndexT > InternalFindRowIndicesByAttrs(const Util::Array< Attr::Attribute > &attr, bool firstMatchOnly) const
internal row-indices-by-multiple-attrs find method
Definition attributetable.cc:795
const Util::Guid & GetGuid(const GuidAttrId &colAttrId, IndexT rowIndex) const
get guid value
Definition attributetable.h:875
void SetInt(const IntAttrId &colAttrId, IndexT rowIndex, int val)
set int value
Definition attributetable.h:794
Util::Array< IndexT > newColumnIndices
Definition attributetable.h:276
void PrintDebug()
print the contents of the table for debugging reasons
Definition attributetable.cc:1286
void SetMat4(const Mat4AttrId &colAttrId, IndexT rowIndex, const Math::mat4 &val)
set mat4 value
Definition attributetable.h:830
void SetVariant(const Attr::AttrId &attrId, IndexT rowIndex, const Util::Variant &val)
set variant value
Definition attributetable.cc:1329
void SetGuid(const GuidAttrId &colAttrId, IndexT rowIndex, const Util::Guid &guid)
set guid value
Definition attributetable.h:866
void SetString(const StringAttrId &colAttrId, IndexT rowIndex, const Util::String &val)
set string value
Definition attributetable.h:848
const Util::Array< IndexT > & GetNewColumnIndices() const
return indices of columns added since the last ResetModifiedState()
Definition attributetable.h:410
void * GetValuePtr(IndexT colIndex, IndexT rowIndex) const
returns pointer to a value's memory location
Definition attributetable.h:501
void DeleteGuid(IndexT colIndex, IndexT rowIndex)
delete a guid from the table
Definition attributetable.cc:151
void SetColumnString(const StringAttrId &attrId, const Util::String &val)
set entire column to string value
void EndAddColumns()
optional: call after adding columns, speeds up adding many columns at once
Definition attributetable.cc:460
void SetColumnInt(const IntAttrId &attrId, int val)
set entire column to int value
bool rowsModified
Definition attributetable.h:289
void SetFloat(const FloatAttrId &colAttrId, IndexT rowIndex, float val)
set float value
Definition attributetable.h:776
bool isModified
Definition attributetable.h:288
void ResetModifiedState()
reset all the modified bits in the table
Definition attributetable.cc:71
const Util::FourCC & GetColumnFourCC(IndexT colIndex) const
get column FourCC
Definition attributetable.h:464
void SetColumnMat4(const Mat4AttrId &attrId, const Math::mat4 &val)
set entire column to mat4 value
bool IsModified() const
return true if the object has been modified since the last ResetModifiedState()
Definition attributetable.h:383
void DeleteRowData(IndexT rowIndex)
delete row data, frees all memory used in one row
Definition attributetable.cc:1386
void SetUInt(IndexT colIndex, IndexT rowIndex, uint val)
set uint value by column index
Definition attributetable.h:587
const Util::Array< IndexT > & GetNewRowIndices() const
return indices of rows added since the last ResetModfiedState()
Definition attributetable.h:392
bool GetModifiedTracking() const
get modified tracking flag
Definition attributetable.h:310
void * valueBuffer
Definition attributetable.h:283
Util::Array< IndexT > readWriteColumnIndices
Definition attributetable.h:275
void SetColumnGuid(const GuidAttrId &attrId, const Util::Guid &guid)
set entire column to guid value
void Clear()
clear the table object
Definition attributetable.cc:268
Util::Array< void * > userData
Definition attributetable.h:279
AccessMode GetColumnAccessMode(IndexT colIndex) const
get a column's access mode
Definition attributetable.h:473
void Realloc(SizeT newPitch, SizeT newAllocRows)
(re-)allocate the current buffer
Definition attributetable.cc:279
int GetInt(const IntAttrId &colAttrId, IndexT rowIndex) const
get int value
Definition attributetable.h:803
void DeleteBlob(IndexT colIndex, IndexT rowIndex)
delete a blob from the table
Definition attributetable.cc:186
Util::Array< IndexT > InternalFindRowIndicesByAttr(const Attr::Attribute &attr, bool firstMatchOnly) const
internal row-indices-by-attr find method
Definition attributetable.cc:903
void AddColumn(const AttrId &id, bool recordNewColumn=true)
add a column
Definition attributetable.cc:498
void ClearDeletedRowsFlags()
clear deleted rows flags
Definition attributetable.cc:781
void SetAttr(const Attr::Attribute &attr, IndexT rowIndex)
set a generic attribute (slow!)
Definition attributetable.cc:1214
void SetRowUserData(IndexT rowIndex, void *p)
set an optional row user data pointer
Definition attributetable.cc:1059
bool IsRowDeleted(IndexT rowIndex) const
return true if row has been marked as deleted
Definition attributetable.h:372
void Delete()
delete all externally allocated data of this object
Definition attributetable.cc:202
const Util::String & GetString(const StringAttrId &colAttrId, IndexT rowIndex) const
get string value
Definition attributetable.h:857
SizeT GetNumColumns() const
get number of columns
Definition attributetable.h:437
void SetColumnBlob(const BlobAttrId &attrId, const Util::Blob &blob)
set entire column to blob value
uchar * rowNewBuffer
Definition attributetable.h:286
SizeT numRows
Definition attributetable.h:281
Util::Array< IndexT > FindRowIndicesByAttrs(const Util::Array< Attribute > &attrs, bool firstMatchOnly) const
find all matching row indices by multiple attribute values
Definition attributetable.cc:1012
void SetColumnFloat(const FloatAttrId &attrId, float val)
set entire column float value
Util::Array< ColumnInfo > columns
Definition attributetable.h:273
Util::Array< IndexT > newRowIndices
Definition attributetable.h:277
float GetFloat(const FloatAttrId &colAttrId, IndexT rowIndex) const
get float value
Definition attributetable.h:785
const Util::String & GetColumnName(IndexT colIndex) const
get a column's name
Definition attributetable.h:455
bool LoadXmlTable(const Util::String &fileName)
load xml table
Typed attribute id for blob type.
Definition blobattrid.h:18
Typed attribute id for bool type.
Definition boolattrid.h:18
Typed attribute id for float type.
Definition floatattrid.h:18
Typed attribute id for guid type.
Definition guidattrid.h:18
Typed attribute id for integer type.
Definition intattrid.h:18
Typed attribute id for mat4 type.
Definition mat4attrid.h:18
Typed attribute id for string type.
Definition stringattrid.h:18
Typed attribute id for vec4 type.
Definition vec4attrid.h:18
The common base class of Nebula.
Definition refcounted.h:38
Nebula's dynamic array class.
Definition array.h:60
const SizeT Size() const
get number of elements in array
Definition array.h:880
The Util::Blob class encapsulates a chunk of raw memory into a C++ object which can be copied,...
Definition blob.h:22
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
A four-character-code is a quasi-human-readable 32-bit-id.
Definition fourcc.h:19
Implements a GUID.
An "any type" variable.
Definition variant.h:31
#define n_assert(exp)
Definition debug.h:50
Definition accessmode.h:13
ValueType
Definition valuetype.h:20
@ Vec4Type
Definition valuetype.h:33
@ IntType
Definition valuetype.h:25
@ FloatType
Definition valuetype.h:29
@ Mat4Type
Definition valuetype.h:36
@ BoolType
Definition valuetype.h:31
@ StringType
Definition valuetype.h:35
@ BlobType
Definition valuetype.h:38
@ UIntType
Definition valuetype.h:26
@ GuidType
Definition valuetype.h:39
AccessMode
Definition accessmode.h:15
float scalar
Definition scalar.h:45
Definition attributetable.h:269
IndexT byteOffset
Definition attributetable.h:271
AttrId attrId
Definition attributetable.h:270
A 4x4 single point precision float matrix.
Definition mat4.h:49
void loadu(const scalar *ptr)
load content from unaligned memory
Definition mat4.h:215
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition mat4.h:250
A 4D vector.
Definition vec4.h:24
void loadu(const scalar *ptr)
load content from unaligned memory
Definition vec4.h:181
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition vec4.h:201
Nebula's universal string class.
Definition string.h:50
unsigned char uchar
Definition types.h:33
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31
int IndexT
Definition types.h:48