mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0031255: Foundation Classes - NCollection_IndexedDataMap should implement random stl iterator
This commit is contained in:
@@ -98,9 +98,10 @@ private:
|
|||||||
myIndex (0) {}
|
myIndex (0) {}
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
Iterator (const NCollection_IndexedDataMap& theMap)
|
Iterator (const NCollection_IndexedDataMap& theMap,
|
||||||
|
Standard_Boolean theToEnd = Standard_False)
|
||||||
: myMap ((NCollection_IndexedDataMap*)&theMap),
|
: myMap ((NCollection_IndexedDataMap*)&theMap),
|
||||||
myIndex (1) {}
|
myIndex (theToEnd ? theMap.Extent() + 1 : 1) {}
|
||||||
|
|
||||||
//! Query if the end of collection is reached by iterator
|
//! Query if the end of collection is reached by iterator
|
||||||
Standard_Boolean More(void) const
|
Standard_Boolean More(void) const
|
||||||
@@ -110,6 +111,37 @@ private:
|
|||||||
void Next(void)
|
void Next(void)
|
||||||
{ ++myIndex; }
|
{ ++myIndex; }
|
||||||
|
|
||||||
|
//! Query if it is possible decrementing iterator position.
|
||||||
|
Standard_Boolean HasPrevious() const
|
||||||
|
{
|
||||||
|
return myMap != NULL
|
||||||
|
&& myIndex > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Decrement operator.
|
||||||
|
void Previous()
|
||||||
|
{
|
||||||
|
--myIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Offset operator.
|
||||||
|
void Offset (ptrdiff_t theOffset)
|
||||||
|
{
|
||||||
|
myIndex += static_cast<int>(theOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Difference operator.
|
||||||
|
ptrdiff_t Differ (const Iterator& theOther) const
|
||||||
|
{
|
||||||
|
return myIndex - theOther.myIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Value index access
|
||||||
|
Standard_Integer Index() const
|
||||||
|
{
|
||||||
|
return myIndex;
|
||||||
|
}
|
||||||
|
|
||||||
//! Value access
|
//! Value access
|
||||||
const TheItemType& Value(void) const
|
const TheItemType& Value(void) const
|
||||||
{
|
{
|
||||||
@@ -144,22 +176,22 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
//! Shorthand for a regular iterator type.
|
//! Shorthand for a regular iterator type.
|
||||||
typedef NCollection_StlIterator<std::forward_iterator_tag, Iterator, TheItemType, false> iterator;
|
typedef NCollection_StlIterator<std::random_access_iterator_tag, Iterator, TheItemType, false> iterator;
|
||||||
|
|
||||||
//! Shorthand for a constant iterator type.
|
//! Shorthand for a constant iterator type.
|
||||||
typedef NCollection_StlIterator<std::forward_iterator_tag, Iterator, TheItemType, true> const_iterator;
|
typedef NCollection_StlIterator<std::random_access_iterator_tag, Iterator, TheItemType, true> const_iterator;
|
||||||
|
|
||||||
//! Returns an iterator pointing to the first element in the map.
|
//! Returns an iterator pointing to the first element in the map.
|
||||||
iterator begin() const { return Iterator (*this); }
|
iterator begin() const { return Iterator (*this, false); }
|
||||||
|
|
||||||
//! Returns an iterator referring to the past-the-end element in the map.
|
//! Returns an iterator referring to the past-the-end element in the map.
|
||||||
iterator end() const { return Iterator(); }
|
iterator end() const { return Iterator (*this, true); }
|
||||||
|
|
||||||
//! Returns a const iterator pointing to the first element in the map.
|
//! Returns a const iterator pointing to the first element in the map.
|
||||||
const_iterator cbegin() const { return Iterator (*this); }
|
const_iterator cbegin() const { return Iterator (*this, false); }
|
||||||
|
|
||||||
//! Returns a const iterator referring to the past-the-end element in the map.
|
//! Returns a const iterator referring to the past-the-end element in the map.
|
||||||
const_iterator cend() const { return Iterator(); }
|
const_iterator cend() const { return Iterator (*this, true); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// ---------- PUBLIC METHODS ------------
|
// ---------- PUBLIC METHODS ------------
|
||||||
|
Reference in New Issue
Block a user