b311480e |
1 | // Created on: 1992-09-24 |
2 | // Created by: Mireille MERCIEN |
3 | // Copyright (c) 1992-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | // ---------------------------------------------------------------------- |
7fd59977 |
18 | // Updated: Remi Lequette,J.P. TIRAULT February,23 1995 |
19 | // we added a basic class BaseSequence where all |
20 | // instantiations of Sequence inherit. |
21 | // ---------------------------------------------------------------------- |
22 | |
23 | static void delnode(TCollection_SeqNode* p) |
24 | { |
25 | TCollection_SequenceNode* q = (TCollection_SequenceNode*) p; |
26 | delete q; |
27 | } |
28 | |
29 | // ---------------------------------- |
30 | // Clear : Clear the Current Sequence |
31 | // ---------------------------------- |
32 | void TCollection_Sequence::Clear() |
33 | { |
34 | TCollection_BaseSequence::Clear((void*)&delnode); |
35 | } |
36 | |
37 | //======================================================================= |
38 | //function : Assign |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | const TCollection_Sequence& TCollection_Sequence::Assign |
43 | (const TCollection_Sequence& Other) |
44 | { |
45 | if (this == &Other) return *this; |
46 | Clear(); |
47 | TCollection_SequenceNode* current = (TCollection_SequenceNode*) Other.FirstItem; |
48 | TCollection_SequenceNode* previous = NULL; |
49 | TCollection_SequenceNode* newnode = NULL; |
50 | FirstItem = NULL; |
51 | while (current) { |
52 | newnode = new TCollection_SequenceNode(current->Value(),previous,(TCollection_SeqNode*)0L); |
53 | if (previous) previous->Next() = newnode; |
54 | else FirstItem = newnode; |
55 | current = (TCollection_SequenceNode *) current->Next(); |
56 | previous = newnode; |
57 | } |
58 | LastItem = newnode; |
59 | Size = Other.Size; |
60 | CurrentItem = FirstItem; |
61 | CurrentIndex = 1; |
62 | return *this; |
63 | } |
64 | |
65 | |
66 | // ------------------------------------------------- |
67 | // Append : Push an item at the end of the sequence |
68 | // ------------------------------------------------- |
69 | void TCollection_Sequence::Append(const SeqItem& T) |
70 | { |
71 | TCollection_SequenceNode* newnode = new TCollection_SequenceNode(T,(TCollection_SeqNode*)LastItem,(TCollection_SeqNode*)0L); |
72 | PAppend ((void*)newnode); |
73 | } |
74 | |
75 | |
76 | // --------------------------------------------------------- |
77 | // Prepend : Push an element at the begining of the sequence |
78 | // --------------------------------------------------------- |
79 | void TCollection_Sequence::Prepend(const SeqItem& T) |
80 | { |
81 | TCollection_SequenceNode* newnode = new TCollection_SequenceNode(T,(TCollection_SeqNode*)0L,(TCollection_SequenceNode*)FirstItem); |
82 | PPrepend ((void*)newnode); |
83 | } |
84 | |
85 | // ----------------------------------------------------------------- |
86 | // InsertAfter : Insert an element after a given index in a sequence |
87 | // ----------------------------------------------------------------- |
88 | void TCollection_Sequence::InsertAfter(const Standard_Integer Index, |
89 | const SeqItem& T) |
90 | { |
2d2b3d53 |
91 | Standard_OutOfRange_Raise_if (Index < 0 || Index > Size, "TCollection_Sequence::InsertAfter() - index is out of range"); |
7fd59977 |
92 | TCollection_SequenceNode* newnode = new TCollection_SequenceNode(T,(TCollection_SeqNode*)0L,(TCollection_SeqNode*)0L); |
93 | PInsertAfter (Index,(void*)newnode); |
94 | } |
95 | |
96 | // --------------------------------------------------- |
97 | // First : Returns the first element of the sequence |
98 | // Raises an exeption if the sequence is empty |
99 | // ---------------------------------------------------- |
100 | const SeqItem& TCollection_Sequence::First() const |
101 | { |
2d2b3d53 |
102 | Standard_NoSuchObject_Raise_if (Size == 0, "TCollection_Sequence::First() - sequence is empty"); |
7fd59977 |
103 | return ((TCollection_SequenceNode*) FirstItem)->Value(); |
104 | } |
105 | |
106 | // ---------------------------------------------------- |
107 | // Last : Returns the last element of the sequence |
108 | // Raises an exeption if the sequence is empty |
109 | // ---------------------------------------------------- |
110 | const SeqItem& TCollection_Sequence::Last() const |
111 | { |
2d2b3d53 |
112 | Standard_NoSuchObject_Raise_if (Size == 0, "TCollection_Sequence::Last() - sequence is empty"); |
7fd59977 |
113 | return ((TCollection_SequenceNode*) LastItem)->Value(); |
114 | } |
115 | |
116 | // ----------------------------------------- |
117 | // Value : Return the value of a given index |
118 | // ----------------------------------------- |
119 | const SeqItem& TCollection_Sequence::Value(const Standard_Integer Index) const |
120 | { |
2d2b3d53 |
121 | Standard_OutOfRange_Raise_if (Index <= 0 || Index > Size, "TCollection_Sequence::Value() - index is out of range"); |
7fd59977 |
122 | TCollection_Sequence* const aLocalTHIS = (TCollection_Sequence* const) this; |
123 | aLocalTHIS->CurrentItem = (TCollection_SequenceNode*) Find(Index); |
124 | aLocalTHIS->CurrentIndex = Index; |
125 | return ((TCollection_SequenceNode*)CurrentItem)->Value(); |
126 | } |
127 | |
128 | // ------------------------------------------------------- |
129 | // ChangeValue : Return the modifiable value of a given index |
130 | // ------------------------------------------------------- |
131 | SeqItem & TCollection_Sequence::ChangeValue(const Standard_Integer Index) |
132 | { |
2d2b3d53 |
133 | Standard_OutOfRange_Raise_if (Index <= 0 || Index > Size, "TCollection_Sequence::ChangeValue() - index is out of range"); |
7fd59977 |
134 | |
135 | CurrentItem = (TCollection_SequenceNode*) Find(Index); |
136 | CurrentIndex = Index; |
137 | return ((TCollection_SequenceNode*)CurrentItem)->Value(); |
138 | } |
139 | |
140 | void TCollection_Sequence::Remove(const Standard_Integer Index) |
141 | { |
142 | TCollection_BaseSequence::Remove(Index,(void*)&delnode); |
143 | } |
144 | |
145 | // --------------------- |
146 | // Remove a set of items |
147 | // --------------------- |
148 | void TCollection_Sequence::Remove(const Standard_Integer FromIndex, const Standard_Integer ToIndex) |
149 | { |
150 | TCollection_BaseSequence::Remove(FromIndex,ToIndex,(void*)&delnode); |
151 | } |
152 | |
153 | |
154 | //======================================================================= |
155 | //function : SetValue |
156 | //purpose : Sets a value to an index |
157 | //======================================================================= |
158 | void TCollection_Sequence::SetValue (const Standard_Integer Index, |
159 | const SeqItem& I) |
160 | { |
161 | ChangeValue(Index) = I ; |
162 | } |