1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-05-21 10:55:33 +03:00

0024831: Make iterators of NCollection classes STL-compatible

STL-compatible iterators returned methods begin() and end() are provided in collection classes from NCollection package.
NCollection_Array1::Iterator is redesigned to use pointer instead of index.
Iterators of Sequence, Array, and Vector are extended by new methods to iterate backwards.

Use of SortTools_QuickSortOfReal is replaced by std::sort() in a few places (where possible).
This commit is contained in:
dbp 2014-04-23 09:38:58 +04:00 committed by apn
parent 574d723693
commit 79a35943dd
25 changed files with 1988 additions and 173 deletions

View File

@ -22,9 +22,9 @@
#include <GeomFill_SnglrFunc.hxx> #include <GeomFill_SnglrFunc.hxx>
#include <Extrema_ExtPC.hxx> #include <Extrema_ExtPC.hxx>
#include <TColStd_HArray1OfBoolean.hxx> #include <TColStd_HArray1OfBoolean.hxx>
#include <SortTools_QuickSortOfReal.hxx>
#include <TCollection_CompareOfReal.hxx>
#include <TColgp_SequenceOfPnt2d.hxx> #include <TColgp_SequenceOfPnt2d.hxx>
#include <NCollection_Array1.hxx>
#include <algorithm>
static const Standard_Real NullTol = 1.e-10; static const Standard_Real NullTol = 1.e-10;
static const Standard_Real MaxSingular = 1.e-5; static const Standard_Real MaxSingular = 1.e-5;
@ -211,11 +211,10 @@ Handle(GeomFill_TrihedronLaw) GeomFill_Frenet::Copy() const
} }
// sorting // sorting
if(SeqArray[i-1].Length() != 0) { if(SeqArray[i-1].Length() != 0) {
TColStd_Array1OfReal anArray( 1, SeqArray[i-1].Length() ); NCollection_Array1<Standard_Real> anArray( 1, SeqArray[i-1].Length() );
for (j = 1; j <= anArray.Length(); j++) for (j = 1; j <= anArray.Length(); j++)
anArray(j) = SeqArray[i-1](j); anArray(j) = SeqArray[i-1](j);
TCollection_CompareOfReal Compar; std::sort (anArray.begin(), anArray.end());
SortTools_QuickSortOfReal::Sort( anArray, Compar);
for (j = 1; j <= anArray.Length(); j++) for (j = 1; j <= anArray.Length(); j++)
SeqArray[i-1](j) = anArray(j); SeqArray[i-1](j) = anArray(j);
} }
@ -258,11 +257,10 @@ Handle(GeomFill_TrihedronLaw) GeomFill_Frenet::Copy() const
if(SnglSeq.Length() > 0) { if(SnglSeq.Length() > 0) {
// sorting // sorting
TColStd_Array1OfReal anArray( 1, SnglSeq.Length() ); NCollection_Array1<Standard_Real> anArray( 1, SnglSeq.Length() );
for (i = 1; i <= SnglSeq.Length(); i++) for (i = 1; i <= SnglSeq.Length(); i++)
anArray(i) = SnglSeq(i); anArray(i) = SnglSeq(i);
TCollection_CompareOfReal Compar; std::sort (anArray.begin(), anArray.end());
SortTools_QuickSortOfReal::Sort( anArray, Compar );
for (i = 1; i <= SnglSeq.Length(); i++) for (i = 1; i <= SnglSeq.Length(); i++)
SnglSeq(i) = anArray(i); SnglSeq(i) = anArray(i);

View File

@ -86,3 +86,5 @@ NCollection_Vec2.hxx
NCollection_Vec3.hxx NCollection_Vec3.hxx
NCollection_Vec4.hxx NCollection_Vec4.hxx
NCollection_Mat4.hxx NCollection_Mat4.hxx
NCollection_StlIterator.hxx

View File

@ -23,6 +23,7 @@
#endif #endif
#include <NCollection_BaseCollection.hxx> #include <NCollection_BaseCollection.hxx>
#include <NCollection_StlIterator.hxx>
// *********************************************** Template for Array1 class // *********************************************** Template for Array1 class
@ -57,43 +58,101 @@
template <class TheItemType> class NCollection_Array1 template <class TheItemType> class NCollection_Array1
: public NCollection_BaseCollection<TheItemType> : public NCollection_BaseCollection<TheItemType>
{ {
public:
//! STL-compliant typedef for value type
typedef TheItemType value_type;
public: public:
//! Implementation of the Iterator interface. //! Implementation of the Iterator interface.
class Iterator : public NCollection_BaseCollection<TheItemType>::Iterator class Iterator : public NCollection_BaseCollection<TheItemType>::Iterator
{ {
public: public:
//! Empty constructor - for later Init //! Empty constructor - for later Init
Iterator (void) : Iterator (void) :
myCurrent (0), myPtrCur (NULL),
myArray (NULL) {} myPtrEnd (NULL)
//! Constructor with initialisation {
Iterator (const NCollection_Array1& theArray) : //
myCurrent (theArray.Lower()), }
myArray ((NCollection_Array1 *) &theArray) {}
//! Constructor with initialization
Iterator (const NCollection_Array1& theArray, Standard_Boolean theToEnd = Standard_False) :
myPtrEnd (const_cast<TheItemType*> (&theArray.Last() + 1))
{
myPtrCur = theToEnd ? myPtrEnd : const_cast<TheItemType*> (&theArray.First());
}
//! Initialisation //! Initialisation
void Init (const NCollection_Array1& theArray) void Init (const NCollection_Array1& theArray)
{ {
myCurrent = theArray.Lower(); myPtrCur = const_cast<TheItemType*> (&theArray.First());
myArray = (NCollection_Array1 *) &theArray; myPtrEnd = const_cast<TheItemType*> (&theArray.Last() + 1);
} }
//! Assignment
Iterator& operator= (const Iterator& theOther)
{
myPtrCur = theOther.myPtrCur;
myPtrEnd = theOther.myPtrEnd;
return *this;
}
//! Check end //! Check end
virtual Standard_Boolean More (void) const virtual Standard_Boolean More (void) const
{ return (myCurrent<=myArray->Upper()); } { return myPtrCur < myPtrEnd; }
//! Make step
//! Increment operator
virtual void Next (void) virtual void Next (void)
{ myCurrent++; } { ++myPtrCur; }
//! Decrement operator
virtual void Previous()
{ --myPtrCur; }
//! Offset operator.
virtual void Offset (ptrdiff_t theOffset)
{ myPtrCur += theOffset; }
//! Difference operator.
virtual ptrdiff_t Differ (const Iterator& theOther) const
{ return myPtrCur - theOther.myPtrCur; }
//! Constant value access //! Constant value access
virtual const TheItemType& Value (void) const virtual const TheItemType& Value (void) const
{ return myArray->Value(myCurrent); } { return *myPtrCur; }
//! Variable value access //! Variable value access
virtual TheItemType& ChangeValue (void) const virtual TheItemType& ChangeValue (void) const
{ return myArray->ChangeValue(myCurrent); } { return *myPtrCur; }
//! Performs comparison of two iterators
virtual Standard_Boolean IsEqual (const Iterator& theOther) const
{ return myPtrCur == theOther.myPtrCur; }
private: private:
Standard_Integer myCurrent; //!< Index of the current item TheItemType* myPtrCur; //!< Pointer to the current element in the array
NCollection_Array1* myArray; //!< Pointer to the array being iterated TheItemType* myPtrEnd; //!< Pointer to the past-the-end element in the array
}; // End of the nested class Iterator }; // End of the nested class Iterator
//! Shorthand for a regular iterator type.
typedef NCollection_StlIterator<std::random_access_iterator_tag, Iterator, TheItemType, false> iterator;
//! Shorthand for a constant iterator type.
typedef NCollection_StlIterator<std::random_access_iterator_tag, Iterator, TheItemType, true> const_iterator;
//! Returns an iterator pointing to the first element in the array.
iterator begin() const { return Iterator (*this, false); }
//! Returns an iterator referring to the past-the-end element in the array.
iterator end() const { return Iterator (*this, true); }
//! Returns a const iterator pointing to the first element in the array.
const_iterator cbegin() const { return Iterator (*this, false); }
//! Returns a const iterator referring to the past-the-end element in the array.
const_iterator cend() const { return Iterator (*this, true); }
public: public:
// ---------- PUBLIC METHODS ------------ // ---------- PUBLIC METHODS ------------

View File

@ -40,6 +40,10 @@
template <class TheItemType> class NCollection_Array2 template <class TheItemType> class NCollection_Array2
: public NCollection_BaseCollection<TheItemType> : public NCollection_BaseCollection<TheItemType>
{ {
public:
//! STL-compliant typedef for value type
typedef TheItemType value_type;
public: public:
// **************** Implementation of the Iterator interface. // **************** Implementation of the Iterator interface.
class Iterator : public NCollection_BaseCollection<TheItemType>::Iterator class Iterator : public NCollection_BaseCollection<TheItemType>::Iterator

View File

@ -72,11 +72,16 @@ class NCollection_BaseList
} }
//skt---------------------------------------------------- //skt----------------------------------------------------
// ******** Comparison operator // ******** Comparison operator
Standard_Boolean operator== (const Iterator& theIt) Standard_Boolean operator== (const Iterator& theIt) const
{ {
return myCurrent == theIt.myCurrent; return myCurrent == theIt.myCurrent;
} }
//------------------------------------------------------- //-------------------------------------------------------
//! Performs comparison of two iterators
virtual Standard_Boolean IsEqual (const Iterator& theOther) const
{
return *this == theOther;
}
protected: protected:
void Init (const NCollection_BaseList& theList, void Init (const NCollection_BaseList& theList,
NCollection_ListNode * const thePrev) NCollection_ListNode * const thePrev)

View File

@ -91,6 +91,12 @@ class NCollection_BaseMap
PNext(); PNext();
} }
//! Performs comparison of two iterators.
virtual Standard_Boolean IsEqual (const Iterator& theOther) const
{
return myBucket == theOther.myBucket && myNode == theOther.myNode;
}
protected: protected:
//! PMore //! PMore
Standard_Boolean PMore (void) const Standard_Boolean PMore (void) const

View File

@ -28,10 +28,9 @@
void NCollection_BaseSequence::ClearSeq void NCollection_BaseSequence::ClearSeq
(NCollection_DelSeqNode fDel, Handle(NCollection_BaseAllocator)& theAl) (NCollection_DelSeqNode fDel, Handle(NCollection_BaseAllocator)& theAl)
{ {
const NCollection_SeqNode * p = myFirstItem; NCollection_SeqNode* p = myFirstItem;
NCollection_SeqNode * q;
while (p) { while (p) {
q = (NCollection_SeqNode *) p; NCollection_SeqNode* q = p;
p = p->Next(); p = p->Next();
fDel (q, theAl); fDel (q, theAl);
} }
@ -49,7 +48,7 @@ void NCollection_BaseSequence::PAppend (NCollection_SeqNode * theItem)
myFirstItem = myLastItem = myCurrentItem = theItem; myFirstItem = myLastItem = myCurrentItem = theItem;
myCurrentIndex = mySize = 1; myCurrentIndex = mySize = 1;
} else { } else {
((NCollection_SeqNode *) myLastItem)->SetNext(theItem); myLastItem->SetNext(theItem);
theItem->SetPrevious(myLastItem); theItem->SetPrevious(myLastItem);
theItem->SetNext(NULL); theItem->SetNext(NULL);
myLastItem = theItem; myLastItem = theItem;
@ -72,9 +71,9 @@ void NCollection_BaseSequence::PAppend(NCollection_BaseSequence& Other)
myCurrentIndex = 1; myCurrentIndex = 1;
} else { } else {
mySize += Other.mySize; mySize += Other.mySize;
((NCollection_SeqNode *) myLastItem)->SetNext(Other.myFirstItem); myLastItem->SetNext(Other.myFirstItem);
if (Other.myFirstItem) { if (Other.myFirstItem) {
((NCollection_SeqNode *) Other.myFirstItem)->SetPrevious(myLastItem); Other.myFirstItem->SetPrevious(myLastItem);
myLastItem = Other.myLastItem; myLastItem = Other.myLastItem;
} }
} }
@ -92,8 +91,8 @@ void NCollection_BaseSequence::PPrepend (NCollection_SeqNode * theItem)
myFirstItem = myLastItem = myCurrentItem = theItem; myFirstItem = myLastItem = myCurrentItem = theItem;
myCurrentIndex = mySize = 1; myCurrentIndex = mySize = 1;
} else { } else {
((NCollection_SeqNode *) myFirstItem)->SetPrevious (theItem); myFirstItem->SetPrevious (theItem);
((NCollection_SeqNode *) theItem)->SetNext (myFirstItem); theItem->SetNext (myFirstItem);
theItem->SetPrevious(NULL); theItem->SetPrevious(NULL);
theItem->SetNext(myFirstItem); theItem->SetNext(myFirstItem);
myFirstItem = theItem; myFirstItem = theItem;
@ -118,8 +117,8 @@ void NCollection_BaseSequence::PPrepend (NCollection_BaseSequence& Other)
} else { } else {
mySize += Other.mySize; mySize += Other.mySize;
if (Other.myLastItem) if (Other.myLastItem)
((NCollection_SeqNode *) Other.myLastItem)->SetNext (myFirstItem); Other.myLastItem->SetNext (myFirstItem);
((NCollection_SeqNode *) myFirstItem)->SetPrevious(Other.myLastItem); myFirstItem->SetPrevious(Other.myLastItem);
myFirstItem = Other.myFirstItem; myFirstItem = Other.myFirstItem;
myCurrentIndex += Other.mySize; myCurrentIndex += Other.mySize;
} }
@ -133,18 +132,18 @@ void NCollection_BaseSequence::PPrepend (NCollection_BaseSequence& Other)
void NCollection_BaseSequence::PReverse() void NCollection_BaseSequence::PReverse()
{ {
const NCollection_SeqNode * p = myFirstItem; NCollection_SeqNode* p = myFirstItem;
const NCollection_SeqNode * tmp;
while (p) { while (p) {
tmp = p->Next(); NCollection_SeqNode* tmp = p->Next();
((NCollection_SeqNode *) p)->SetNext (p->Previous()); p->SetNext (p->Previous());
((NCollection_SeqNode *) p)->SetPrevious (tmp); p->SetPrevious (tmp);
p = tmp; p = tmp;
} }
tmp = myFirstItem; NCollection_SeqNode* tmp = myFirstItem;
myFirstItem = myLastItem; myFirstItem = myLastItem;
myLastItem = tmp; myLastItem = tmp;
if (mySize != 0) myCurrentIndex = mySize + 1 - myCurrentIndex; if (mySize != 0)
myCurrentIndex = mySize + 1 - myCurrentIndex;
} }
@ -163,8 +162,10 @@ void NCollection_BaseSequence::PInsertAfter
else { else {
theItem->SetNext (aPos->Next()); theItem->SetNext (aPos->Next());
theItem->SetPrevious (aPos); theItem->SetPrevious (aPos);
if (aPos->Next() == NULL) myLastItem = theItem; if (aPos->Next() == NULL)
else ((NCollection_SeqNode *) aPos->Next())->SetPrevious(theItem); myLastItem = theItem;
else
aPos->Next()->SetPrevious(theItem);
aPos->SetNext(theItem); aPos->SetNext(theItem);
++ mySize; ++ mySize;
myCurrentItem = myFirstItem; myCurrentItem = myFirstItem;
@ -183,12 +184,14 @@ void NCollection_BaseSequence::PInsertAfter(const Standard_Integer theIndex,
if (theIndex == 0) if (theIndex == 0)
PPrepend (theItem); PPrepend (theItem);
else { else {
const NCollection_SeqNode * p = Find (theIndex); NCollection_SeqNode * p = Find (theIndex);
theItem->SetNext(p->Next()); theItem->SetNext(p->Next());
theItem->SetPrevious(p); theItem->SetPrevious(p);
if (theIndex == mySize) myLastItem = theItem; if (theIndex == mySize)
else ((NCollection_SeqNode *) p->Next())->SetPrevious(theItem); myLastItem = theItem;
((NCollection_SeqNode *) p)->SetNext(theItem); else
p->Next()->SetPrevious(theItem);
p->SetNext(theItem);
++ mySize; ++ mySize;
if (theIndex < myCurrentIndex) if (theIndex < myCurrentIndex)
++ myCurrentIndex; ++ myCurrentIndex;
@ -209,14 +212,14 @@ void NCollection_BaseSequence::PInsertAfter (const Standard_Integer theIndex,
if (theIndex == 0) if (theIndex == 0)
PPrepend (Other); PPrepend (Other);
else { else {
const NCollection_SeqNode * p = Find (theIndex); NCollection_SeqNode * p = Find (theIndex);
((NCollection_SeqNode *) Other.myFirstItem)->SetPrevious (p); Other.myFirstItem->SetPrevious (p);
((NCollection_SeqNode *) Other.myLastItem)->SetNext (p->Next()); Other.myLastItem->SetNext (p->Next());
if (theIndex == mySize) if (theIndex == mySize)
myLastItem = Other.myLastItem; myLastItem = Other.myLastItem;
else else
((NCollection_SeqNode *) p->Next())->SetPrevious (Other.myLastItem); p->Next()->SetPrevious (Other.myLastItem);
((NCollection_SeqNode *) p)->SetNext (Other.myFirstItem); p->SetNext (Other.myFirstItem);
mySize += Other.mySize; mySize += Other.mySize;
if (theIndex < myCurrentIndex) if (theIndex < myCurrentIndex)
myCurrentIndex += Other.mySize; myCurrentIndex += Other.mySize;
@ -240,39 +243,39 @@ void NCollection_BaseSequence::PExchange (const Standard_Integer I,
if (J < I) if (J < I)
PExchange(J,I); PExchange(J,I);
else if (I < J) { else if (I < J) {
const NCollection_SeqNode * pi = Find(I); NCollection_SeqNode * pi = Find(I);
const NCollection_SeqNode * pj = Find(J); NCollection_SeqNode * pj = Find(J);
// update the node before I // update the node before I
if (pi->Previous()) if (pi->Previous())
((NCollection_SeqNode *) pi->Previous())->SetNext (pj); pi->Previous()->SetNext (pj);
else else
myFirstItem = pj; myFirstItem = pj;
// update the node after J // update the node after J
if (pj->Next()) if (pj->Next())
((NCollection_SeqNode *) pj->Next())->SetPrevious(pi); pj->Next()->SetPrevious(pi);
else else
myLastItem = pi; myLastItem = pi;
if (pi->Next() == pj) { // I and J are consecutives, update them if (pi->Next() == pj) { // I and J are consecutives, update them
((NCollection_SeqNode *) pj)->SetPrevious (pi->Previous()); pj->SetPrevious (pi->Previous());
((NCollection_SeqNode *) pi)->SetPrevious (pj); pi->SetPrevious (pj);
((NCollection_SeqNode *) pi)->SetNext (pj->Next()); pi->SetNext (pj->Next());
((NCollection_SeqNode *) pj)->SetNext (pi); pj->SetNext (pi);
} }
else { // I and J are not consecutive else { // I and J are not consecutive
// update the node after I // update the node after I
((NCollection_SeqNode *) pi->Next())->SetPrevious (pj); pi->Next()->SetPrevious (pj);
// update the node before J // update the node before J
((NCollection_SeqNode *) pj->Previous())->SetNext (pi); pj->Previous()->SetNext (pi);
// update nodes I and J // update nodes I and J
const NCollection_SeqNode* tmp = pi->Next(); NCollection_SeqNode* tmp = pi->Next();
((NCollection_SeqNode *) pi)->SetNext (pj->Next()); pi->SetNext (pj->Next());
((NCollection_SeqNode *) pj)->SetNext (tmp); pj->SetNext (tmp);
tmp = pi->Previous(); tmp = pi->Previous();
((NCollection_SeqNode *) pi)->SetPrevious (pj->Previous()); pi->SetPrevious (pj->Previous());
((NCollection_SeqNode *) pj)->SetPrevious (tmp); pj->SetPrevious (tmp);
} }
if (myCurrentIndex == I) myCurrentItem = pj; if (myCurrentIndex == I) myCurrentItem = pj;
@ -291,14 +294,14 @@ void NCollection_BaseSequence::PSplit (const Standard_Integer theIndex,
Standard_OutOfRange_Raise_if (theIndex <= 0 || theIndex > mySize,"" ); Standard_OutOfRange_Raise_if (theIndex <= 0 || theIndex > mySize,"" );
Standard_DomainError_Raise_if (this == &Sub, "No Split on myself!!"); Standard_DomainError_Raise_if (this == &Sub, "No Split on myself!!");
const NCollection_SeqNode * p = Find (theIndex); NCollection_SeqNode * p = Find (theIndex);
Sub.myLastItem = myLastItem; Sub.myLastItem = myLastItem;
Sub.mySize = mySize - theIndex + 1; Sub.mySize = mySize - theIndex + 1;
myLastItem = p->Previous(); myLastItem = p->Previous();
if (myLastItem) { if (myLastItem) {
((NCollection_SeqNode *) myLastItem)->SetNext(NULL); myLastItem->SetNext(NULL);
mySize = theIndex - 1; mySize = theIndex - 1;
if (myCurrentIndex >= theIndex) { if (myCurrentIndex >= theIndex) {
myCurrentIndex = 1; myCurrentIndex = 1;
@ -310,7 +313,7 @@ void NCollection_BaseSequence::PSplit (const Standard_Integer theIndex,
} }
Sub.myFirstItem = Sub.myCurrentItem = p; Sub.myFirstItem = Sub.myCurrentItem = p;
((NCollection_SeqNode *) p)->SetPrevious (NULL); p->SetPrevious (NULL);
Sub.myCurrentIndex = 1; Sub.myCurrentIndex = 1;
} }
@ -327,15 +330,15 @@ void NCollection_BaseSequence::RemoveSeq
NCollection_SeqNode * aPos = thePosition.myCurrent; NCollection_SeqNode * aPos = thePosition.myCurrent;
if (aPos == NULL) if (aPos == NULL)
return; return;
thePosition.myCurrent = (NCollection_SeqNode *) aPos -> Next(); thePosition.myCurrent = aPos -> Next();
if (aPos->Previous()) if (aPos->Previous())
((NCollection_SeqNode *) aPos->Previous())->SetNext (aPos->Next()); aPos->Previous()->SetNext (aPos->Next());
else else
myFirstItem = aPos->Next(); myFirstItem = aPos->Next();
if (aPos->Next()) if (aPos->Next())
((NCollection_SeqNode *) aPos->Next())->SetPrevious (aPos->Previous()); aPos->Next()->SetPrevious (aPos->Previous());
else else
myLastItem = aPos->Previous(); myLastItem = aPos->Previous();
@ -358,13 +361,13 @@ void NCollection_BaseSequence::RemoveSeq
{ {
Standard_OutOfRange_Raise_if (theIndex <= 0 || theIndex > mySize, ""); Standard_OutOfRange_Raise_if (theIndex <= 0 || theIndex > mySize, "");
const NCollection_SeqNode * p = Find (theIndex); NCollection_SeqNode * p = Find (theIndex);
if (p->Previous()) if (p->Previous())
((NCollection_SeqNode *) p->Previous())->SetNext (p->Next()); p->Previous()->SetNext (p->Next());
else else
myFirstItem = p->Next(); myFirstItem = p->Next();
if (p->Next()) if (p->Next())
((NCollection_SeqNode *) p->Next())->SetPrevious (p->Previous()); p->Next()->SetPrevious (p->Previous());
else else
myLastItem = p->Previous(); myLastItem = p->Previous();
@ -378,7 +381,7 @@ void NCollection_BaseSequence::RemoveSeq
myCurrentIndex = mySize; myCurrentIndex = mySize;
} }
} }
fDel ((NCollection_SeqNode *) p, theAl); fDel (p, theAl);
} }
//======================================================================= //=======================================================================
@ -394,15 +397,15 @@ void NCollection_BaseSequence::RemoveSeq
{ {
Standard_OutOfRange_Raise_if (From <= 0 || To > mySize || From > To, ""); Standard_OutOfRange_Raise_if (From <= 0 || To > mySize || From > To, "");
const NCollection_SeqNode * pfrom = Find(From); NCollection_SeqNode * pfrom = Find(From);
const NCollection_SeqNode * pto = Find(To); NCollection_SeqNode * pto = Find(To);
if (pfrom->Previous()) if (pfrom->Previous())
((NCollection_SeqNode *) pfrom->Previous())->SetNext (pto->Next()); pfrom->Previous()->SetNext (pto->Next());
else else
myFirstItem = pto->Next(); myFirstItem = pto->Next();
if (pto->Next()) if (pto->Next())
((NCollection_SeqNode *) pto->Next())->SetPrevious (pfrom->Previous()); pto->Next()->SetPrevious (pfrom->Previous());
else else
myLastItem = pfrom->Previous(); myLastItem = pfrom->Previous();
@ -420,7 +423,7 @@ void NCollection_BaseSequence::RemoveSeq
} }
for (Standard_Integer i = From; i <= To; i++) { for (Standard_Integer i = From; i <= To; i++) {
NCollection_SeqNode * tmp = (NCollection_SeqNode *)pfrom; NCollection_SeqNode * tmp = pfrom;
pfrom = pfrom->Next(); pfrom = pfrom->Next();
fDel (tmp, theAl); fDel (tmp, theAl);
} }
@ -431,26 +434,29 @@ void NCollection_BaseSequence::RemoveSeq
//purpose : //purpose :
//======================================================================= //=======================================================================
const NCollection_SeqNode * NCollection_BaseSequence::Find NCollection_SeqNode * NCollection_BaseSequence::Find (const Standard_Integer theIndex) const
(const Standard_Integer theIndex) const
{ {
Standard_Integer i; Standard_Integer i;
const NCollection_SeqNode * p; NCollection_SeqNode * p;
if (theIndex <= myCurrentIndex) { if (theIndex <= myCurrentIndex) {
if (theIndex < myCurrentIndex / 2) { if (theIndex < myCurrentIndex / 2) {
p = myFirstItem; p = myFirstItem;
for (i = 1; i < theIndex; i++) p = p->Next(); for (i = 1; i < theIndex; i++)
p = p->Next();
} else { } else {
p = myCurrentItem; p = myCurrentItem;
for (i = myCurrentIndex; i > theIndex; i--) p = p->Previous(); for (i = myCurrentIndex; i > theIndex; i--)
p = p->Previous();
} }
} else { } else {
if (theIndex < (myCurrentIndex + mySize) / 2) { if (theIndex < (myCurrentIndex + mySize) / 2) {
p = myCurrentItem; p = myCurrentItem;
for (i = myCurrentIndex; i < theIndex; i++) p = p->Next(); for (i = myCurrentIndex; i < theIndex; i++)
p = p->Next();
} else { } else {
p = myLastItem; p = myLastItem;
for (i = mySize; i > theIndex; i--) p = p->Previous(); for (i = mySize; i > theIndex; i--)
p = p->Previous();
} }
} }
return p; return p;

View File

@ -24,26 +24,15 @@
class NCollection_SeqNode class NCollection_SeqNode
{ {
public: public:
// Methods PUBLIC NCollection_SeqNode () : myNext (NULL), myPrevious (NULL) {}
// NCollection_SeqNode * Next () const { return myNext; }
NCollection_SeqNode (void) NCollection_SeqNode * Previous () const { return myPrevious; }
: myNext (NULL), myPrevious (NULL) {} void SetNext (NCollection_SeqNode * theNext) { myNext = theNext; }
const NCollection_SeqNode * Next () const { return myNext; } void SetPrevious (NCollection_SeqNode * thePrev) { myPrevious = thePrev; }
const NCollection_SeqNode * Previous () const { return myPrevious; }
void SetNext (const NCollection_SeqNode * theNext)
{ myNext = theNext; }
void SetPrevious (const NCollection_SeqNode * thePrev)
{ myPrevious = thePrev; }
//~NCollection_SeqNode() {
// if (myNext) myNext -> myPrevious = myPrevious;
// if (myPrevious) myPrevious -> myNext = myNext;
//}
private: private:
// Fields PRIVATE NCollection_SeqNode* myNext;
// NCollection_SeqNode* myPrevious;
const NCollection_SeqNode * myNext;
const NCollection_SeqNode * myPrevious;
}; };
typedef void (* NCollection_DelSeqNode) typedef void (* NCollection_DelSeqNode)
@ -60,28 +49,41 @@ class NCollection_BaseSequence
{ {
public: public:
//! Empty constructor //! Empty constructor
Iterator (void) : myCurrent (NULL) {} Iterator (void) : myCurrent (NULL), myPrevious(NULL) {}
//! Constructor with initialisation //! Constructor with initialisation
Iterator (const NCollection_BaseSequence& theSeq, Iterator (const NCollection_BaseSequence& theSeq,
const Standard_Boolean isStart) const Standard_Boolean isStart)
: myCurrent(isStart ? (NCollection_SeqNode *)theSeq.myFirstItem {
: (NCollection_SeqNode *)theSeq.myLastItem) {} Init (theSeq, isStart);
}
//! Initialisation //! Initialisation
void Init (const NCollection_BaseSequence& theSeq, void Init (const NCollection_BaseSequence& theSeq,
const Standard_Boolean isStart const Standard_Boolean isStart = Standard_True)
= Standard_True) {
{ myCurrent = isStart ? (NCollection_SeqNode *)theSeq.myFirstItem myCurrent = (isStart ? theSeq.myFirstItem : NULL);
: (NCollection_SeqNode *)theSeq.myLastItem; } myPrevious = (isStart ? NULL : theSeq.myLastItem);
}
//! Assignment //! Assignment
Iterator& operator = (const Iterator& theOther) Iterator& operator = (const Iterator& theOther)
{ myCurrent = theOther.myCurrent; return *this; } {
//! Previous myCurrent = theOther.myCurrent;
myPrevious = theOther.myPrevious;
return *this;
}
//! Switch to previous element; note that it will reset
void Previous() void Previous()
{ if (myCurrent) {
myCurrent = (NCollection_SeqNode *)myCurrent -> Previous(); } myCurrent = myPrevious;
if (myCurrent)
myPrevious = myCurrent->Previous();
}
protected: protected:
NCollection_SeqNode* myCurrent; //!< Pointer to the current node NCollection_SeqNode* myCurrent; //!< Pointer to the current node
NCollection_SeqNode* myPrevious; //!< Pointer to the previous node
friend class NCollection_BaseSequence; friend class NCollection_BaseSequence;
}; };
@ -122,15 +124,15 @@ class NCollection_BaseSequence
Standard_EXPORT void PReverse (); Standard_EXPORT void PReverse ();
Standard_EXPORT void PExchange (const Standard_Integer I, Standard_EXPORT void PExchange (const Standard_Integer I,
const Standard_Integer J) ; const Standard_Integer J) ;
Standard_EXPORT const NCollection_SeqNode * Standard_EXPORT NCollection_SeqNode *
Find (const Standard_Integer) const; Find (const Standard_Integer) const;
protected: protected:
// Fields PROTECTED // Fields PROTECTED
// //
const NCollection_SeqNode * myFirstItem; NCollection_SeqNode* myFirstItem;
const NCollection_SeqNode * myLastItem; NCollection_SeqNode* myLastItem;
const NCollection_SeqNode * myCurrentItem; NCollection_SeqNode* myCurrentItem;
Standard_Integer myCurrentIndex; Standard_Integer myCurrentIndex;
Standard_Integer mySize; Standard_Integer mySize;

View File

@ -36,20 +36,24 @@ void NCollection_BaseVector::Iterator::copyV (const NCollection_BaseVector::Iter
//purpose : Initialisation of iterator by a vector //purpose : Initialisation of iterator by a vector
//======================================================================= //=======================================================================
void NCollection_BaseVector::Iterator::initV (const NCollection_BaseVector& theVector) void NCollection_BaseVector::Iterator::initV (const NCollection_BaseVector& theVector, Standard_Boolean theToEnd)
{ {
myVector = &theVector; myVector = &theVector;
myICurBlock = 0;
myCurIndex = 0;
if (theVector.myNBlocks == 0) if (theVector.myNBlocks == 0)
{ {
myIEndBlock = 0; myCurIndex = 0;
myEndIndex = 0; myEndIndex = 0;
myICurBlock = 0;
myIEndBlock = 0;
} }
else else
{ {
myIEndBlock = theVector.myNBlocks - 1; myIEndBlock = theVector.myNBlocks - 1;
myEndIndex = theVector.myData[myIEndBlock].Length; myEndIndex = theVector.myData[myIEndBlock].Length;
myICurBlock = !theToEnd ? 0 : myIEndBlock;
myCurIndex = !theToEnd ? 0 : myEndIndex;
} }
} }

View File

@ -74,9 +74,9 @@ protected:
myCurIndex (0), myCurIndex (0),
myEndIndex (0) {} myEndIndex (0) {}
Iterator (const NCollection_BaseVector& theVector) Iterator (const NCollection_BaseVector& theVector, Standard_Boolean theToEnd = Standard_False)
{ {
initV (theVector); initV (theVector, theToEnd);
} }
Iterator (const Iterator& theVector) Iterator (const Iterator& theVector)
@ -84,7 +84,7 @@ protected:
copyV (theVector); copyV (theVector);
} }
Standard_EXPORT void initV (const NCollection_BaseVector& theVector); Standard_EXPORT void initV (const NCollection_BaseVector& theVector, Standard_Boolean theToEnd = Standard_False);
Standard_EXPORT void copyV (const Iterator&); Standard_EXPORT void copyV (const Iterator&);
@ -103,6 +103,27 @@ protected:
} }
} }
void prevV()
{
if (--myCurIndex < 0 && myICurBlock > 0)
{
--myICurBlock;
myCurIndex = myVector->myData[myICurBlock].Length - 1;
}
}
virtual void offsetV (Standard_Integer theOffset)
{
const Standard_Integer anIndex = myCurIndex + myICurBlock * myVector->myIncrement + theOffset;
myICurBlock = anIndex / myVector->myIncrement;
myCurIndex = anIndex % myVector->myIncrement;
}
virtual Standard_Integer differV (const Iterator& theOther) const
{
return (myCurIndex - theOther.myCurIndex) + (myICurBlock - theOther.myICurBlock) * myVector->myIncrement;
}
const MemBlock* curBlockV() const const MemBlock* curBlockV() const
{ {
return &myVector->myData[myICurBlock]; return &myVector->myData[myICurBlock];

View File

@ -19,7 +19,7 @@
#include <NCollection_BaseCollection.hxx> #include <NCollection_BaseCollection.hxx>
#include <NCollection_BaseMap.hxx> #include <NCollection_BaseMap.hxx>
#include <NCollection_TListNode.hxx> #include <NCollection_TListNode.hxx>
#include <NCollection_StlIterator.hxx>
#include <NCollection_DefaultHasher.hxx> #include <NCollection_DefaultHasher.hxx>
#include <Standard_TypeMismatch.hxx> #include <Standard_TypeMismatch.hxx>
@ -125,6 +125,24 @@ template < class TheKeyType,
} }
}; };
//! Shorthand for a regular iterator type.
typedef NCollection_StlIterator<std::forward_iterator_tag, Iterator, TheItemType, false> iterator;
//! Shorthand for a constant iterator type.
typedef NCollection_StlIterator<std::forward_iterator_tag, Iterator, TheItemType, true> const_iterator;
//! Returns an iterator pointing to the first element in the map.
iterator begin() const { return Iterator (*this); }
//! Returns an iterator referring to the past-the-end element in the map.
iterator end() const { return Iterator(); }
//! Returns a const iterator pointing to the first element in the map.
const_iterator cbegin() const { return Iterator (*this); }
//! Returns a const iterator referring to the past-the-end element in the map.
const_iterator cend() const { return Iterator(); }
public: public:
// ---------- PUBLIC METHODS ------------ // ---------- PUBLIC METHODS ------------

View File

@ -21,7 +21,7 @@
#include <NCollection_TListNode.hxx> #include <NCollection_TListNode.hxx>
#include <Standard_TypeMismatch.hxx> #include <Standard_TypeMismatch.hxx>
#include <Standard_NoSuchObject.hxx> #include <Standard_NoSuchObject.hxx>
#include <NCollection_StlIterator.hxx>
#include <NCollection_DefaultHasher.hxx> #include <NCollection_DefaultHasher.hxx>
#if !defined No_Exception && !defined No_Standard_OutOfRange #if !defined No_Exception && !defined No_Standard_OutOfRange
@ -110,7 +110,7 @@ template < class TheKeyType,
myIndex (1) {} myIndex (1) {}
//! Query if the end of collection is reached by iterator //! Query if the end of collection is reached by iterator
virtual Standard_Boolean More(void) const virtual Standard_Boolean More(void) const
{ return (myIndex <= myMap->Extent()); } { return (myMap != NULL) && (myIndex <= myMap->Extent()); }
//! Make a step along the collection //! Make a step along the collection
virtual void Next(void) virtual void Next(void)
{ {
@ -143,12 +143,37 @@ template < class TheKeyType,
#endif #endif
return myNode->Key1(); return myNode->Key1();
} }
//! Performs comparison of two iterators.
virtual Standard_Boolean IsEqual (const Iterator& theOther) const
{
return myMap == theOther.myMap &&
myNode == theOther.myNode &&
myIndex == theOther.myIndex;
}
private: private:
NCollection_IndexedDataMap* myMap; //!< Pointer to the map being iterated NCollection_IndexedDataMap* myMap; //!< Pointer to the map being iterated
IndexedDataMapNode* myNode; //!< Current node IndexedDataMapNode* myNode; //!< Current node
Standard_Integer myIndex; //!< Current index Standard_Integer myIndex; //!< Current index
}; };
//! Shorthand for a regular iterator type.
typedef NCollection_StlIterator<std::forward_iterator_tag, Iterator, TheItemType, false> iterator;
//! Shorthand for a constant iterator type.
typedef NCollection_StlIterator<std::forward_iterator_tag, Iterator, TheItemType, true> const_iterator;
//! Returns an iterator pointing to the first element in the map.
iterator begin() const { return Iterator (*this); }
//! Returns an iterator referring to the past-the-end element in the map.
iterator end() const { return Iterator(); }
//! Returns a const iterator pointing to the first element in the map.
const_iterator cbegin() const { return Iterator (*this); }
//! Returns a const iterator referring to the past-the-end element in the map.
const_iterator cend() const { return Iterator(); }
public: public:
// ---------- PUBLIC METHODS ------------ // ---------- PUBLIC METHODS ------------

