|
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // CMStack.inl |
|
15 // |
|
16 // |
|
17 |
|
18 #include <cmarkedstack.h> |
|
19 |
|
20 /** Destructor. |
|
21 |
|
22 It clears all marks. |
|
23 */ |
|
24 template <class T, TBool Owner> |
|
25 inline CMarkedStack<T, Owner>::~CMarkedStack() |
|
26 { |
|
27 iMarks.Clear(); |
|
28 } |
|
29 |
|
30 /** Marks the stack's head item. |
|
31 |
|
32 @param aMarkType Mark type |
|
33 */ |
|
34 template <class T, TBool Owner> |
|
35 void |
|
36 inline CMarkedStack<T, Owner>::MarkL(TInt aMarkType) |
|
37 { |
|
38 TMarkPoint* point = new (ELeave) TMarkPoint(aMarkType, this->Count()); |
|
39 iMarks.PushL(point); |
|
40 } |
|
41 |
|
42 /** Removes all marks until a mark of the specified type is found. |
|
43 |
|
44 @return Index of the stack item marked by the found mark |
|
45 @param aMarkType Mark type |
|
46 */ |
|
47 template <class T, TBool Owner> |
|
48 TInt |
|
49 inline CMarkedStack<T, Owner>::RemoveMark(TInt aMarkType) |
|
50 { |
|
51 TMarkPoint* point = NULL; |
|
52 do |
|
53 { |
|
54 delete point; |
|
55 point = iMarks.Pop(); |
|
56 } while (point->iMarkType != aMarkType); |
|
57 TInt stackIndex = point->iStackIndex; |
|
58 delete point; |
|
59 return stackIndex; |
|
60 } |
|
61 |
|
62 /** Pops and deletes items from the stack until the item marked with the specified mark type is at the head. |
|
63 |
|
64 @param aMarkType Mark type |
|
65 */ |
|
66 template <class T, TBool Owner> |
|
67 void |
|
68 inline CMarkedStack<T, Owner>::DeleteToMark(TInt aMarkType) |
|
69 { |
|
70 TInt lastMark = RemoveMark(aMarkType); |
|
71 while (this->Count() > lastMark) |
|
72 delete this->Pop(); |
|
73 } |
|
74 |
|
75 /** Pops items from the stack until the item marked with the specified mark type is at the head. |
|
76 |
|
77 @param aMarkType Mark type |
|
78 */ |
|
79 template <class T, TBool Owner> |
|
80 void |
|
81 inline CMarkedStack<T, Owner>::ResetToMark(TInt aMarkType) |
|
82 { |
|
83 TInt lastMark = RemoveMark(aMarkType); |
|
84 while (this->Count() > lastMark) |
|
85 this->Pop(); |
|
86 } |