1 // Created on: 2002-04-10
2 // Created by: Alexander KARTOMIN (akm)
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef NCollection_BaseSequence_HeaderFile
17 #define NCollection_BaseSequence_HeaderFile
19 #include <Standard.hxx>
20 #include <NCollection_BaseAllocator.hxx>
21 #include <NCollection_DefineAlloc.hxx>
23 // **************************************** Class SeqNode ********************
25 class NCollection_SeqNode
28 // define new operator for use with NCollection allocators
29 DEFINE_NCOLLECTION_ALLOC
31 NCollection_SeqNode () : myNext (NULL), myPrevious (NULL) {}
32 NCollection_SeqNode * Next () const { return myNext; }
33 NCollection_SeqNode * Previous () const { return myPrevious; }
34 void SetNext (NCollection_SeqNode * theNext) { myNext = theNext; }
35 void SetPrevious (NCollection_SeqNode * thePrev) { myPrevious = thePrev; }
38 NCollection_SeqNode* myNext;
39 NCollection_SeqNode* myPrevious;
42 typedef void (* NCollection_DelSeqNode)
43 (NCollection_SeqNode*, Handle(NCollection_BaseAllocator)& theAl);
46 * Purpose: This is a base class for the Sequence. It deals with
47 * an indexed bidirectional list of NCollection_SeqNode's.
49 class NCollection_BaseSequence
54 DEFINE_NCOLLECTION_ALLOC
61 Iterator (void) : myCurrent (NULL), myPrevious(NULL) {}
63 //! Constructor with initialisation
64 Iterator (const NCollection_BaseSequence& theSeq,
65 const Standard_Boolean isStart)
67 Init (theSeq, isStart);
71 void Init (const NCollection_BaseSequence& theSeq,
72 const Standard_Boolean isStart = Standard_True)
74 myCurrent = (isStart ? theSeq.myFirstItem : NULL);
75 myPrevious = (isStart ? NULL : theSeq.myLastItem);
79 Iterator& operator = (const Iterator& theOther)
81 myCurrent = theOther.myCurrent;
82 myPrevious = theOther.myPrevious;
85 //! Switch to previous element; note that it will reset
88 myCurrent = myPrevious;
90 myPrevious = myCurrent->Previous();
94 NCollection_SeqNode* myCurrent; //!< Pointer to the current node
95 NCollection_SeqNode* myPrevious; //!< Pointer to the previous node
96 friend class NCollection_BaseSequence;
102 Standard_Boolean IsEmpty () const {return (mySize == 0);}
103 Standard_Integer Length () const {return mySize;}
108 NCollection_BaseSequence (const Handle(NCollection_BaseAllocator)& theAllocator) :
111 myCurrentItem (NULL),
115 myAllocator = (theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator);
118 Standard_EXPORT void ClearSeq (NCollection_DelSeqNode fDel);
119 Standard_EXPORT void PAppend (NCollection_SeqNode *);
120 Standard_EXPORT void PAppend (NCollection_BaseSequence& S);
121 Standard_EXPORT void PPrepend (NCollection_SeqNode *);
122 Standard_EXPORT void PPrepend (NCollection_BaseSequence& S);
123 Standard_EXPORT void PInsertAfter(Iterator& thePosition,
124 NCollection_SeqNode *);
125 Standard_EXPORT void PInsertAfter(const Standard_Integer Index,
126 NCollection_SeqNode *);
127 Standard_EXPORT void PInsertAfter(const Standard_Integer Index,
128 NCollection_BaseSequence& S);
129 Standard_EXPORT void PSplit (const Standard_Integer Index,
130 NCollection_BaseSequence& Sub);
131 Standard_EXPORT void RemoveSeq (Iterator& thePosition,
132 NCollection_DelSeqNode fDel);
133 Standard_EXPORT void RemoveSeq (const Standard_Integer Index,
134 NCollection_DelSeqNode fDel);
135 Standard_EXPORT void RemoveSeq (const Standard_Integer From,
136 const Standard_Integer To,
137 NCollection_DelSeqNode fDel);
138 Standard_EXPORT void PReverse ();
139 Standard_EXPORT void PExchange (const Standard_Integer I,
140 const Standard_Integer J) ;
141 Standard_EXPORT NCollection_SeqNode *
142 Find (const Standard_Integer) const;
147 Handle(NCollection_BaseAllocator) myAllocator;
148 NCollection_SeqNode* myFirstItem;
149 NCollection_SeqNode* myLastItem;
150 NCollection_SeqNode* myCurrentItem;
151 Standard_Integer myCurrentIndex;
152 Standard_Integer mySize;
157 Standard_EXPORT NCollection_BaseSequence
158 (const NCollection_BaseSequence& Other);
159 inline void Nullify ();
160 friend class Iterator;