2 // Created: Wed Jun 24 12:47:46 1992
3 // Author: Gilles DEBARBOUILLE
7 //=======================================================================
10 //=======================================================================
12 MAT_TList::MAT_TList()
18 //=======================================================================
21 //=======================================================================
23 void MAT_TList::First()
25 thecurrentnode = thefirstnode;
29 //=======================================================================
32 //=======================================================================
34 void MAT_TList::Last()
36 thecurrentnode = thelastnode;
37 thecurrentindex = thenumberofitems;
40 //=======================================================================
43 //=======================================================================
45 void MAT_TList::Init(const Item& anitem)
50 if(anitem == thecurrentnode->GetItem()) break;
55 //=======================================================================
58 //=======================================================================
60 void MAT_TList::Next()
64 thecurrentnode = thecurrentnode->Next();
65 thecurrentindex = (thecurrentindex % thenumberofitems) + 1;
69 //=======================================================================
72 //=======================================================================
74 void MAT_TList::Previous()
78 thecurrentnode = thecurrentnode->Previous();
79 thecurrentindex = ((thecurrentindex+thenumberofitems-2)%thenumberofitems)+1;
83 //=======================================================================
86 //=======================================================================
88 Standard_Boolean MAT_TList::More() const
90 return (!thecurrentnode.IsNull());
93 //=======================================================================
96 //=======================================================================
98 Item MAT_TList::Current() const
100 return thecurrentnode->GetItem();
103 //=======================================================================
106 //=======================================================================
108 void MAT_TList::Current(const Item& anitem) const
110 thecurrentnode->SetItem(anitem);
113 //=======================================================================
114 //function : FirstItem
116 //=======================================================================
118 Item MAT_TList::FirstItem() const
120 return thefirstnode->GetItem();
123 //=======================================================================
124 //function : LastItem
126 //=======================================================================
128 Item MAT_TList::LastItem() const
130 return thelastnode->GetItem();
133 //=======================================================================
134 //function : PreviousItem
136 //=======================================================================
138 Item MAT_TList::PreviousItem() const
140 return thecurrentnode->Previous()->GetItem();
143 //=======================================================================
144 //function : NextItem
146 //=======================================================================
148 Item MAT_TList::NextItem() const
150 return thecurrentnode->Next()->GetItem();
153 //=======================================================================
154 //function : Brackets
156 //=======================================================================
158 Item MAT_TList::Brackets (const Standard_Integer anindex)
160 if(thecurrentindex > anindex)
162 while(thecurrentindex != anindex)
165 thecurrentnode = thecurrentnode->Previous();
168 else if(thecurrentindex < anindex)
170 while(thecurrentindex != anindex)
173 thecurrentnode = thecurrentnode->Next();
176 return thecurrentnode->GetItem();
179 //=======================================================================
182 //=======================================================================
184 void MAT_TList::Unlink()
186 Standard_Boolean previousisnull = thecurrentnode->Previous().IsNull();
187 Standard_Boolean nextisnull = thecurrentnode->Next().IsNull();
191 if(!nextisnull && !previousisnull)
193 thecurrentnode->Next()->Previous(thecurrentnode->Previous());
194 thecurrentnode->Previous()->Next(thecurrentnode->Next());
197 if(thecurrentindex == 1)
199 thefirstnode = thecurrentnode->Next();
201 else if(thecurrentindex == thenumberofitems)
203 thelastnode = thecurrentnode->Previous();
210 //=======================================================================
211 //function : LinkBefore
213 //=======================================================================
215 void MAT_TList::LinkBefore(const Item& anitem)
218 if(thecurrentindex)thecurrentindex++;
220 Handle(MAT_TListNode) previous;
222 Handle(MAT_TListNode) node = new MAT_TListNode(anitem);
224 if(!(thecurrentnode->Previous()).IsNull())
226 previous = thecurrentnode->Previous();
227 previous->Next(node);
228 node->Previous(previous);
231 if(thecurrentindex == 2)
236 thecurrentnode->Previous(node);
237 node->Next(thecurrentnode);
240 //=======================================================================
241 //function : LinkAfter
243 //=======================================================================
245 void MAT_TList::LinkAfter(const Item& anitem)
248 Handle(MAT_TListNode) next;
250 Handle(MAT_TListNode) node = new MAT_TListNode(anitem);
252 if(!(thecurrentnode->Next()).IsNull())
254 next = thecurrentnode->Next();
255 next->Previous(node);
259 if(thecurrentindex+1 ==thenumberofitems)
264 thecurrentnode->Next(node);
265 node->Previous(thecurrentnode);
268 //=======================================================================
269 //function : FrontAdd
271 //=======================================================================
273 void MAT_TList::FrontAdd(const Item& anitem)
276 if(thecurrentindex)thecurrentindex++;
278 Handle(MAT_TListNode) node = new MAT_TListNode(anitem);
280 if(!thefirstnode.IsNull())
282 thefirstnode->Previous(node);
283 node->Next(thefirstnode);
293 //=======================================================================
296 //=======================================================================
298 void MAT_TList::BackAdd(const Item& anitem)
301 Handle(MAT_TListNode) node = new MAT_TListNode(anitem);
303 if(!thelastnode.IsNull())
305 thelastnode->Next(node);
306 node->Previous(thelastnode);
316 //=======================================================================
319 //=======================================================================
321 void MAT_TList::Permute()
323 Handle(MAT_TListNode) previous = thecurrentnode->Previous();
324 Handle(MAT_TListNode) current = thecurrentnode;
325 Handle(MAT_TListNode) next = thecurrentnode->Next();
326 Handle(MAT_TListNode) nextnext = next->Next();
327 Handle(MAT_TListNode) null;
329 if(!previous.IsNull())
331 previous->Next(next);
332 next->Previous(previous);
336 next->Previous(null);
339 current->Previous(next);
340 if(!nextnext.IsNull())
342 current->Next(nextnext);
343 nextnext->Previous(current);
349 if(thefirstnode == current) thefirstnode = next;
350 if(thelastnode == next) thelastnode = current;
354 //=======================================================================
357 //=======================================================================
359 void MAT_TList::Loop() const
361 thelastnode->Next(thefirstnode);
362 thefirstnode->Previous(thelastnode);
365 //=======================================================================
368 //=======================================================================
370 void MAT_TList::Dump(const Standard_Integer ashift,
371 const Standard_Integer alevel)
373 for(First(); More(); Next()) Current()->Dump(ashift,alevel);