File indexing completed on 2026-10-04 09:15:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef NCollection_SparseArray_HeaderFile
0017 #define NCollection_SparseArray_HeaderFile
0018
0019 #include <NCollection_SparseArrayBase.hxx>
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 template <class TheItemType>
0047 class NCollection_SparseArray : public NCollection_SparseArrayBase
0048 {
0049 public:
0050
0051 explicit NCollection_SparseArray(size_t theIncrement) noexcept
0052 : NCollection_SparseArrayBase(sizeof(TheItemType), theIncrement, destroyItemImpl)
0053 {
0054 }
0055
0056
0057 NCollection_SparseArray& Assign(const NCollection_SparseArray& theOther)
0058 {
0059 if (this == &theOther)
0060 return *this;
0061 this->assign(theOther, createItemImpl, destroyItemImpl, copyItemImpl);
0062 return *this;
0063 }
0064
0065
0066
0067
0068 void Exchange(NCollection_SparseArray& theOther) noexcept { this->exchange(theOther); }
0069
0070
0071 void Clear() { clearItems(destroyItemImpl); }
0072
0073 public:
0074
0075
0076
0077
0078 const TheItemType& Value(const size_t theIndex) const
0079 {
0080 return *(const TheItemType*)this->getValue(theIndex);
0081 }
0082
0083
0084 const TheItemType& operator()(const size_t theIndex) const { return Value(theIndex); }
0085
0086
0087 TheItemType& ChangeValue(const size_t theIndex)
0088 {
0089 return *(TheItemType*)(this->getValue(theIndex));
0090 }
0091
0092
0093 TheItemType& operator()(const size_t theIndex) { return ChangeValue(theIndex); }
0094
0095
0096 TheItemType& SetValue(const size_t theIndex, const TheItemType& theValue)
0097 {
0098 return *(TheItemType*)this->setValue(theIndex, (void*)&theValue, createItemImpl, copyItemImpl);
0099 }
0100
0101
0102
0103 bool UnsetValue(const size_t theIndex) { return this->unsetValue(theIndex, destroyItemImpl); }
0104
0105
0106
0107 public:
0108
0109
0110
0111
0112 size_t Extent() const noexcept { return Size(); }
0113
0114
0115 bool IsEmpty() const noexcept { return Size() == 0; }
0116
0117
0118 const TheItemType& Find(const size_t theIndex) const { return Value(theIndex); }
0119
0120
0121 TheItemType& ChangeFind(const size_t theIndex) { return ChangeValue(theIndex); }
0122
0123
0124 TheItemType& Bind(const size_t theIndex, const TheItemType& theValue)
0125 {
0126 return SetValue(theIndex, theValue);
0127 }
0128
0129
0130 bool IsBound(const size_t theIndex) const { return this->HasValue(theIndex); }
0131
0132
0133 bool UnBind(const size_t theIndex) { return UnsetValue(theIndex); }
0134
0135
0136
0137 public:
0138
0139
0140
0141
0142
0143 class ConstIterator : public NCollection_SparseArrayBase::Iterator
0144 {
0145 public:
0146
0147 ConstIterator() noexcept = default;
0148
0149
0150 ConstIterator(const NCollection_SparseArray& theVector)
0151 : NCollection_SparseArrayBase::Iterator(&theVector)
0152 {
0153 }
0154
0155
0156 void Init(const NCollection_SparseArray& theVector) { this->init(&theVector); }
0157
0158
0159 const TheItemType& Value() const { return *(const TheItemType*)this->value(); }
0160
0161
0162 const TheItemType& operator()() const { return *(const TheItemType*)this->value(); }
0163
0164
0165 size_t Key() const noexcept { return Index(); }
0166 };
0167
0168
0169
0170
0171 class Iterator : public ConstIterator
0172 {
0173 public:
0174
0175 Iterator() noexcept = default;
0176
0177
0178 Iterator(NCollection_SparseArray& theVector)
0179 : ConstIterator(theVector)
0180 {
0181 }
0182
0183
0184 void Init(const NCollection_SparseArray& theVector) { this->init(&theVector); }
0185
0186
0187 TheItemType& ChangeValue() { return *(TheItemType*)this->value(); }
0188
0189
0190 TheItemType& operator()() { return *(TheItemType*)this->value(); }
0191
0192
0193 const TheItemType& operator()() const { return *(const TheItemType*)this->value(); }
0194 };
0195
0196 private:
0197
0198
0199
0200 static void createItemImpl(void* theAddress, void* theOther)
0201 {
0202 new (theAddress) TheItemType(*(const TheItemType*)theOther);
0203 }
0204
0205
0206 static void destroyItemImpl(void* theAddress)
0207 {
0208 ((TheItemType*)theAddress)->TheItemType::~TheItemType();
0209 }
0210
0211
0212 static void copyItemImpl(void* theAddress, void* theOther)
0213 {
0214 (*(TheItemType*)theAddress) = *(const TheItemType*)theOther;
0215 }
0216 };
0217
0218 #endif