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 SetInt64(const Int64AttrId& colAttrId, IndexT rowIndex, int64_t val);
154 int64_t GetInt64(const Int64AttrId& colAttrId, IndexT rowIndex) const;
156 void SetString(const StringAttrId& colAttrId, IndexT rowIndex, const Util::String& val);
158 const Util::String& GetString(const StringAttrId& colAttrId, IndexT rowIndex) const;
160 void SetVec4(const Vec4AttrId& colAttrId, IndexT rowIndex, const Math::vec4& val);
162 Math::vec4 GetVec4(const Vec4AttrId& colAttrId, IndexT rowIndex) const;
164 void SetMat4(const Mat4AttrId& colAttrId, IndexT rowIndex, const Math::mat4& val);
166 Math::mat4 GetMat4(const Mat4AttrId& colAttrId, IndexT rowIndex) const;
168 void SetGuid(const GuidAttrId& colAttrId, IndexT rowIndex, const Util::Guid& guid);
170 const Util::Guid& GetGuid(const GuidAttrId& colAttrId, IndexT rowIndex) const;
172 void SetBlob(const BlobAttrId& colAttrId, IndexT rowIndex, const Util::Blob& blob);
174 const Util::Blob& GetBlob(const BlobAttrId& colAttrId, IndexT rowIndex) const;
175
177 void SetVariant(IndexT colIndex, IndexT rowIndex, const Util::Variant& val);
179 void SetBool(IndexT colIndex, IndexT rowIndex, bool val);
181 bool GetBool(IndexT colIndex, IndexT rowIndex) const;
183 void SetFloat(IndexT colIndex, IndexT rowIndex, float val);
185 float GetFloat(IndexT colIndex, IndexT rowIndex) const;
187 void SetInt(IndexT colIndex, IndexT rowIndex, int val);
189 int GetInt(IndexT colIndex, IndexT rowIndex) const;
191 void SetInt64(IndexT colIndex, IndexT rowIndex, int64_t val);
193 int64_t GetInt64(IndexT colIndex, IndexT rowIndex) const;
195 void SetUInt(IndexT colIndex, IndexT rowIndex, uint val);
197 uint GetUInt(IndexT colIndex, IndexT rowIndex) const;
199 void SetString(IndexT colIndex, IndexT rowIndex, const Util::String& val);
201 const Util::String& GetString(IndexT colIndex, IndexT rowIndex) const;
203 void SetVec4(IndexT colIndex, IndexT rowIndex, const Math::vec4& val);
205 Math::vec4 GetVec4(IndexT colIndex, IndexT rowIndex) const;
207 void SetMat4(IndexT colIndex, IndexT rowIndex, const Math::mat4& val);
209 Math::mat4 GetMat4(IndexT colIndex, IndexT rowIndex) const;
211 void SetGuid(IndexT colIndex, IndexT rowIndex, const Util::Guid& guid);
213 const Util::Guid& GetGuid(IndexT colIndex, IndexT rowIndex) const;
215 void SetBlob(IndexT colIndex, IndexT rowIndex, const Util::Blob& blob);
217 const Util::Blob& GetBlob(IndexT colIndex, IndexT rowIndex) const;
218
220 bool LoadXmlTable(const Util::String& fileName);
221
222private:
224 void Realloc(SizeT newPitch, SizeT newAllocRows);
228 SizeT GetValueTypeSize(ValueType type) const;
230 void* GetValuePtr(IndexT colIndex, IndexT rowIndex) const;
232 void Delete();
234 void DeleteRowData(IndexT rowIndex);
236 void DeleteString(IndexT colIndex, IndexT rowIndex);
238 void CopyString(IndexT colIndex, IndexT rowIndex, const Util::String& val);
240 void DeleteBlob(IndexT colIndex, IndexT rowIndex);
242 void CopyBlob(IndexT colIndex, IndexT rowIndex, const Util::Blob& val);
244 void DeleteGuid(IndexT colIndex, IndexT rowIndex);
246 void CopyGuid(IndexT colIndex, IndexT rowIndex, const Util::Guid& val);
248 Util::Array<IndexT> InternalFindRowIndicesByAttr(const Attr::Attribute& attr, bool firstMatchOnly) const;
252 void InternalAddColumnHelper(const AttrId& id, bool recordAsNewColumn);
253
255 void SetColumnToDefaultValues(IndexT colIndex);
257 void SetRowToDefaultValues(IndexT rowIndex);
258
260 void SetColumnBool(const BoolAttrId& attrId, bool val);
262 void SetColumnFloat(const FloatAttrId& attrId, float val);
264 void SetColumnInt(const IntAttrId& attrId, int val);
266 void SetColumnString(const StringAttrId& attrId, const Util::String& val);
268 void SetColumnVec4(const Vec4AttrId& attrId, const Math::vec4& val);
270 void SetColumnMat4(const Mat4AttrId& attrId, const Math::mat4& val);
272 void SetColumnGuid(const GuidAttrId& attrId, const Util::Guid& guid);
274 void SetColumnBlob(const BlobAttrId& attrId, const Util::Blob& blob);
275
277 {
278 AttrId attrId; // attribute id of the column
279 IndexT byteOffset; // byte offset into a row
280 };
282 Util::Dictionary<AttrId,IndexT> indexMap; // map attribute id to column index
283 Util::Array<IndexT> readWriteColumnIndices; // indices of all columns that are read/writable
284 Util::Array<IndexT> newColumnIndices; // indices of new columns since last ResetModifiedState
285 Util::Array<IndexT> newRowIndices; // indices of new rows since last ResetModifiedState
286 Util::Array<IndexT> deletedRowIndices; // indices of rows that are marked for deletion
288 SizeT rowPitch; // pitch of a row in bytes
289 SizeT numRows; // number of rows
290 SizeT allocatedRows; // number of allocated rows
291 void* valueBuffer; // points to value buffer
292 uchar* rowModifiedBuffer; // 1 for a modified row, zero for not modified
293 uchar* rowDeletedBuffer; // 1 for a deleted row, zero for not deleted
294 uchar* rowNewBuffer; // 1 for a new row, zero for not new
295 bool trackModifications; // modified tracking on/off
296 bool isModified; // global modified flag
297 bool rowsModified; // return true if modified rows exist
298 bool inBeginAddColumns; // current inside BeginAddColumns()/EndAddColumns()
299 bool addColumnsRecordAsNewColumns; // recordAsNewColumns flag in BeginAddColumns
300 IndexT firstNewColumnIndex; // set in BeginAddColumns
301};
302
303//------------------------------------------------------------------------------
306inline
307void
312
313//------------------------------------------------------------------------------
316inline
317bool
319{
320 return this->trackModifications;
321}
322
323//------------------------------------------------------------------------------
326inline
327bool
329{
330 return this->newRowIndices.Size() > 0;
331}
332
333//------------------------------------------------------------------------------
336inline
337bool
339{
340 return this->deletedRowIndices.Size() > 0;
341}
342
343//------------------------------------------------------------------------------
346inline
347bool
349{
350 return this->rowsModified;
351}
352
353//------------------------------------------------------------------------------
356inline
362
363//------------------------------------------------------------------------------
367inline bool
369{
370 n_assert(rowIndex < this->numRows);
371 n_assert(0 != this->rowModifiedBuffer);
372 return (0 != this->rowModifiedBuffer[rowIndex]);
373}
374
375//------------------------------------------------------------------------------
379inline bool
381{
382 n_assert(rowIndex < this->numRows);
383 n_assert(0 != this->rowDeletedBuffer);
384 return (this->rowDeletedBuffer[rowIndex] == 1);
385}
386
387//------------------------------------------------------------------------------
390inline bool
392{
393 return this->isModified;
394}
395
396//------------------------------------------------------------------------------
399inline const Util::Array<IndexT>&
401{
402 return this->newRowIndices;
403}
404
405//------------------------------------------------------------------------------
408inline const Util::Array<IndexT>&
410{
411 return this->deletedRowIndices;
412}
413
414//------------------------------------------------------------------------------
417inline const Util::Array<IndexT>&
419{
420 return this->newColumnIndices;
421}
422
423//------------------------------------------------------------------------------
426inline bool
428{
429 return this->indexMap.Contains(id);
430}
431
432//------------------------------------------------------------------------------
435inline IndexT
437{
438 return this->indexMap[id];
439}
440
441//------------------------------------------------------------------------------
444inline SizeT
446{
447 return this->columns.Size();
448}
449
450//------------------------------------------------------------------------------
453inline const AttrId&
455{
456 return this->columns[colIndex].attrId;
457}
458
459//------------------------------------------------------------------------------
462inline const Util::String&
464{
465 return this->columns[colIndex].attrId.GetName();
466}
467
468//------------------------------------------------------------------------------
471inline const Util::FourCC&
473{
474 return this->columns[colIndex].attrId.GetFourCC();
475}
476
477//------------------------------------------------------------------------------
480inline AccessMode
482{
483 return this->columns[colIndex].attrId.GetAccessMode();
484}
485
486//------------------------------------------------------------------------------
489inline ValueType
491{
492 return this->columns[colIndex].attrId.GetValueType();
493}
494
495//------------------------------------------------------------------------------
498inline SizeT
500{
501 return this->numRows;
502}
503
504//------------------------------------------------------------------------------
508inline void*
510{
511 n_assert((colIndex < this->columns.Size()) && (rowIndex < this->numRows));
512 IndexT bufferOffset = (rowIndex * this->rowPitch) + this->columns[colIndex].byteOffset;
513 return (void*)((char*)this->valueBuffer + bufferOffset);
514}
515
516//------------------------------------------------------------------------------
519inline void
520AttributeTable::SetBool(IndexT colIndex, IndexT rowIndex, bool val)
521{
522 n_assert(this->GetColumnValueType(colIndex) == BoolType);
523 n_assert(!this->IsRowDeleted(rowIndex));
524 int* valuePtr = (int*) this->GetValuePtr(colIndex, rowIndex);
525 *valuePtr = val ? 1 : 0;
526 this->rowModifiedBuffer[rowIndex] = 1;
527 this->isModified = true;
528}
529
530//------------------------------------------------------------------------------
533inline bool
534AttributeTable::GetBool(IndexT colIndex, IndexT rowIndex) const
535{
536 n_assert(this->GetColumnValueType(colIndex) == BoolType);
537 int* valuePtr = (int*) this->GetValuePtr(colIndex, rowIndex);
538 return (*valuePtr != 0);
539}
540
541//------------------------------------------------------------------------------
544inline void
545AttributeTable::SetFloat(IndexT colIndex, IndexT rowIndex, float val)
546{
547 n_assert(this->GetColumnValueType(colIndex) == FloatType);
548 n_assert(!this->IsRowDeleted(rowIndex));
549 float* valuePtr = (float*) this->GetValuePtr(colIndex, rowIndex);
550 *valuePtr = val;
551 this->rowModifiedBuffer[rowIndex] = 1;
552 this->isModified = true;
553}
554
555//------------------------------------------------------------------------------
558inline float
559AttributeTable::GetFloat(IndexT colIndex, IndexT rowIndex) const
560{
561 n_assert(this->GetColumnValueType(colIndex) == FloatType);
562 float* valuePtr = (float*) this->GetValuePtr(colIndex, rowIndex);
563 return *valuePtr;
564}
565
566//------------------------------------------------------------------------------
569inline void
570AttributeTable::SetInt(IndexT colIndex, IndexT rowIndex, int val)
571{
572 n_assert(this->GetColumnValueType(colIndex) == IntType);
573 n_assert(!this->IsRowDeleted(rowIndex));
574 int* valuePtr = (int*) this->GetValuePtr(colIndex, rowIndex);
575 *valuePtr = val;
576 this->rowModifiedBuffer[rowIndex] = 1;
577 this->isModified = true;
578}
579
580//------------------------------------------------------------------------------
583inline int
584AttributeTable::GetInt(IndexT colIndex, IndexT rowIndex) const
585{
586 n_assert(this->GetColumnValueType(colIndex) == IntType);
587 int* valuePtr = (int*) this->GetValuePtr(colIndex, rowIndex);
588 return *valuePtr;
589}
590
591//------------------------------------------------------------------------------
594inline void
595AttributeTable::SetInt64(IndexT colIndex, IndexT rowIndex, int64_t val)
596{
597 n_assert(this->GetColumnValueType(colIndex) == Int64Type);
598 n_assert(!this->IsRowDeleted(rowIndex));
599 int64_t* valuePtr = (int64_t*) this->GetValuePtr(colIndex, rowIndex);
600 *valuePtr = val;
601 this->rowModifiedBuffer[rowIndex] = 1;
602 this->isModified = true;
603}
604
605//------------------------------------------------------------------------------
608inline int64_t
609AttributeTable::GetInt64(IndexT colIndex, IndexT rowIndex) const
610{
611 n_assert(this->GetColumnValueType(colIndex) == Int64Type);
612 int64_t* valuePtr = (int64_t*) this->GetValuePtr(colIndex, rowIndex);
613 return *valuePtr;
614}
615
616//------------------------------------------------------------------------------
619inline void
621{
622 n_assert(this->GetColumnValueType(colIndex) == UIntType);
623 n_assert(!this->IsRowDeleted(rowIndex));
624 uint* valuePtr = (uint*)this->GetValuePtr(colIndex, rowIndex);
625 *valuePtr = val;
626 this->rowModifiedBuffer[rowIndex] = 1;
627 this->isModified = true;
628}
629
630//------------------------------------------------------------------------------
633inline uint
634AttributeTable::GetUInt(IndexT colIndex, IndexT rowIndex) const
635{
636 n_assert(this->GetColumnValueType(colIndex) == UIntType);
637 uint* valuePtr = (uint*)this->GetValuePtr(colIndex, rowIndex);
638 return *valuePtr;
639}
640
641//------------------------------------------------------------------------------
644inline void
645AttributeTable::SetVec4(IndexT colIndex, IndexT rowIndex, const Math::vec4& val)
646{
647 n_assert(this->GetColumnValueType(colIndex) == Vec4Type);
648 n_assert(!this->IsRowDeleted(rowIndex));
649 Math::scalar* valuePtr = (Math::scalar*) this->GetValuePtr(colIndex, rowIndex);
650 val.storeu(valuePtr);
651 if (this->trackModifications)
652 {
653 this->rowModifiedBuffer[rowIndex] = 1;
654 this->isModified = true;
655 this->rowsModified = true;
656 }
657}
658
659//------------------------------------------------------------------------------
662inline Math::vec4
663AttributeTable::GetVec4(IndexT colIndex, IndexT rowIndex) const
664{
665 n_assert(this->GetColumnValueType(colIndex) == Vec4Type);
666 Math::scalar* valuePtr = (Math::scalar*) this->GetValuePtr(colIndex, rowIndex);
667 Math::vec4 vec;
668 vec.loadu(valuePtr);
669 return vec;
670}
671
672//------------------------------------------------------------------------------
675inline void
676AttributeTable::SetMat4(IndexT colIndex, IndexT rowIndex, const Math::mat4& val)
677{
678 n_assert(this->GetColumnValueType(colIndex) == Mat4Type);
679 n_assert(!this->IsRowDeleted(rowIndex));
680 Math::scalar* valuePtr = (Math::scalar*) this->GetValuePtr(colIndex, rowIndex);
681 val.storeu(valuePtr);
682 if (this->trackModifications)
683 {
684 this->rowModifiedBuffer[rowIndex] = 1;
685 this->isModified = true;
686 this->rowsModified = true;
687 }
688}
689
690//------------------------------------------------------------------------------
693inline Math::mat4
694AttributeTable::GetMat4(IndexT colIndex, IndexT rowIndex) const
695{
696 n_assert(this->GetColumnValueType(colIndex) == Mat4Type);
697 Math::scalar* valuePtr = (Math::scalar*) this->GetValuePtr(colIndex, rowIndex);
698 Math::mat4 mx;
699 mx.loadu(valuePtr);
700 return mx;
701}
702
703//------------------------------------------------------------------------------
706inline void
708{
709 n_assert(this->GetColumnValueType(colIndex) == StringType);
710 n_assert(!this->IsRowDeleted(rowIndex));
711 this->CopyString(colIndex, rowIndex, val);
712 if (this->trackModifications)
713 {
714 this->rowModifiedBuffer[rowIndex] = 1;
715 this->isModified = true;
716 this->rowsModified = true;
717 }
718}
719
720//------------------------------------------------------------------------------
723inline const Util::String&
724AttributeTable::GetString(IndexT colIndex, IndexT rowIndex) const
725{
726 n_assert(this->GetColumnValueType(colIndex) == StringType);
727 Util::String** valuePtr = (Util::String**) this->GetValuePtr(colIndex, rowIndex);
728 return **valuePtr;
729}
730
731//------------------------------------------------------------------------------
734inline void
735AttributeTable::SetGuid(IndexT colIndex, IndexT rowIndex, const Util::Guid& val)
736{
737 n_assert(this->GetColumnValueType(colIndex) == GuidType);
738 n_assert(!this->IsRowDeleted(rowIndex));
739 this->CopyGuid(colIndex, rowIndex, val);
740 if (this->trackModifications)
741 {
742 this->rowModifiedBuffer[rowIndex] = 1;
743 this->isModified = true;
744 this->rowsModified = true;
745 }
746}
747
748//------------------------------------------------------------------------------
751inline const Util::Guid&
752AttributeTable::GetGuid(IndexT colIndex, IndexT rowIndex) const
753{
754 n_assert(this->GetColumnValueType(colIndex) == GuidType);
755 Util::Guid** valuePtr = (Util::Guid**) this->GetValuePtr(colIndex, rowIndex);
756 return **valuePtr;
757}
758
759//------------------------------------------------------------------------------
762inline void
763AttributeTable::SetBlob(IndexT colIndex, IndexT rowIndex, const Util::Blob& val)
764{
765 n_assert(this->GetColumnValueType(colIndex) == BlobType);
766 n_assert(!this->IsRowDeleted(rowIndex));
767 this->CopyBlob(colIndex, rowIndex, val);
768 if (this->trackModifications)
769 {
770 this->rowModifiedBuffer[rowIndex] = 1;
771 this->isModified = true;
772 this->rowsModified = true;
773 }
774}
775
776//------------------------------------------------------------------------------
779inline const Util::Blob&
780AttributeTable::GetBlob(IndexT colIndex, IndexT rowIndex) const
781{
782 n_assert(this->GetColumnValueType(colIndex) == BlobType);
783 Util::Blob** valuePtr = (Util::Blob**) this->GetValuePtr(colIndex, rowIndex);
784 return **valuePtr;
785}
786
787//------------------------------------------------------------------------------
790inline void
791AttributeTable::SetBool(const BoolAttrId& colAttrId, IndexT rowIndex, bool val)
792{
793 this->SetBool(this->indexMap[colAttrId], rowIndex, val);
794}
795
796//------------------------------------------------------------------------------
799inline bool
800AttributeTable::GetBool(const BoolAttrId& colAttrId, IndexT rowIndex) const
801{
802 return this->GetBool(this->indexMap[colAttrId], rowIndex);
803}
804
805//------------------------------------------------------------------------------
808inline void
809AttributeTable::SetFloat(const FloatAttrId& colAttrId, IndexT rowIndex, float val)
810{
811 this->SetFloat(this->indexMap[colAttrId], rowIndex, val);
812}
813
814//------------------------------------------------------------------------------
817inline float
818AttributeTable::GetFloat(const FloatAttrId& colAttrId, IndexT rowIndex) const
819{
820 return this->GetFloat(this->indexMap[colAttrId], rowIndex);
821}
822
823//------------------------------------------------------------------------------
826inline void
827AttributeTable::SetInt(const IntAttrId& colAttrId, IndexT rowIndex, int val)
828{
829 this->SetInt(this->indexMap[colAttrId], rowIndex, val);
830}
831
832//------------------------------------------------------------------------------
835inline int
836AttributeTable::GetInt(const IntAttrId& colAttrId, IndexT rowIndex) const
837{
838 return this->GetInt(this->indexMap[colAttrId], rowIndex);
839}
840
841//------------------------------------------------------------------------------
844inline void
845AttributeTable::SetInt64(const Int64AttrId& colAttrId, IndexT rowIndex, int64_t val)
846{
847 this->SetInt64(this->indexMap[colAttrId], rowIndex, val);
848}
849
850//------------------------------------------------------------------------------
853inline int64_t
854AttributeTable::GetInt64(const Int64AttrId& colAttrId, IndexT rowIndex) const
855{
856 return this->GetInt64(this->indexMap[colAttrId], rowIndex);
857}
858
859//------------------------------------------------------------------------------
862inline void
863AttributeTable::SetVec4(const Vec4AttrId& colAttrId, IndexT rowIndex, const Math::vec4& val)
864{
865 this->SetVec4(this->indexMap[colAttrId], rowIndex, val);
866}
867
868//------------------------------------------------------------------------------
871inline Math::vec4
872AttributeTable::GetVec4(const Vec4AttrId& colAttrId, IndexT rowIndex) const
873{
874 return this->GetVec4(this->indexMap[colAttrId], rowIndex);
875}
876
877//------------------------------------------------------------------------------
880inline void
881AttributeTable::SetMat4(const Mat4AttrId& colAttrId, IndexT rowIndex, const Math::mat4& val)
882{
883 this->SetMat4(this->indexMap[colAttrId], rowIndex, val);
884}
885
886//------------------------------------------------------------------------------
889inline Math::mat4
890AttributeTable::GetMat4(const Mat4AttrId& colAttrId, IndexT rowIndex) const
891{
892 return this->GetMat4(this->indexMap[colAttrId], rowIndex);
893}
894
895//------------------------------------------------------------------------------
898inline void
899AttributeTable::SetString(const StringAttrId& colAttrId, IndexT rowIndex, const Util::String& val)
900{
901 this->SetString(this->indexMap[colAttrId], rowIndex, val);
902}
903
904//------------------------------------------------------------------------------
907inline const Util::String&
908AttributeTable::GetString(const StringAttrId& colAttrId, IndexT rowIndex) const
909{
910 return this->GetString(this->indexMap[colAttrId], rowIndex);
911}
912
913//------------------------------------------------------------------------------
916inline void
917AttributeTable::SetGuid(const GuidAttrId& colAttrId, IndexT rowIndex, const Util::Guid& val)
918{
919 this->SetGuid(this->indexMap[colAttrId], rowIndex, val);
920}
921
922//------------------------------------------------------------------------------
925inline const Util::Guid&
926AttributeTable::GetGuid(const GuidAttrId& colAttrId, IndexT rowIndex) const
927{
928 return this->GetGuid(this->indexMap[colAttrId], rowIndex);
929}
930
931//------------------------------------------------------------------------------
934inline void
935AttributeTable::SetBlob(const BlobAttrId& colAttrId, IndexT rowIndex, const Util::Blob& val)
936{
937 this->SetBlob(this->indexMap[colAttrId], rowIndex, val);
938}
939
940//------------------------------------------------------------------------------
943inline const Util::Blob&
944AttributeTable::GetBlob(const BlobAttrId& colAttrId, IndexT rowIndex) const
945{
946 return this->GetBlob(this->indexMap[colAttrId], rowIndex);
947}
948
949} // namespace Db
950//------------------------------------------------------------------------------
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:33
int64_t GetInt64(const Int64AttrId &colAttrId, IndexT rowIndex) const
get int64 value
Definition attributetable.h:854
void ReserveRows(SizeT numRows)
reserve rows to reduce re-allocation overhead
Definition attributetable.cc:711
void SetRowToDefaultValues(IndexT rowIndex)
set a row to its default values
Definition attributetable.cc:1085
IndexT CopyRow(IndexT rowIndex)
create a new row as copy of another row
Definition attributetable.cc:571
SizeT allocatedRows
Definition attributetable.h:290
SizeT GetNumRows() const
get number of rows in table
Definition attributetable.h:499
void BeginAddColumns(bool recordNewColumns=true)
optional: call before adding columns, speeds up adding many columns at once
Definition attributetable.cc:411
ValueType GetColumnValueType(IndexT colIndex) const
get a column's value type
Definition attributetable.h:490
IndexT FindRowIndexByAttr(const Attribute &attr) const
find all matching row indices by attribute value
Definition attributetable.cc:1030
bool HasDeletedRows() const
return true if table has deleted rows
Definition attributetable.h:338
AttributeTable()
constructor
Definition attributetable.cc:19
IndexT GetColumnIndex(const AttrId &id) const
return index of column by id
Definition attributetable.h:436
bool HasNewRows() const
return true if table has new rows
Definition attributetable.h:328
Util::Array< IndexT > GetModifiedRowsExcludeNewAndDeletedRows() const
return array of modified rows, exclude rows marked as rows
Definition attributetable.cc:1283
bool addColumnsRecordAsNewColumns
Definition attributetable.h:299
void InternalAddColumnHelper(const AttrId &id, bool recordAsNewColumn)
internal helper method for adding a column
Definition attributetable.cc:425
uchar * rowDeletedBuffer
Definition attributetable.h:293
void SetBlob(const BlobAttrId &colAttrId, IndexT rowIndex, const Util::Blob &blob)
set blob value
Definition attributetable.h:935
void DeleteAllRows()
mark all rows as deleted
Definition attributetable.cc:555
void SetBool(const BoolAttrId &colAttrId, IndexT rowIndex, bool val)
set bool value
Definition attributetable.h:791
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:308
Math::mat4 GetMat4(const Mat4AttrId &colAttrId, IndexT rowIndex) const
get mat4 value
Definition attributetable.h:890
void DeleteString(IndexT colIndex, IndexT rowIndex)
delete a string from the table
Definition attributetable.cc:116
bool trackModifications
Definition attributetable.h:295
const Util::Array< IndexT > & GetReadWriteColumnIndices() const
return indices of all ReadWrite columns
Definition attributetable.h:358
void * GetRowUserData(IndexT rowIndex) const
get optional row user data pointer
Definition attributetable.cc:1075
Attr::Attribute GetAttr(IndexT rowIndex, IndexT colIndex) const
get a generic attribute
Definition attributetable.cc:1257
void SetColumnToDefaultValues(IndexT colIndex)
set entire column to its default values
Definition attributetable.cc:1115
SizeT UpdateColumnOffsets()
update the column byte offset and return new pitch
Definition attributetable.cc:388
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:298
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:641
uchar * rowModifiedBuffer
Definition attributetable.h:292
SizeT rowPitch
Definition attributetable.h:288
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:863
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:777
Util::Dictionary< AttrId, IndexT > indexMap
Definition attributetable.h:282
virtual ~AttributeTable()
destructor
Definition attributetable.cc:59
IndexT AddRow()
add a row to the table, returns index of new row
Definition attributetable.cc:728
const Util::Blob & GetBlob(const BlobAttrId &colAttrId, IndexT rowIndex) const
get blob value
Definition attributetable.h:944
bool HasModifiedRows() const
return true if table has modified rows
Definition attributetable.h:348
uint GetUInt(IndexT colIndex, IndexT rowIndex) const
get uint value by column index
Definition attributetable.h:634
bool HasColumn(const AttrId &id) const
return true if a column exists
Definition attributetable.h:427
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:368
IndexT firstNewColumnIndex
Definition attributetable.h:300
const Util::Array< IndexT > & GetDeletedRowIndices() const
return indices of rows deleted since the last ResetModifiedState()
Definition attributetable.h:409
IndexT FindRowIndexByAttrs(const Util::Array< Attribute > &attrs) const
find all matching row indices by multiple attribute values
Definition attributetable.cc:1049
bool GetBool(const BoolAttrId &colAttrId, IndexT rowIndex) const
get bool value
Definition attributetable.h:800
Util::Array< IndexT > deletedRowIndices
Definition attributetable.h:286
Util::Array< IndexT > FindRowIndicesByAttr(const Attribute &attr, bool firstMatchOnly) const
find all matching row indices by attribute value
Definition attributetable.cc:1008
const AttrId & GetColumnId(IndexT colIndex) const
get column definition at index
Definition attributetable.h:454
void DeleteRow(IndexT rowIndex)
mark a row as deleted from the table
Definition attributetable.cc:532
Math::vec4 GetVec4(const Vec4AttrId &colAttrId, IndexT rowIndex) const
get float4 value
Definition attributetable.h:872
Util::Array< IndexT > InternalFindRowIndicesByAttrs(const Util::Array< Attr::Attribute > &attr, bool firstMatchOnly) const
internal row-indices-by-multiple-attrs find method
Definition attributetable.cc:802
const Util::Guid & GetGuid(const GuidAttrId &colAttrId, IndexT rowIndex) const
get guid value
Definition attributetable.h:926
void SetInt(const IntAttrId &colAttrId, IndexT rowIndex, int val)
set int value
Definition attributetable.h:827
Util::Array< IndexT > newColumnIndices
Definition attributetable.h:284
void PrintDebug()
print the contents of the table for debugging reasons
Definition attributetable.cc:1304
void SetMat4(const Mat4AttrId &colAttrId, IndexT rowIndex, const Math::mat4 &val)
set mat4 value
Definition attributetable.h:881
void SetInt64(const Int64AttrId &colAttrId, IndexT rowIndex, int64_t val)
set int64 value
Definition attributetable.h:845
void SetVariant(const Attr::AttrId &attrId, IndexT rowIndex, const Util::Variant &val)
set variant value
Definition attributetable.cc:1347
void SetGuid(const GuidAttrId &colAttrId, IndexT rowIndex, const Util::Guid &guid)
set guid value
Definition attributetable.h:917
void SetString(const StringAttrId &colAttrId, IndexT rowIndex, const Util::String &val)
set string value
Definition attributetable.h:899
const Util::Array< IndexT > & GetNewColumnIndices() const
return indices of columns added since the last ResetModifiedState()
Definition attributetable.h:418
void * GetValuePtr(IndexT colIndex, IndexT rowIndex) const
returns pointer to a value's memory location
Definition attributetable.h:509
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:459
void SetColumnInt(const IntAttrId &attrId, int val)
set entire column to int value
bool rowsModified
Definition attributetable.h:297
void SetFloat(const FloatAttrId &colAttrId, IndexT rowIndex, float val)
set float value
Definition attributetable.h:809
bool isModified
Definition attributetable.h:296
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:472
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:391
void DeleteRowData(IndexT rowIndex)
delete row data, frees all memory used in one row
Definition attributetable.cc:1404
void SetUInt(IndexT colIndex, IndexT rowIndex, uint val)
set uint value by column index
Definition attributetable.h:620
const Util::Array< IndexT > & GetNewRowIndices() const
return indices of rows added since the last ResetModfiedState()
Definition attributetable.h:400
bool GetModifiedTracking() const
get modified tracking flag
Definition attributetable.h:318
void * valueBuffer
Definition attributetable.h:291
Util::Array< IndexT > readWriteColumnIndices
Definition attributetable.h:283
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:287
AccessMode GetColumnAccessMode(IndexT colIndex) const
get a column's access mode
Definition attributetable.h:481
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:836
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:910
void AddColumn(const AttrId &id, bool recordNewColumn=true)
add a column
Definition attributetable.cc:497
void ClearDeletedRowsFlags()
clear deleted rows flags
Definition attributetable.cc:788
void SetAttr(const Attr::Attribute &attr, IndexT rowIndex)
set a generic attribute (slow!)
Definition attributetable.cc:1232
void SetRowUserData(IndexT rowIndex, void *p)
set an optional row user data pointer
Definition attributetable.cc:1066
bool IsRowDeleted(IndexT rowIndex) const
return true if row has been marked as deleted
Definition attributetable.h:380
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:908
SizeT GetNumColumns() const
get number of columns
Definition attributetable.h:445
void SetColumnBlob(const BlobAttrId &attrId, const Util::Blob &blob)
set entire column to blob value
uchar * rowNewBuffer
Definition attributetable.h:294
SizeT numRows
Definition attributetable.h:289
Util::Array< IndexT > FindRowIndicesByAttrs(const Util::Array< Attribute > &attrs, bool firstMatchOnly) const
find all matching row indices by multiple attribute values
Definition attributetable.cc:1019
void SetColumnFloat(const FloatAttrId &attrId, float val)
set entire column float value
Util::Array< ColumnInfo > columns
Definition attributetable.h:281
Util::Array< IndexT > newRowIndices
Definition attributetable.h:285
float GetFloat(const FloatAttrId &colAttrId, IndexT rowIndex) const
get float value
Definition attributetable.h:818
const Util::String & GetColumnName(IndexT colIndex) const
get a column's name
Definition attributetable.h:463
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
Definition intattrid.h:97
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
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
An "any type" variable.
Definition variant.h:32
#define n_assert(exp)
Definition debug.h:50
Definition accessmode.h:13
ValueType
Definition valuetype.h:20
@ Vec4Type
Definition valuetype.h:32
@ IntType
Definition valuetype.h:25
@ FloatType
Definition valuetype.h:28
@ Mat4Type
Definition valuetype.h:35
@ BoolType
Definition valuetype.h:30
@ Int64Type
Definition valuetype.h:27
@ StringType
Definition valuetype.h:34
@ BlobType
Definition valuetype.h:37
@ UIntType
Definition valuetype.h:26
@ GuidType
Definition valuetype.h:38
AccessMode
Definition accessmode.h:15
float scalar
Definition scalar.h:45
Definition attributetable.h:277
IndexT byteOffset
Definition attributetable.h:279
AttrId attrId
Definition attributetable.h:278
A 4x4 single point precision float matrix.
Definition mat4.h:49
void loadu(const scalar *ptr)
load content from unaligned memory
Definition mat4.h:244
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition mat4.h:279
A 4D vector.
Definition vec4.h:24
void loadu(const scalar *ptr)
load content from unaligned memory
Definition vec4.h:183
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition vec4.h:203
Nebula's universal string class.
Definition String.cs:8
unsigned char uchar
Definition types.h:35
int SizeT
Definition types.h:42
unsigned int uint
Definition types.h:33
int IndexT
Definition types.h:41