View File

@ -19,6 +19,7 @@
#include <NCollection_BaseCollection.hxx> #include <NCollection_BaseCollection.hxx>
#include <NCollection_BaseMap.hxx> #include <NCollection_BaseMap.hxx>
#include <NCollection_TListNode.hxx> #include <NCollection_TListNode.hxx>
#include <NCollection_StlIterator.hxx>
#include <Standard_NoSuchObject.hxx> #include <Standard_NoSuchObject.hxx>
#include <Standard_ImmutableObject.hxx> #include <Standard_ImmutableObject.hxx>
@ -99,7 +100,7 @@ template < class TheKeyType,
myIndex(1) {} myIndex(1) {}
//! Query if the end of collection is reached by iterator //! Query if the end of collection is reached by iterator
virtual Standard_Boolean More(void) const virtual Standard_Boolean More(void) const
{ return (myIndex <= myMap->Extent()); } { return (myMap != NULL) && (myIndex <= myMap->Extent()); }
//! Make a step along the collection //! Make a step along the collection
virtual void Next(void) virtual void Next(void)
{ myIndex++; } { myIndex++; }
@ -118,12 +119,26 @@ template < class TheKeyType,
Standard_ImmutableObject::Raise ("impossible to ChangeValue"); Standard_ImmutableObject::Raise ("impossible to ChangeValue");
return * (TheKeyType *) NULL; // This for compiler return * (TheKeyType *) NULL; // This for compiler
} }
//! Performs comparison of two iterators.
virtual Standard_Boolean IsEqual (const Iterator& theOther) const
{
return myMap == theOther.myMap && myIndex == theOther.myIndex;
}
private: private:
NCollection_IndexedMap * myMap; // Pointer to the map being iterated NCollection_IndexedMap * myMap; // Pointer to the map being iterated
Standard_Integer myIndex; // Current index Standard_Integer myIndex; // Current index
}; };
//! Shorthand for a constant iterator type.
typedef NCollection_StlIterator<std::forward_iterator_tag, Iterator, TheKeyType, true> const_iterator;
//! Returns a const iterator pointing to the first element in the map.
const_iterator cbegin() const { return Iterator (*this); }
//! Returns a const iterator referring to the past-the-end element in the map.
const_iterator cend() const { return Iterator(); }
public: public:
// ---------- PUBLIC METHODS ------------ // ---------- PUBLIC METHODS ------------

