diff -r 000000000000 -r b16258d2340f applayerprotocols/httptransportfw/Test/T_HttpIntegration/CPile.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/applayerprotocols/httptransportfw/Test/T_HttpIntegration/CPile.cpp Tue Feb 02 01:09:52 2010 +0200 @@ -0,0 +1,444 @@ +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// $Header$ +// Noticed lots of classes want to 'pile' up objects (as in stack 'em) but +// all create their own 'class'. Stuff that for a game of soldiers... +// here's a templated class that serves all! +// mjd, mark@mjdss.com, july 2002 +// +// + +#include "CPile.h" + +//----------------------------------------------------------------------------- +// the NewL calls default values (e.g. 16) in ConstructL + +template +CPile * CPile::NewL() +{ +CPile* self = NewLC(); +CleanupStack::Pop(); +return self; +} + +//----------------------------------------------------------------------------- +// the NewL calls passes desired default size to ConstructL + +template +CPile * CPile::NewL(const TInt &aElements) +{ +CPile *self = NewLC(aElements); +CleanupStack::Pop(); +return self; +} + +//----------------------------------------------------------------------------- + +template +CPile * CPile::NewLC(const TInt &aElements) +{ +CPile *self = new (ELeave) CPile(); +CleanupStack::PushL(self); +self->ConstructL(aElements); +return self; +} + +//----------------------------------------------------------------------------- +// destroy the pile of T! +// not forgetting to delete the stacks contents first! + +template +CPile::~CPile() +{ +iPile->ResetAndDestroy(); +delete iPile; +iPile = NULL; +} + +//----------------------------------------------------------------------------- +// would be nice to be able to easily specify in the constructor +// the size of the initial stack... +// mjd: added in the aElements which is now passed (via default) from NewL + +template +void CPile::ConstructL(const TInt &aElements) +{ +iPile = new (ELeave) CArrayPtrSeg(aElements); +} + +//----------------------------------------------------------------------------- +// ok, push an object of class T onto the stack + +template +void CPile::PushL(T *aT) +{ +iPile->AppendL(aT); +} + +//----------------------------------------------------------------------------- +// pop an object of class T off the top of the pile (stack) or +// NULL if nothing to get... +// note: Count is always 1 more than actual contents of stack... + +template +T *CPile::Pop() +{ +TInt count = Count(); +if (count > 0) + { + T *t = At(--count); + iPile->Delete(count); + return t; + } +else + return NULL; +} + +//----------------------------------------------------------------------------- +// zap the objcet of class T sitting at the top of the stack + +template +void CPile::Skim() +{ +T *t = Pop(); +delete t; +} + +//----------------------------------------------------------------------------- +// zap all objects of class T sitting on the stack + +template +void CPile::Empty() +{ +while (iPile->Count()) + Skim(); +} + +//----------------------------------------------------------------------------- +// How many do we have - this SHOULD be a property! + +template +TInt CPile::Count() const +{ +return iPile->Count(); +} + +//----------------------------------------------------------------------------- +// get the n'th item in the list +// indexed from 0 so [0] is valid. + +template +T *CPile::At(const TInt &aIndex) const +{ +if ((aIndex >= 0) || (aIndex < Count())) + return iPile->At(aIndex); +return NULL; +} + +//----------------------------------------------------------------------------- +// get the [n]'th item in the list + +template +T *CPile::operator[](const TInt &aIndex) const +{ +return At(aIndex); +} + +//----------------------------------------------------------------------------- + +template +T *CPile::Peek() +{ +TInt count = Count(); +if (count > 0) + { + T *t = At(--count); + return t; + } + +return NULL; +} +//----------------------------------------------------------------------------- +// Template Specialization requirements: CLogFile +//----------------------------------------------------------------------------- + +CPile * CPile::NewL() +{ +CPile *self = NewLC(); +CleanupStack::Pop(); +return self; +} + +//----------------------------------------------------------------------------- + +CPile *CPile::NewLC(const TInt &aElements) +{ +CPile *self = new (ELeave) CPile(); +CleanupStack::PushL(self); +self->ConstructL(aElements); +return self; +} + +//----------------------------------------------------------------------------- + +void CPile::ConstructL(const TInt &aElements) +{ +iPile = new (ELeave) CArrayPtrSeg(aElements); +} + +//----------------------------------------------------------------------------- + +void CPile::PushL(CLogFile *aT) +{ +iPile->AppendL(aT); +} + +//----------------------------------------------------------------------------- + +CLogFile *CPile::Pop() +{ +TInt count = Count(); +if (count > 0) + { + CLogFile *t = At(--count); + iPile->Delete(count); + return t; + } +else + return NULL; +} + +//----------------------------------------------------------------------------- + +CLogFile *CPile::At(const TInt &aIndex) const +{ +if ((aIndex >= 0) || (aIndex < Count())) + return (CLogFile *)iPile->At(aIndex); + //return (CLogFile *) &iPile[aIndex]; +return NULL; +} + +//----------------------------------------------------------------------------- + +TInt CPile::Count() const +{ +return iPile->Count(); +} + +//----------------------------------------------------------------------------- + +CPile::~CPile() +{ +iPile->ResetAndDestroy(); +delete iPile; +iPile = NULL; +} + + +//----------------------------------------------------------------------------- +// Template Specialization requirements: CCmdFile +//----------------------------------------------------------------------------- + +CPile *CPile::NewL() +{ +CPile *self = NewLC(); +CleanupStack::Pop(); +return self; +} + +//----------------------------------------------------------------------------- + +CPile *CPile::NewLC(const TInt &aElements) +{ +CPile *self = new (ELeave) CPile(); +CleanupStack::PushL(self); +self->ConstructL(aElements); +return self; +} + +//----------------------------------------------------------------------------- + +CPile::~CPile() +{ +iPile->ResetAndDestroy(); +delete iPile; +iPile = NULL; +} + +//----------------------------------------------------------------------------- + +void CPile::ConstructL(const TInt &aElements) +{ +iPile = new (ELeave) CArrayPtrSeg(aElements); +} + +//----------------------------------------------------------------------------- + +TInt CPile::Count() const +{ +return iPile->Count(); +} + +//----------------------------------------------------------------------------- + +CCmdFile *CPile::At(const TInt &aIndex) const +{ +if ((aIndex >= 0) || (aIndex < Count())) + return (CCmdFile *)iPile->At(aIndex); + //return (CCmdFile *) &iPile[aIndex]; +return NULL; +} + +//----------------------------------------------------------------------------- + +void CPile::PushL(CCmdFile *aT) +{ +iPile->AppendL(aT); +} + +//----------------------------------------------------------------------------- + +CCmdFile *CPile::Pop() +{ +TInt count = Count(); +if (count > 0) + { + CCmdFile *t = At(--count); + iPile->Delete(count); + return t; + } +else + return NULL; +} + +//----------------------------------------------------------------------------- + +void CPile::Skim() +{ +CCmdFile *t = Pop(); +delete t; +} + +//----------------------------------------------------------------------------- + +void CPile::Empty() +{ +while (iPile->Count()) + Skim(); +} + + + + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// Template Specialization requirements: CIFControl +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- + +CPile *CPile::NewL() +{ +CPile *self = NewLC(); +CleanupStack::Pop(); +return self; +} + +//----------------------------------------------------------------------------- + +CPile *CPile::NewLC(const TInt &aElements) +{ +CPile *self = new (ELeave) CPile(); +CleanupStack::PushL(self); +self->ConstructL(aElements); +return self; +} + +//----------------------------------------------------------------------------- + +void CPile::ConstructL(const TInt &aElements) +{ +iPile = new (ELeave) CArrayPtrSeg(aElements); +} + +//----------------------------------------------------------------------------- + +CIFControl *CPile::At(const TInt &aIndex) const +{ +if ((aIndex >= 0) || (aIndex < Count())) + return (CIFControl *)iPile->At(aIndex); +return NULL; +} + +//----------------------------------------------------------------------------- + +void CPile::PushL(CIFControl *aT) +{ +iPile->AppendL(aT); +} + +//----------------------------------------------------------------------------- + +TInt CPile::Count() const +{ +return iPile->Count(); +} + +//----------------------------------------------------------------------------- + +CIFControl *CPile::Pop() +{ +TInt count = Count(); +if (count > 0) + { + CIFControl *t = At(--count); + iPile->Delete(count); + return t; + } + +return NULL; +} + +void CPile::Skim() +{ + CIFControl *t = Pop(); + delete t; +} + +//----------------------------------------------------------------------------- + +CIFControl *CPile::Peek() +{ +TInt count = Count(); +if (count > 0) + { + CIFControl *t = At(--count); + return t; + } + +return NULL; +} + + +//----------------------------------------------------------------------------- + +CPile::~CPile() +{ +iPile->ResetAndDestroy(); +delete iPile; +iPile = NULL; +} + +//----------------------------------------------------------------------------- +// End of File +//-----------------------------------------------------------------------------