File indexing completed on 2026-05-04 08:45:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef NCollection_IndexedIterator_HeaderFile
0015 #define NCollection_IndexedIterator_HeaderFile
0016
0017 #include <Standard_Assert.hxx>
0018 #include <iterator>
0019
0020
0021
0022
0023
0024
0025
0026 template <class Category, class BaseIndexedMap, class ItemType, bool IsConstant>
0027 class NCollection_IndexedIterator
0028 {
0029 public:
0030
0031 using iterator_category = Category;
0032 using value_type = ItemType;
0033 using difference_type = ptrdiff_t;
0034 using pointer = typename std::conditional<IsConstant, const ItemType*, ItemType*>::type;
0035 using reference = typename std::conditional<IsConstant, const ItemType&, ItemType&>::type;
0036
0037
0038 NCollection_IndexedIterator()
0039 : myIndex(0),
0040 myIndexedMap(nullptr)
0041 {
0042 }
0043
0044
0045 NCollection_IndexedIterator(const BaseIndexedMap& theMap)
0046 : myIndex(0),
0047 myIndexedMap((&const_cast<BaseIndexedMap&>(theMap)))
0048 {
0049 }
0050
0051
0052 NCollection_IndexedIterator(const size_t theIndex, const BaseIndexedMap& theMap)
0053 : myIndex(theIndex),
0054 myIndexedMap(&const_cast<BaseIndexedMap&>(theMap))
0055 {
0056 }
0057
0058
0059 NCollection_IndexedIterator(
0060 const NCollection_IndexedIterator<Category, BaseIndexedMap, ItemType, false>& theOther)
0061 : myIndex(theOther.myIndex),
0062 myIndexedMap(theOther.myIndexedMap)
0063 {
0064 }
0065
0066
0067 NCollection_IndexedIterator& operator=(
0068 const NCollection_IndexedIterator<Category, BaseIndexedMap, ItemType, false>& theOther)
0069 {
0070 myIndex = theOther.myIndex;
0071 myIndexedMap = theOther.myIndexedMap;
0072 return *this;
0073 }
0074
0075 protected:
0076
0077
0078
0079 template <bool Condition>
0080 typename std::enable_if<!Condition, ItemType&>::type Reference() const
0081 {
0082 return myIndexedMap->at(myIndex);
0083 }
0084
0085 template <bool Condition>
0086 typename std::enable_if<Condition, const ItemType&>::type Reference() const
0087 {
0088 return myIndexedMap->at(myIndex);
0089 }
0090
0091 public:
0092
0093 bool operator==(const NCollection_IndexedIterator& theOther) const
0094 {
0095 return myIndexedMap == theOther.myIndexedMap && myIndex == theOther.myIndex;
0096 }
0097
0098 template <bool theOtherIsConstant>
0099 bool operator==(
0100 const NCollection_IndexedIterator<Category, BaseIndexedMap, ItemType, theOtherIsConstant>&
0101 theOther) const
0102 {
0103 return myIndexedMap == theOther.myIndexedMap && myIndex == theOther.myIndex;
0104 }
0105
0106 template <bool theOtherIsConstant>
0107 bool operator!=(
0108 const NCollection_IndexedIterator<Category, BaseIndexedMap, ItemType, theOtherIsConstant>&
0109 theOther) const
0110 {
0111 return myIndexedMap != theOther.myIndexedMap || myIndex != theOther.myIndex;
0112 }
0113
0114
0115 bool operator!=(const NCollection_IndexedIterator& theOther) const
0116 {
0117 return !(*this == theOther);
0118 }
0119
0120
0121 typename NCollection_IndexedIterator::reference operator*() const
0122 {
0123 return Reference<IsConstant>();
0124 }
0125
0126
0127 typename NCollection_IndexedIterator::pointer operator->() const
0128 {
0129 return &Reference<IsConstant>();
0130 }
0131
0132
0133 NCollection_IndexedIterator& operator++()
0134 {
0135 myIndex++;
0136 return *this;
0137 }
0138
0139
0140 NCollection_IndexedIterator operator++(int)
0141 {
0142 const NCollection_IndexedIterator theOld(*this);
0143 ++(*this);
0144 return theOld;
0145 }
0146
0147 public:
0148
0149 NCollection_IndexedIterator& operator--()
0150 {
0151 Standard_STATIC_ASSERT(
0152 (opencascade::std::is_same<std::bidirectional_iterator_tag, Category>::value
0153 || opencascade::std::is_same<std::random_access_iterator_tag, Category>::value));
0154 myIndex--;
0155 return *this;
0156 }
0157
0158
0159 NCollection_IndexedIterator operator--(int)
0160 {
0161 NCollection_IndexedIterator theOld(*this);
0162 --(*this);
0163 return theOld;
0164 }
0165
0166 public:
0167
0168 NCollection_IndexedIterator& operator+=(
0169 typename NCollection_IndexedIterator::difference_type theOffset)
0170 {
0171 Standard_STATIC_ASSERT(
0172 (opencascade::std::is_same<std::random_access_iterator_tag, Category>::value));
0173 myIndex += theOffset;
0174 return *this;
0175 }
0176
0177
0178 NCollection_IndexedIterator operator+(
0179 typename NCollection_IndexedIterator::difference_type theOffset) const
0180 {
0181 NCollection_IndexedIterator aTemp(*this);
0182 return aTemp += theOffset;
0183 }
0184
0185
0186 NCollection_IndexedIterator& operator-=(
0187 typename NCollection_IndexedIterator::difference_type theOffset)
0188 {
0189 return *this += -theOffset;
0190 }
0191
0192
0193 NCollection_IndexedIterator operator-(
0194 typename NCollection_IndexedIterator::difference_type theOffset) const
0195 {
0196 NCollection_IndexedIterator aTemp(*this);
0197 return aTemp += -theOffset;
0198 }
0199
0200
0201 typename NCollection_IndexedIterator::difference_type operator-(
0202 const NCollection_IndexedIterator& theOther) const
0203 {
0204 Standard_STATIC_ASSERT(
0205 (opencascade::std::is_same<std::random_access_iterator_tag, Category>::value));
0206 return myIndex - theOther.myIndex;
0207 }
0208
0209
0210 typename NCollection_IndexedIterator::reference operator[](
0211 typename NCollection_IndexedIterator::difference_type theOffset) const
0212 {
0213 return *(*this + theOffset);
0214 }
0215
0216
0217 bool operator<(const NCollection_IndexedIterator& theOther) const
0218 {
0219 return (*this - theOther) < 0;
0220 }
0221
0222
0223 bool operator>(const NCollection_IndexedIterator& theOther) const { return theOther < *this; }
0224
0225
0226 bool operator<=(const NCollection_IndexedIterator& theOther) const { return !(theOther < *this); }
0227
0228
0229 bool operator>=(const NCollection_IndexedIterator& theOther) const { return !(*this < theOther); }
0230
0231 friend class NCollection_IndexedIterator<Category, BaseIndexedMap, ItemType, !IsConstant>;
0232
0233 private:
0234
0235 size_t myIndex;
0236 BaseIndexedMap* myIndexedMap;
0237 };
0238
0239 #endif