View File

@ -17,6 +17,7 @@
#define NCollection_List_HeaderFile #define NCollection_List_HeaderFile
#include <NCollection_TListIterator.hxx> #include <NCollection_TListIterator.hxx>
#include <NCollection_StlIterator.hxx>
#if !defined No_Exception && !defined No_Standard_NoSuchObject #if !defined No_Exception && !defined No_Standard_NoSuchObject
#include <Standard_NoSuchObject.hxx> #include <Standard_NoSuchObject.hxx>
@ -31,10 +32,32 @@ template <class TheItemType> class NCollection_List
: public NCollection_BaseCollection<TheItemType>, : public NCollection_BaseCollection<TheItemType>,
public NCollection_BaseList public NCollection_BaseList
{ {
public:
//! STL-compliant typedef for value type
typedef TheItemType value_type;
public: public:
typedef NCollection_TListNode<TheItemType> ListNode; typedef NCollection_TListNode<TheItemType> ListNode;
typedef NCollection_TListIterator<TheItemType> Iterator; typedef NCollection_TListIterator<TheItemType> Iterator;
//! Shorthand for a regular iterator type.
typedef NCollection_StlIterator<std::forward_iterator_tag, Iterator, TheItemType, false> iterator;
//! Shorthand for a constant iterator type.
typedef NCollection_StlIterator<std::forward_iterator_tag, Iterator, TheItemType, true> const_iterator;
//! Returns an iterator pointing to the first element in the list.
iterator begin() const { return Iterator (*this); }
//! Returns an iterator referring to the past-the-end element in the list.
iterator end() const { return Iterator(); }
//! Returns a const iterator pointing to the first element in the list.
const_iterator cbegin() const { return Iterator (*this); }
//! Returns a const iterator referring to the past-the-end element in the list.
const_iterator cend() const { return Iterator(); }
public: public:
// ---------- PUBLIC METHODS ------------ // ---------- PUBLIC METHODS ------------

View File

@ -20,7 +20,7 @@
#include <NCollection_BaseMap.hxx> #include <NCollection_BaseMap.hxx>
#include <NCollection_DataMap.hxx> #include <NCollection_DataMap.hxx>
#include <NCollection_TListNode.hxx> #include <NCollection_TListNode.hxx>
#include <NCollection_StlIterator.hxx>
#include <NCollection_DefaultHasher.hxx> #include <NCollection_DefaultHasher.hxx>
#include <Standard_ImmutableObject.hxx> #include <Standard_ImmutableObject.hxx>
@ -123,6 +123,15 @@ template < class TheKeyType,
} }
}; };
//! Shorthand for a constant iterator type.
typedef NCollection_StlIterator<std::forward_iterator_tag, Iterator, TheKeyType, true> const_iterator;
//! Returns a const iterator pointing to the first element in the map.
const_iterator cbegin() const { return Iterator (*this); }
//! Returns a const iterator referring to the past-the-end element in the map.
const_iterator cend() const { return Iterator(); }
public: public:
// ---------- PUBLIC METHODS ------------ // ---------- PUBLIC METHODS ------------

