1 // Copyright (c) 2000-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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __CSTACK_INL__ |
|
17 #define __CSTACK_INL__ |
|
18 |
|
19 // constants |
|
20 const TInt KStackGranularity=32; |
|
21 |
|
22 enum TCStackPanic |
|
23 { |
|
24 ECStackErrStackIsEmpty, |
|
25 ECStackDeleteWhenNotOwner, |
|
26 ECStackPopsWhenOwner |
|
27 }; |
|
28 |
|
29 _LIT(KCStackPanicName, "CStack"); |
|
30 |
|
31 inline void Panic(TCStackPanic aPanic) |
|
32 { |
|
33 User::Panic(KCStackPanicName, aPanic); |
|
34 } |
|
35 |
|
36 // |
|
37 // CStack |
|
38 // |
|
39 |
|
40 template <class T, TBool StackOwnsEntry> |
|
41 inline CStack<T, StackOwnsEntry>::CStack() |
|
42 : CArrayPtrSeg<T>(KStackGranularity) |
|
43 { |
|
44 this->Reset(); |
|
45 } |
|
46 |
|
47 template <class T, TBool StackOwnsEntry> |
|
48 inline CStack<T, StackOwnsEntry>::~CStack() |
|
49 { |
|
50 Clear(); |
|
51 } |
|
52 |
|
53 template <class T, TBool StackOwnsEntry> |
|
54 inline void CStack<T, StackOwnsEntry>::Clear() |
|
55 { |
|
56 if (StackOwnsEntry) |
|
57 this->ResetAndDestroy(); |
|
58 else |
|
59 this->Reset(); |
|
60 } |
|
61 |
|
62 template <class T, TBool StackOwnsEntry> |
|
63 inline TBool CStack<T, StackOwnsEntry>::IsEmpty() const |
|
64 { |
|
65 return this->Count()==0; |
|
66 } |
|
67 |
|
68 template <class T, TBool StackOwnsEntry> |
|
69 inline void CStack<T, StackOwnsEntry>::PushL(T* aItem) |
|
70 { |
|
71 if (StackOwnsEntry) |
|
72 CleanupStack::PushL(aItem); |
|
73 this->AppendL(aItem); |
|
74 if (StackOwnsEntry) |
|
75 CleanupStack::Pop(); |
|
76 } |
|
77 |
|
78 template <class T, TBool StackOwnsEntry> |
|
79 inline T* CStack<T, StackOwnsEntry>::Pop() |
|
80 { |
|
81 __ASSERT_DEBUG(!IsEmpty(), Panic(ECStackErrStackIsEmpty)); |
|
82 T* item=Head(); |
|
83 this->Delete(this->Count()-1); |
|
84 return item; |
|
85 } |
|
86 |
|
87 template <class T, TBool StackOwnsEntry> |
|
88 inline T* CStack<T, StackOwnsEntry>::Head() const |
|
89 { |
|
90 __ASSERT_DEBUG(!IsEmpty(), Panic(ECStackErrStackIsEmpty)); |
|
91 return this->At(this->Count()-1); |
|
92 } |
|
93 |
|
94 template <class T, TBool StackOwnsEntry> |
|
95 inline T* CStack<T, StackOwnsEntry>::Last() const |
|
96 { |
|
97 __ASSERT_DEBUG(!IsEmpty(), Panic(ECStackErrStackIsEmpty)); |
|
98 return this->At(0); |
|
99 } |
|
100 |
|
101 |
|
102 #endif // __CSTACK_INL__ |
|