epoc32/include/cstack.inl
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
--- a/epoc32/include/cstack.inl	Tue Nov 24 13:55:44 2009 +0000
+++ b/epoc32/include/cstack.inl	Tue Mar 16 16:12:26 2010 +0000
@@ -1,1 +1,102 @@
-cstack.inl
+// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
+// All rights reserved.
+// This component and the accompanying materials are made available
+// 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
+// which accompanies this distribution, and is available
+// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
+//
+// Initial Contributors:
+// Nokia Corporation - initial contribution.
+//
+// Contributors:
+//
+// Description:
+//
+
+#ifndef __CSTACK_INL__
+#define __CSTACK_INL__
+
+// constants
+const TInt KStackGranularity=32;
+
+enum TCStackPanic
+	{
+	ECStackErrStackIsEmpty,
+	ECStackDeleteWhenNotOwner,
+	ECStackPopsWhenOwner
+	};
+
+_LIT(KCStackPanicName, "CStack");
+
+inline void Panic(TCStackPanic aPanic)
+	{
+	User::Panic(KCStackPanicName, aPanic);
+	}
+
+//
+// CStack
+//
+
+template <class T, TBool StackOwnsEntry>
+inline CStack<T, StackOwnsEntry>::CStack()
+: CArrayPtrSeg<T>(KStackGranularity)
+	{
+	this->Reset();
+	}
+
+template <class T, TBool StackOwnsEntry>
+inline CStack<T, StackOwnsEntry>::~CStack()
+	{ 
+	Clear();
+	}
+
+template <class T, TBool StackOwnsEntry>
+inline void CStack<T, StackOwnsEntry>::Clear() 
+	{ 
+	if (StackOwnsEntry) 
+		this->ResetAndDestroy(); 
+	else 
+		this->Reset(); 
+	}
+
+template <class T, TBool StackOwnsEntry>
+inline TBool CStack<T, StackOwnsEntry>::IsEmpty() const 
+	{ 
+	return this->Count()==0;
+	}
+
+template <class T, TBool StackOwnsEntry>
+inline void CStack<T, StackOwnsEntry>::PushL(T* aItem) 
+	{
+	if (StackOwnsEntry)
+		CleanupStack::PushL(aItem); 
+	this->AppendL(aItem); 
+	if (StackOwnsEntry)
+		CleanupStack::Pop();
+	}
+
+template <class T, TBool StackOwnsEntry>
+inline T* CStack<T, StackOwnsEntry>::Pop() 
+	{
+	__ASSERT_DEBUG(!IsEmpty(), Panic(ECStackErrStackIsEmpty));
+	T* item=Head(); 
+	this->Delete(this->Count()-1);
+	return item;
+	}
+
+template <class T, TBool StackOwnsEntry>
+inline T* CStack<T, StackOwnsEntry>::Head() const 
+	{
+	__ASSERT_DEBUG(!IsEmpty(), Panic(ECStackErrStackIsEmpty));
+	return this->At(this->Count()-1);
+	}
+
+template <class T, TBool StackOwnsEntry>
+inline T* CStack<T, StackOwnsEntry>::Last() const 
+	{
+	__ASSERT_DEBUG(!IsEmpty(), Panic(ECStackErrStackIsEmpty));
+	return this->At(0);
+	}
+	
+
+#endif // __CSTACK_INL__