View File

@ -18,6 +18,7 @@
#include <NCollection_BaseCollection.hxx> #include <NCollection_BaseCollection.hxx>
#include <NCollection_BaseSequence.hxx> #include <NCollection_BaseSequence.hxx>
#include <NCollection_StlIterator.hxx>
#ifndef No_Exception #ifndef No_Exception
#include <Standard_OutOfRange.hxx> #include <Standard_OutOfRange.hxx>
@ -32,6 +33,9 @@ template <class TheItemType> class NCollection_Sequence
: public NCollection_BaseCollection<TheItemType>, : public NCollection_BaseCollection<TheItemType>,
public NCollection_BaseSequence public NCollection_BaseSequence
{ {
public:
//! STL-compliant typedef for value type
typedef TheItemType value_type;
public: public:
//! Class defining sequence node - for internal use by Sequence //! Class defining sequence node - for internal use by Sequence
@ -78,15 +82,44 @@ template <class TheItemType> class NCollection_Sequence
{ return (myCurrent!=NULL); } { return (myCurrent!=NULL); }
//! Make step //! Make step
virtual void Next (void) virtual void Next (void)
{ if (myCurrent) myCurrent = (NCollection_SeqNode *) myCurrent->Next(); } {
if (myCurrent)
{
myPrevious = myCurrent;
myCurrent = myCurrent->Next();
}
}
//! Constant value access //! Constant value access
virtual const TheItemType& Value (void) const virtual const TheItemType& Value (void) const
{ return ((const Node *)myCurrent)->Value(); } { return ((const Node *)myCurrent)->Value(); }
//! Variable value access //! Variable value access
virtual TheItemType& ChangeValue (void) const virtual TheItemType& ChangeValue (void) const
{ return ((Node *)myCurrent)->ChangeValue(); } { return ((Node *)myCurrent)->ChangeValue(); }
//! Performs comparison of two iterators.
virtual Standard_Boolean IsEqual (const Iterator& theOther) const
{
return myCurrent == theOther.myCurrent;
}
}; // End of nested class Iterator }; // End of nested class Iterator
//! Shorthand for a regular iterator type.
typedef NCollection_StlIterator<std::bidirectional_iterator_tag, Iterator, TheItemType, false> iterator;
//! Shorthand for a constant iterator type.
typedef NCollection_StlIterator<std::bidirectional_iterator_tag, Iterator, TheItemType, true> const_iterator;
//! Returns an iterator pointing to the first element in the sequence.
iterator begin() const { return Iterator (*this, true); }
//! Returns an iterator referring to the past-the-end element in the sequence.
iterator end() const { Iterator anIter (*this, false); anIter.Next(); return anIter; }
//! Returns a const iterator pointing to the first element in the sequence.
const_iterator cbegin() const { return Iterator (*this, true); }
//! Returns a const iterator referring to the past-the-end element in the sequence.
const_iterator cend() const { Iterator anIter (*this, false); anIter.Next(); return anIter; }
public: public:
// ---------- PUBLIC METHODS ------------ // ---------- PUBLIC METHODS ------------

View File

@ -0,0 +1,246 @@
// Created on: 2014-04-15
// Created by: Denis BOGOLEPOV
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef NCollection_StlIterator_HeaderFile
#define NCollection_StlIterator_HeaderFile
#include <Standard_Assert.hxx>
#include <iterator>
// This file uses C++11 utilities like std::is_base<>, which are not
// available in some environments (e.g. MSVC includes them since VS 2008).
// Hence here we define our own implementation of these tools in namespace opencascade.
// When all compilers support this, this namespace can be removed and replaced by std.
namespace opencascade
{
template<bool Condition, typename T>
struct enable_if
{
typedef T type;
};
template<typename T>
struct enable_if<false, T>
{
};
template<typename T1, typename T2>
struct is_same
{
enum { value = 0 };
};
template<typename T>
struct is_same<T, T>
{
enum { value = 1 };
};
template<bool Condition, typename TypeTrue, typename TypeFalse>
struct conditional
{
typedef TypeTrue type;
};
template<typename TypeTrue, typename TypeFalse>
struct conditional<false, TypeTrue, TypeFalse>
{
typedef TypeFalse type;
};
}
//! Helper class that allows to use NCollection iterators as STL iterators.
//! NCollection iterator can be extended to STL iterator of any category by
//! adding necessary methods: STL forward iterator requires IsEqual method,
//! STL bidirectional iterator requires Previous method, and STL random access
//! iterator requires Offset and Differ methods. See NCollection_Vector as
//! example of declaring custom STL iterators.
template<class Category, class BaseIterator, class ItemType, bool IsConstant>
class NCollection_StlIterator : private BaseIterator,
public std::iterator<Category, ItemType, ptrdiff_t,
typename opencascade::conditional<IsConstant, const ItemType*, ItemType*>::type,
typename opencascade::conditional<IsConstant, const ItemType&, ItemType&>::type>
{
public:
//! Default constructor
NCollection_StlIterator () {}
//! Constructor from NCollection iterator
NCollection_StlIterator (const BaseIterator& theIterator)
: BaseIterator (theIterator)
{ }
//! Cast from non-const variant to const one
NCollection_StlIterator (const NCollection_StlIterator<Category, BaseIterator, ItemType, false>& theIterator)
: BaseIterator (theIterator)
{ }
//! Assignment of non-const iterator to const one
NCollection_StlIterator& operator= (const NCollection_StlIterator<Category, BaseIterator, ItemType, false>& theIterator)
{
BaseIterator::operator= (theIterator);
return *this;
}
friend class NCollection_StlIterator<Category, BaseIterator, ItemType, !IsConstant>;
protected: //! @name methods related to forward STL iterator
// Note: Here we use SFINAE (Substitution failure is not an error) to choose
// an appropriate method based on template arguments (at instantiation time).
template<bool Condition>
typename opencascade::enable_if<!Condition, ItemType&>::type Reference()
{
return BaseIterator::ChangeValue();
}
template<bool Condition>
typename opencascade::enable_if<Condition, const ItemType&>::type Reference()
{
return BaseIterator::Value();
}
public: //! @name methods related to forward STL iterator
//! Test for equality
bool operator== (const NCollection_StlIterator& theOther) const
{
return BaseIterator::More() == theOther.More() &&
(!BaseIterator::More() || BaseIterator::IsEqual (theOther));
}
//! Test for inequality
bool operator!= (const NCollection_StlIterator& theOther) const
{
return !(*this == theOther);
}
//! Get reference to current item
typename NCollection_StlIterator::reference operator*()
{
return Reference<IsConstant>();
}
//! Dereferencing operator
typename NCollection_StlIterator::pointer operator->()
{
return &Reference<IsConstant>();
}
//! Prefix increment
NCollection_StlIterator& operator++()
{
BaseIterator::Next();
return *this;
}
//! Postfix increment
NCollection_StlIterator operator++(int)
{
const NCollection_StlIterator theOld (*this);
++(*this);
return theOld;
}
public: //! @name methods related to bidirectional STL iterator
//! Prefix decrement
NCollection_StlIterator& operator--()
{
Standard_STATIC_ASSERT((opencascade::is_same<std::bidirectional_iterator_tag,Category>::value ||
opencascade::is_same<std::random_access_iterator_tag,Category>::value));
BaseIterator::Previous();
return *this;
}
//! Postfix decrement
NCollection_StlIterator operator--(int)
{
NCollection_StlIterator theOld (*this);
--(*this);
return theOld;
}
public: //! @name methods related to random access STL iterator
//! Move forward
NCollection_StlIterator& operator+= (typename NCollection_StlIterator::difference_type theOffset)
{
Standard_STATIC_ASSERT((opencascade::is_same<std::random_access_iterator_tag,Category>::value));
BaseIterator::Offset (theOffset);
return *this;
}
//! Addition
NCollection_StlIterator operator+ (typename NCollection_StlIterator::difference_type theOffset) const
{
NCollection_StlIterator aTemp (*this);
return aTemp += theOffset;
}
//! Move backward
NCollection_StlIterator& operator-= (typename NCollection_StlIterator::difference_type theOffset)
{
return *this += -theOffset;
}
//! Decrease
NCollection_StlIterator operator- (typename NCollection_StlIterator::difference_type theOffset) const
{
NCollection_StlIterator aTemp (*this);
return aTemp += -theOffset;
}
//! Difference
typename NCollection_StlIterator::difference_type operator- (const NCollection_StlIterator& theOther) const
{
Standard_STATIC_ASSERT((opencascade::is_same<std::random_access_iterator_tag,Category>::value));
return BaseIterator::Differ (theOther);
}
//! Get item at offset from current
typename NCollection_StlIterator::reference operator[] (typename NCollection_StlIterator::difference_type theOffset) const
{
return *(*this + theOffset);
}
//! Comparison
bool operator< (const NCollection_StlIterator& theOther) const
{
return (*this - theOther) < 0;
}
//! Comparison
bool operator> (const NCollection_StlIterator& theOther) const
{
return theOther < *this;
}
//! Comparison
bool operator<= (const NCollection_StlIterator& theOther) const
{
return !(theOther < *this);
}
//! Comparison
bool operator>= (const NCollection_StlIterator& theOther) const
{
return !(*this < theOther);
}
};
#endif // NCollection_StlIterator_HeaderFile

View File

@ -18,6 +18,7 @@
#include <NCollection_BaseVector.hxx> #include <NCollection_BaseVector.hxx>
#include <NCollection_BaseCollection.hxx> #include <NCollection_BaseCollection.hxx>
#include <NCollection_StlIterator.hxx>
//! Class NCollection_Vector (dynamic array of objects) //! Class NCollection_Vector (dynamic array of objects)
//! //!
@ -45,8 +46,10 @@ template <class TheItemType> class NCollection_Vector
public NCollection_BaseVector public NCollection_BaseVector
{ {
public: public:
//! STL-compliant typedef for value type
typedef TheItemType value_type;
typedef TheItemType TheItemTypeD; public:
//! Nested class Iterator //! Nested class Iterator
class Iterator : public NCollection_BaseCollection<TheItemType>::Iterator, class Iterator : public NCollection_BaseCollection<TheItemType>::Iterator,
@ -58,8 +61,8 @@ public:
Iterator() {} Iterator() {}
//! Constructor with initialisation //! Constructor with initialisation
Iterator (const NCollection_Vector& theVector) Iterator (const NCollection_Vector& theVector, Standard_Boolean theToEnd = Standard_False)
: NCollection_BaseVector::Iterator (theVector) {} : NCollection_BaseVector::Iterator (theVector, theToEnd) {}
//! Copy constructor //! Copy constructor
Iterator (const Iterator& theOther) Iterator (const Iterator& theOther)
@ -84,12 +87,30 @@ public:
return moreV(); return moreV();
} }
//! Make step //! Increment operator.
virtual void Next() virtual void Next()
{ {
nextV(); nextV();
} }
//! Decrement operator.
virtual void Previous()
{
prevV();
}
//! Offset operator.
virtual void Offset (ptrdiff_t theOffset)
{
offsetV ((int)theOffset);
}
//! Difference operator.
virtual ptrdiff_t Differ (const Iterator& theOther) const
{
return differV (theOther);
}
//! Constant value access //! Constant value access
virtual const TheItemType& Value() const virtual const TheItemType& Value() const
{ {
@ -102,8 +123,35 @@ public:
return ((TheItemType* )curBlockV()->DataPtr)[myCurIndex]; return ((TheItemType* )curBlockV()->DataPtr)[myCurIndex];
} }
//! Performs comparison of two iterators.
virtual Standard_Boolean IsEqual (const Iterator& theOther) const
{
return myVector == theOther.myVector
&& myCurIndex == theOther.myCurIndex
&& myEndIndex == theOther.myEndIndex
&& myICurBlock == theOther.myICurBlock
&& myIEndBlock == theOther.myIEndBlock;
}
}; };
//! Shorthand for a regular iterator type.
typedef NCollection_StlIterator<std::random_access_iterator_tag, Iterator, TheItemType, false> iterator;
//! Shorthand for a constant iterator type.
typedef NCollection_StlIterator<std::random_access_iterator_tag, Iterator, TheItemType, true> const_iterator;
//! Returns an iterator pointing to the first element in the vector.
iterator begin() const { return Iterator (*this, false); }
//! Returns an iterator referring to the past-the-end element in the vector.
iterator end() const { return Iterator (*this, true); }
//! Returns a const iterator pointing to the first element in the vector.
const_iterator cbegin() const { return Iterator (*this, false); }
//! Returns a const iterator referring to the past-the-end element in the vector.
const_iterator cend() const { return Iterator (*this, true); }
public: //! @name public methods public: //! @name public methods
//! Constructor //! Constructor
@ -297,7 +345,7 @@ private: //! @name private methods
{ {
for (Standard_Integer anItemIter = 0; anItemIter < theBlock.Size; ++anItemIter) for (Standard_Integer anItemIter = 0; anItemIter < theBlock.Size; ++anItemIter)
{ {
((TheItemType* )theBlock.DataPtr)[anItemIter].~TheItemTypeD(); ((TheItemType* )theBlock.DataPtr)[anItemIter].~TheItemType();
} }
anAllocator->Free (theBlock.DataPtr); anAllocator->Free (theBlock.DataPtr);
theBlock.DataPtr = NULL; theBlock.DataPtr = NULL;

View File

@ -5,6 +5,7 @@ QANCollection1.cxx
QANCollection2.cxx QANCollection2.cxx
QANCollection3.cxx QANCollection3.cxx
QANCollection4.cxx QANCollection4.cxx
QANCollection_Stl.cxx
QANCollection_Common.cxx QANCollection_Common.cxx
QANCollection_Common.hxx QANCollection_Common.hxx
QANCollection_Common2.hxx QANCollection_Common2.hxx

View File

@ -51,5 +51,6 @@ is
Commands2(DI : in out Interpretor from Draw); Commands2(DI : in out Interpretor from Draw);
Commands3(DI : in out Interpretor from Draw); Commands3(DI : in out Interpretor from Draw);
Commands4(DI : in out Interpretor from Draw); Commands4(DI : in out Interpretor from Draw);
CommandsStl(DI : in out Interpretor from Draw);
end; end;

View File

@ -19,10 +19,11 @@
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
//#include <QANCollection_Common.hxx> //#include <QANCollection_Common.hxx>
void QANCollection::Commands(Draw_Interpretor& theCommands) { void QANCollection::Commands (Draw_Interpretor& theCommands)
{
QANCollection::Commands1 (theCommands); QANCollection::Commands1 (theCommands);
QANCollection::Commands2 (theCommands); QANCollection::Commands2 (theCommands);
QANCollection::Commands3 (theCommands); QANCollection::Commands3 (theCommands);
QANCollection::Commands4 (theCommands); QANCollection::Commands4 (theCommands);
return; QANCollection::CommandsStl (theCommands);
} }

File diff suppressed because it is too large Load Diff

View File

@ -1356,7 +1356,7 @@ QANewModTopOpe_Glue::SectionInsideFace(const TopoDS_Face& theFace,
// check if vertices of aSEdge contacts edges of aFace // check if vertices of aSEdge contacts edges of aFace
TopoDS_Iterator aIter (aSEdge, Standard_False); TopoDS_Iterator aIter (aSEdge, Standard_False);
for (; aIter.More(); aIter.Next()) { for (; aIter.More(); aIter.Next()) {
const TopoDS_Vertex& aSVer = TopoDS::Vertex (aIter.Value()); TopoDS_Vertex aSVer = TopoDS::Vertex (aIter.Value());
if (aSVer.Orientation() != TopAbs_FORWARD && if (aSVer.Orientation() != TopAbs_FORWARD &&
aSVer.Orientation() != TopAbs_REVERSED) continue; aSVer.Orientation() != TopAbs_REVERSED) continue;

View File

@ -31,9 +31,6 @@
#include <TopTools_IndexedMapOfShape.hxx> #include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_DataMapOfIntegerShape.hxx> #include <TopTools_DataMapOfIntegerShape.hxx>
#include <TCollection_CompareOfReal.hxx>
#include <SortTools_QuickSortOfReal.hxx>
#include <TColStd_Array1OfReal.hxx> #include <TColStd_Array1OfReal.hxx>
#include <TColStd_IndexedMapOfReal.hxx> #include <TColStd_IndexedMapOfReal.hxx>
#include <TColStd_ListOfInteger.hxx> #include <TColStd_ListOfInteger.hxx>
@ -48,6 +45,9 @@
#include <BOPDS_CommonBlock.hxx> #include <BOPDS_CommonBlock.hxx>
#include <BOPTools_AlgoTools3D.hxx> #include <BOPTools_AlgoTools3D.hxx>
#include <NCollection_Array1.hxx>
#include <algorithm>
static Standard_Boolean AddShapeToHistoryMap(const TopoDS_Shape& theOldShape, static Standard_Boolean AddShapeToHistoryMap(const TopoDS_Shape& theOldShape,
const TopoDS_Shape& theNewShape, const TopoDS_Shape& theNewShape,
TopTools_IndexedDataMapOfShapeListOfShape& theHistoryMap); TopTools_IndexedDataMapOfShapeListOfShape& theHistoryMap);
@ -815,7 +815,7 @@ void SortVertexOnEdge(const TopoDS_Edge& theEdge,
mapiv.Bind(iv,v); mapiv.Bind(iv,v);
} }
Standard_Integer nv = mapiv.Extent(); Standard_Integer nv = mapiv.Extent();
TColStd_Array1OfReal tabpar(1,nv); NCollection_Array1<Standard_Real> tabpar(1,nv);
Standard_Integer i = 0; Standard_Integer i = 0;
for ( i = 1; i <= nv; i++) { for ( i = 1; i <= nv; i++) {
@ -823,8 +823,7 @@ void SortVertexOnEdge(const TopoDS_Edge& theEdge,
tabpar.SetValue(i,p); tabpar.SetValue(i,p);
} }
theListOfVertexSorted.Clear(); theListOfVertexSorted.Clear();
TCollection_CompareOfReal compare; std::sort (tabpar.begin(), tabpar.end());
SortTools_QuickSortOfReal::Sort(tabpar, compare);
for (i = 1; i <= nv; i++) { for (i = 1; i <= nv; i++) {
Standard_Real par = tabpar.Value(i); Standard_Real par = tabpar.Value(i);

View File

@ -41,8 +41,7 @@
#include <TopTools_DataMapOfIntegerShape.hxx> #include <TopTools_DataMapOfIntegerShape.hxx>
#include <TColStd_Array1OfReal.hxx> #include <TColStd_Array1OfReal.hxx>
#include <TColStd_IndexedMapOfReal.hxx> #include <TColStd_IndexedMapOfReal.hxx>
#include <TCollection_CompareOfReal.hxx> #include <NCollection_Array1.hxx>
#include <SortTools_QuickSortOfReal.hxx>
#include <BRepLProp_CLProps.hxx> #include <BRepLProp_CLProps.hxx>
#include <GeomLProp_SLProps.hxx> #include <GeomLProp_SLProps.hxx>
#include <gp_Torus.hxx> #include <gp_Torus.hxx>
@ -51,6 +50,7 @@
#include <Bnd_Box.hxx> #include <Bnd_Box.hxx>
#include <BRepBndLib.hxx> #include <BRepBndLib.hxx>
#include <ElCLib.hxx> #include <ElCLib.hxx>
#include <algorithm>
#define M_FORWARD(sta) (sta == TopAbs_FORWARD) #define M_FORWARD(sta) (sta == TopAbs_FORWARD)
#define M_REVERSED(sta) (sta == TopAbs_REVERSED) #define M_REVERSED(sta) (sta == TopAbs_REVERSED)
@ -335,7 +335,7 @@ static void FUN_tool_sortVonE(TopTools_ListOfShape& lov, const TopoDS_Edge E)
mapiv.Bind(iv,v); mapiv.Bind(iv,v);
} }
Standard_Integer nv = mapiv.Extent(); Standard_Integer nv = mapiv.Extent();
TColStd_Array1OfReal tabpar(1,nv); NCollection_Array1<Standard_Real> tabpar(1,nv);
// for (Standard_Integer i = 1; i <= nv; i++) { // for (Standard_Integer i = 1; i <= nv; i++) {
Standard_Integer i ; Standard_Integer i ;
for ( i = 1; i <= nv; i++) { for ( i = 1; i <= nv; i++) {
@ -344,7 +344,7 @@ static void FUN_tool_sortVonE(TopTools_ListOfShape& lov, const TopoDS_Edge E)
} }
TopTools_ListOfShape newlov; TopTools_ListOfShape newlov;
TCollection_CompareOfReal compare; SortTools_QuickSortOfReal::Sort(tabpar, compare); std::sort (tabpar.begin(), tabpar.end());
for (i = 1; i <= nv; i++) { for (i = 1; i <= nv; i++) {
Standard_Real par = tabpar.Value(i); Standard_Real par = tabpar.Value(i);
Standard_Integer iv = mappar.FindIndex(par); Standard_Integer iv = mappar.FindIndex(par);