0023024: Update headers of OCCT files
[occt.git] / src / NCollection / NCollection_BaseSequence.hxx
CommitLineData
b311480e 1// Created on: 2002-04-10
2// Created by: Alexander KARTOMIN (akm)
3// Copyright (c) 2002-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22#ifndef NCollection_BaseSequence_HeaderFile
23#define NCollection_BaseSequence_HeaderFile
24
25#include <Standard.hxx>
26#include <NCollection_BaseAllocator.hxx>
27
28// **************************************** Class SeqNode ********************
29
30class NCollection_SeqNode
31{
32 public:
33 // Methods PUBLIC
34 //
35 NCollection_SeqNode (void)
36 : myNext (NULL), myPrevious (NULL) {}
37 const NCollection_SeqNode * Next () const { return myNext; }
38 const NCollection_SeqNode * Previous () const { return myPrevious; }
39 void SetNext (const NCollection_SeqNode * theNext)
40 { myNext = theNext; }
41 void SetPrevious (const NCollection_SeqNode * thePrev)
42 { myPrevious = thePrev; }
43 //~NCollection_SeqNode() {
44 // if (myNext) myNext -> myPrevious = myPrevious;
45 // if (myPrevious) myPrevious -> myNext = myNext;
46 //}
47
48 private:
49 // Fields PRIVATE
50 //
51 const NCollection_SeqNode * myNext;
52 const NCollection_SeqNode * myPrevious;
53};
54
55typedef void (* NCollection_DelSeqNode)
56 (NCollection_SeqNode*, Handle(NCollection_BaseAllocator)& theAl);
57
58/**
59 * Purpose: This is a base class for the Sequence. It deals with
60 * an indexed bidirectional list of NCollection_SeqNode's.
61 */
62class NCollection_BaseSequence
63{
64 public:
65 class Iterator
66 {
67 public:
68 //! Empty constructor
69 Iterator (void) : myCurrent (NULL) {}
70 //! Constructor with initialisation
71 Iterator (const NCollection_BaseSequence& theSeq,
72 const Standard_Boolean isStart)
73 : myCurrent(isStart ? (NCollection_SeqNode *)theSeq.myFirstItem
74 : (NCollection_SeqNode *)theSeq.myLastItem) {}
75 //! Initialisation
76 void Init (const NCollection_BaseSequence& theSeq,
77 const Standard_Boolean isStart
78 = Standard_True)
79 { myCurrent = isStart ? (NCollection_SeqNode *)theSeq.myFirstItem
80 : (NCollection_SeqNode *)theSeq.myLastItem; }
81 //! Assignment
82 Iterator& operator = (const Iterator& theOther)
83 { myCurrent = theOther.myCurrent; return *this; }
84 //! Previous
85 void Previous ()
86 { if (myCurrent)
87 myCurrent = (NCollection_SeqNode *)myCurrent -> Previous(); }
88
89 protected:
90 NCollection_SeqNode * myCurrent; //!< Pointer to the current node
91 friend class NCollection_BaseSequence;
92 };
93
94 public:
95 // Methods PUBLIC
96 //
97 Standard_Boolean IsEmpty () const {return (mySize == 0);}
98 Standard_Integer Length () const {return mySize;}
99
100 protected:
101 // Methods PROTECTED
102 //
103 inline NCollection_BaseSequence ();
104 Standard_EXPORT void ClearSeq (NCollection_DelSeqNode fDel,
105 Handle(NCollection_BaseAllocator)& theAl);
106 Standard_EXPORT void PAppend (NCollection_SeqNode *);
107 Standard_EXPORT void PAppend (NCollection_BaseSequence& S);
108 Standard_EXPORT void PPrepend (NCollection_SeqNode *);
109 Standard_EXPORT void PPrepend (NCollection_BaseSequence& S);
110 Standard_EXPORT void PInsertAfter(Iterator& thePosition,
111 NCollection_SeqNode *);
112 Standard_EXPORT void PInsertAfter(const Standard_Integer Index,
113 NCollection_SeqNode *);
114 Standard_EXPORT void PInsertAfter(const Standard_Integer Index,
115 NCollection_BaseSequence& S);
116 Standard_EXPORT void PSplit (const Standard_Integer Index,
117 NCollection_BaseSequence& Sub);
118 Standard_EXPORT void RemoveSeq (Iterator& thePosition,
119 NCollection_DelSeqNode fDel,
120 Handle(NCollection_BaseAllocator)& theAl);
121 Standard_EXPORT void RemoveSeq (const Standard_Integer Index,
122 NCollection_DelSeqNode fDel,
123 Handle(NCollection_BaseAllocator)& theAl);
124 Standard_EXPORT void RemoveSeq (const Standard_Integer From,
125 const Standard_Integer To,
126 NCollection_DelSeqNode fDel,
127 Handle(NCollection_BaseAllocator)& theAl);
128 Standard_EXPORT void PReverse ();
129 Standard_EXPORT void PExchange (const Standard_Integer I,
130 const Standard_Integer J) ;
131 Standard_EXPORT const NCollection_SeqNode *
132 Find (const Standard_Integer) const;
133
134 protected:
135 // Fields PROTECTED
136 //
137 const NCollection_SeqNode * myFirstItem;
138 const NCollection_SeqNode * myLastItem;
139 const NCollection_SeqNode * myCurrentItem;
140 Standard_Integer myCurrentIndex;
141 Standard_Integer mySize;
142
143 private:
144 // Methods PRIVATE
145 //
146 Standard_EXPORT NCollection_BaseSequence
147 (const NCollection_BaseSequence& Other);
148 inline void Nullify ();
149 friend class Iterator;
150};
151
152inline NCollection_BaseSequence::NCollection_BaseSequence ()
153 : myFirstItem (NULL),
154 myLastItem (NULL),
155 myCurrentItem (NULL),
156 myCurrentIndex (0),
157 mySize (0) {}
158
159inline void NCollection_BaseSequence::Nullify ()
160{
161 myFirstItem = myLastItem = myCurrentItem = NULL;
162 myCurrentIndex = mySize = 0;
163}
164
165#endif