0023951: Visibility of free, simple shapes not saved when writing XCAF Document into...
[occt.git] / src / NCollection / NCollection_BaseSequence.hxx
CommitLineData
b311480e 1// Created on: 2002-04-10
2// Created by: Alexander KARTOMIN (akm)
973c2be1 3// Copyright (c) 2002-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#ifndef NCollection_BaseSequence_HeaderFile
17#define NCollection_BaseSequence_HeaderFile
18
19#include <Standard.hxx>
20#include <NCollection_BaseAllocator.hxx>
21
22// **************************************** Class SeqNode ********************
23
24class NCollection_SeqNode
25{
26 public:
27 // Methods PUBLIC
28 //
29 NCollection_SeqNode (void)
30 : myNext (NULL), myPrevious (NULL) {}
31 const NCollection_SeqNode * Next () const { return myNext; }
32 const NCollection_SeqNode * Previous () const { return myPrevious; }
33 void SetNext (const NCollection_SeqNode * theNext)
34 { myNext = theNext; }
35 void SetPrevious (const NCollection_SeqNode * thePrev)
36 { myPrevious = thePrev; }
37 //~NCollection_SeqNode() {
38 // if (myNext) myNext -> myPrevious = myPrevious;
39 // if (myPrevious) myPrevious -> myNext = myNext;
40 //}
41
42 private:
43 // Fields PRIVATE
44 //
45 const NCollection_SeqNode * myNext;
46 const NCollection_SeqNode * myPrevious;
47};
48
49typedef void (* NCollection_DelSeqNode)
50 (NCollection_SeqNode*, Handle(NCollection_BaseAllocator)& theAl);
51
52/**
53 * Purpose: This is a base class for the Sequence. It deals with
54 * an indexed bidirectional list of NCollection_SeqNode's.
55 */
56class NCollection_BaseSequence
57{
58 public:
59 class Iterator
60 {
61 public:
62 //! Empty constructor
63 Iterator (void) : myCurrent (NULL) {}
64 //! Constructor with initialisation
65 Iterator (const NCollection_BaseSequence& theSeq,
66 const Standard_Boolean isStart)
67 : myCurrent(isStart ? (NCollection_SeqNode *)theSeq.myFirstItem
68 : (NCollection_SeqNode *)theSeq.myLastItem) {}
69 //! Initialisation
70 void Init (const NCollection_BaseSequence& theSeq,
71 const Standard_Boolean isStart
72 = Standard_True)
73 { myCurrent = isStart ? (NCollection_SeqNode *)theSeq.myFirstItem
74 : (NCollection_SeqNode *)theSeq.myLastItem; }
75 //! Assignment
76 Iterator& operator = (const Iterator& theOther)
77 { myCurrent = theOther.myCurrent; return *this; }
78 //! Previous
79 void Previous ()
80 { if (myCurrent)
81 myCurrent = (NCollection_SeqNode *)myCurrent -> Previous(); }
82
83 protected:
84 NCollection_SeqNode * myCurrent; //!< Pointer to the current node
85 friend class NCollection_BaseSequence;
86 };
87
88 public:
89 // Methods PUBLIC
90 //
91 Standard_Boolean IsEmpty () const {return (mySize == 0);}
92 Standard_Integer Length () const {return mySize;}
93
94 protected:
95 // Methods PROTECTED
96 //
97 inline NCollection_BaseSequence ();
98 Standard_EXPORT void ClearSeq (NCollection_DelSeqNode fDel,
99 Handle(NCollection_BaseAllocator)& theAl);
100 Standard_EXPORT void PAppend (NCollection_SeqNode *);
101 Standard_EXPORT void PAppend (NCollection_BaseSequence& S);
102 Standard_EXPORT void PPrepend (NCollection_SeqNode *);
103 Standard_EXPORT void PPrepend (NCollection_BaseSequence& S);
104 Standard_EXPORT void PInsertAfter(Iterator& thePosition,
105 NCollection_SeqNode *);
106 Standard_EXPORT void PInsertAfter(const Standard_Integer Index,
107 NCollection_SeqNode *);
108 Standard_EXPORT void PInsertAfter(const Standard_Integer Index,
109 NCollection_BaseSequence& S);
110 Standard_EXPORT void PSplit (const Standard_Integer Index,
111 NCollection_BaseSequence& Sub);
112 Standard_EXPORT void RemoveSeq (Iterator& thePosition,
113 NCollection_DelSeqNode fDel,
114 Handle(NCollection_BaseAllocator)& theAl);
115 Standard_EXPORT void RemoveSeq (const Standard_Integer Index,
116 NCollection_DelSeqNode fDel,
117 Handle(NCollection_BaseAllocator)& theAl);
118 Standard_EXPORT void RemoveSeq (const Standard_Integer From,
119 const Standard_Integer To,
120 NCollection_DelSeqNode fDel,
121 Handle(NCollection_BaseAllocator)& theAl);
122 Standard_EXPORT void PReverse ();
123 Standard_EXPORT void PExchange (const Standard_Integer I,
124 const Standard_Integer J) ;
125 Standard_EXPORT const NCollection_SeqNode *
126 Find (const Standard_Integer) const;
127
128 protected:
129 // Fields PROTECTED
130 //
131 const NCollection_SeqNode * myFirstItem;
132 const NCollection_SeqNode * myLastItem;
133 const NCollection_SeqNode * myCurrentItem;
134 Standard_Integer myCurrentIndex;
135 Standard_Integer mySize;
136
137 private:
138 // Methods PRIVATE
139 //
140 Standard_EXPORT NCollection_BaseSequence
141 (const NCollection_BaseSequence& Other);
142 inline void Nullify ();
143 friend class Iterator;
144};
145
146inline NCollection_BaseSequence::NCollection_BaseSequence ()
147 : myFirstItem (NULL),
148 myLastItem (NULL),
149 myCurrentItem (NULL),
150 myCurrentIndex (0),
151 mySize (0) {}
152
153inline void NCollection_BaseSequence::Nullify ()
154{
155 myFirstItem = myLastItem = myCurrentItem = NULL;
156 myCurrentIndex = mySize = 0;
157}
158
159#endif