1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/euser/cbase/ub_cln.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,780 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\euser\cbase\ub_cln.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include "ub_std.h"
1.22 +#include "us_data.h"
1.23 +
1.24 +const TInt KCleanupGranularity=4;
1.25 +const TInt KCleanupInitialSlots=8;
1.26 +
1.27 +LOCAL_C void doDelete(CBase *aPtr)
1.28 +//
1.29 +// Delete the CBase pointer
1.30 +//
1.31 + {
1.32 +
1.33 + delete aPtr;
1.34 + }
1.35 +
1.36 +LOCAL_C CCleanup &cleanup()
1.37 +//
1.38 +// Return the CTrapHandler's cleanup list.
1.39 +//
1.40 + {
1.41 +
1.42 + TCleanupTrapHandler *pH=(TCleanupTrapHandler *)GetTrapHandler();
1.43 + __ASSERT_ALWAYS(pH!=NULL,Panic(EClnNoTrapHandlerInstalled));
1.44 + return(pH->Cleanup());
1.45 + }
1.46 +
1.47 +
1.48 +
1.49 +
1.50 +TCleanupTrapHandler::TCleanupTrapHandler()
1.51 + : iCleanup(NULL)
1.52 +/**
1.53 +Default constructor.
1.54 +*/
1.55 + {}
1.56 +
1.57 +
1.58 +
1.59 +
1.60 +void TCleanupTrapHandler::Trap()
1.61 +/**
1.62 +Deals with the invocation of a call to TRAP.
1.63 +*/
1.64 + {
1.65 +
1.66 + iCleanup->NextLevel();
1.67 + }
1.68 +
1.69 +
1.70 +
1.71 +
1.72 +void TCleanupTrapHandler::UnTrap()
1.73 +/**
1.74 +Deals with a function exiting a TRAP without leaving.
1.75 +*/
1.76 + {
1.77 +
1.78 + iCleanup->PreviousLevel();
1.79 + }
1.80 +
1.81 +
1.82 +
1.83 +
1.84 +void TCleanupTrapHandler::Leave(TInt /*aValue*/)
1.85 +/**
1.86 +Deals with a function within a TRAP leaving.
1.87 +
1.88 +@param aValue The leave value.
1.89 +*/
1.90 + {
1.91 +
1.92 + iCleanup->PopAndDestroyAll();
1.93 + }
1.94 +
1.95 +
1.96 +
1.97 +
1.98 +class TCleanupStackItem
1.99 + {
1.100 +public:
1.101 + void Set(const TCleanupItem &aItem);
1.102 + inline void Cleanup();
1.103 + inline TBool IsLevelMarker() const;
1.104 + inline void MarkLevel();
1.105 + inline void PushLevel();
1.106 + inline TInt PopLevel();
1.107 + inline TBool Check(TAny* aExpectedItem) const;
1.108 +private:
1.109 + TCleanupOperation iOperation;
1.110 + union
1.111 + {
1.112 + TAny *iPtr;
1.113 + TInt iLevelCount; // may stack >1 level on this entry
1.114 + };
1.115 + };
1.116 +inline void TCleanupStackItem::MarkLevel()
1.117 + { iOperation=NULL; iLevelCount=1; }
1.118 +inline TBool TCleanupStackItem::IsLevelMarker() const
1.119 + { return (iOperation==NULL); }
1.120 +inline void TCleanupStackItem::Cleanup()
1.121 + { (*iOperation)(iPtr); }
1.122 +inline void TCleanupStackItem::PushLevel()
1.123 + { ++iLevelCount; }
1.124 +inline TInt TCleanupStackItem::PopLevel()
1.125 + { return (--iLevelCount); }
1.126 +inline TBool TCleanupStackItem::Check(TAny* aExpectedItem) const
1.127 + { return (iOperation && iPtr==aExpectedItem); }
1.128 +
1.129 +void TCleanupStackItem::Set(const TCleanupItem &anItem)
1.130 +//
1.131 +// Initialise an entry as a cleanup item.
1.132 +//
1.133 + {
1.134 +
1.135 + __ASSERT_ALWAYS(anItem.iOperation!=NULL,Panic(EClnNoCleanupOperation));
1.136 + iOperation=anItem.iOperation;
1.137 + iPtr=anItem.iPtr;
1.138 + }
1.139 +
1.140 +
1.141 +
1.142 +
1.143 +EXPORT_C CCleanup *CCleanup::New()
1.144 +/**
1.145 +Creates a new cleanup stack object.
1.146 +
1.147 +The cleanup stack itself is allocated with enough space initially to hold
1.148 +a number of stack items.
1.149 +
1.150 +@return A pointer to the new cleanup stack object. This is Null if there is
1.151 + insufficient memory.
1.152 +*/
1.153 + {
1.154 +
1.155 + CCleanup *pC=new CCleanup;
1.156 + if (pC!=NULL)
1.157 + {
1.158 + TCleanupStackItem *base=(TCleanupStackItem *)User::Alloc(KCleanupInitialSlots*sizeof(TCleanupStackItem));
1.159 + if (base!=NULL)
1.160 + {
1.161 + pC->iBase=base;
1.162 + pC->iNext=base;
1.163 + pC->iTop=base+KCleanupInitialSlots;
1.164 + }
1.165 + else
1.166 + {
1.167 + delete pC;
1.168 + pC=NULL;
1.169 + }
1.170 + }
1.171 + return(pC);
1.172 + }
1.173 +
1.174 +
1.175 +
1.176 +
1.177 +EXPORT_C CCleanup *CCleanup::NewL()
1.178 +/**
1.179 +Creates a new cleanup stack object, and leaves if there is insufficient memory
1.180 +to create it.
1.181 +
1.182 +The cleanup stack itself is allocated with enough space initially to hold
1.183 +a number of stack items.
1.184 +
1.185 +@return A pointer to the new cleanup stack object. This is Null if there is
1.186 + nsufficient memory.
1.187 +*/
1.188 + {
1.189 +
1.190 + CCleanup *pC=New();
1.191 + User::LeaveIfNull(pC);
1.192 + return(pC);
1.193 + }
1.194 +
1.195 +
1.196 +
1.197 +
1.198 +EXPORT_C CCleanup::CCleanup()
1.199 +/**
1.200 +Default constructor.
1.201 +*/
1.202 + {
1.203 +
1.204 +// iBase=NULL;
1.205 +// iTop=NULL;
1.206 +// iNext=NULL;
1.207 + }
1.208 +
1.209 +
1.210 +
1.211 +
1.212 +EXPORT_C CCleanup::~CCleanup()
1.213 +/**
1.214 +Destructor.
1.215 +
1.216 +Pops and destroys all items from the cleanup stack and then destroys
1.217 +the cleanup stack itself.
1.218 +*/
1.219 + {
1.220 +
1.221 + while (iNext>iBase)
1.222 + PopAndDestroyAll();
1.223 + User::Free(iBase);
1.224 + }
1.225 +
1.226 +
1.227 +
1.228 +
1.229 +EXPORT_C void CCleanup::NextLevel()
1.230 +/**
1.231 +Goes to the next cleanup level.
1.232 +*/
1.233 + {
1.234 +
1.235 + if (iNext>iBase && (iNext-1)->IsLevelMarker())
1.236 + (iNext-1)->PushLevel();
1.237 + else
1.238 + {
1.239 + iNext->MarkLevel();
1.240 + ++iNext;
1.241 + }
1.242 + }
1.243 +
1.244 +
1.245 +
1.246 +
1.247 +EXPORT_C void CCleanup::PreviousLevel()
1.248 +/**
1.249 +Goes to the previous cleanup level.
1.250 +
1.251 +@panic E32USER-CBase 71 If the previous stack item does not represent a cleanup
1.252 + level.
1.253 +*/
1.254 + {
1.255 +
1.256 + TCleanupStackItem *item=iNext;
1.257 + --item;
1.258 + // current level must be empty
1.259 + __ASSERT_ALWAYS(item->IsLevelMarker(), Panic(EClnLevelNotEmpty));
1.260 + if (item->PopLevel())
1.261 + ++item;
1.262 + iNext=item;
1.263 + }
1.264 +
1.265 +
1.266 +
1.267 +
1.268 +EXPORT_C void CCleanup::PushL(TAny *aPtr)
1.269 +/**
1.270 +Pushes a cleanup item onto the cleanup stack.
1.271 +
1.272 +The cleanup item represents an operation that frees the specified heap cell.
1.273 +
1.274 +@param aPtr A pointer to a heap cell that will be freed by
1.275 + the cleanup operation.
1.276 +*/
1.277 + {
1.278 +
1.279 + PushL(TCleanupItem(User::Free,aPtr));
1.280 + }
1.281 +
1.282 +
1.283 +
1.284 +
1.285 +EXPORT_C void CCleanup::PushL(CBase *anObject)
1.286 +/**
1.287 +Pushes a cleanup item onto the cleanup stack.
1.288 +
1.289 +The cleanup item represents an operation that deletes the specified CBase
1.290 +derived object.
1.291 +
1.292 +@param anObject A pointer to CBase derived object that will be deleted by
1.293 + the cleanup operation.
1.294 +*/
1.295 + {
1.296 +
1.297 + PushL(TCleanupItem(TCleanupOperation(doDelete),anObject));
1.298 + }
1.299 +
1.300 +
1.301 +
1.302 +
1.303 +EXPORT_C void CCleanup::PushL(TCleanupItem anItem)
1.304 +/**
1.305 +Pushes a cleanup item onto the cleanup stack.
1.306 +
1.307 +The cleanup item represents a call back operation that performs the required
1.308 +cleanup.
1.309 +
1.310 +@param anItem Encapsulates a cleanup operation and an object on which the
1.311 + cleanup operation is to be performed.
1.312 +
1.313 +@see CleanupClosePushL
1.314 +@see CleanupReleasePushL
1.315 +@see CleanupDeletePushL
1.316 +*/
1.317 + {
1.318 +
1.319 + TCleanupStackItem *item=iNext;
1.320 + __ASSERT_ALWAYS(item>iBase,Panic(EClnPushAtLevelZero));
1.321 + __ASSERT_ALWAYS(item<iTop,Panic(EClnNoFreeSlotItem));
1.322 + item->Set(anItem);
1.323 + iNext=++item;
1.324 +//
1.325 +// We always try and make sure that there are two free slots in the cleanup array.
1.326 +// one for a level marker and one for an item to follow it
1.327 +// If this fails its o.k. as we have already added the entry to the list, so
1.328 +// it will be cleaned up o.k.
1.329 +//
1.330 + if (item+1>=iTop)
1.331 + {
1.332 + TInt size=(TUint8 *)(iTop+KCleanupGranularity)-(TUint8 *)iBase;
1.333 + TCleanupStackItem *base=(TCleanupStackItem *)User::ReAllocL(iBase,size);
1.334 + iNext=PtrAdd(base,(TUint8 *)item-(TUint8 *)iBase);
1.335 + iBase=base;
1.336 + iTop=PtrAdd(base,size);
1.337 + }
1.338 + }
1.339 +
1.340 +
1.341 +
1.342 +
1.343 +EXPORT_C void CCleanup::DoPop(TInt aCount,TBool aDestroy)
1.344 +/**
1.345 +Provides an implementation for Pop() and PopAndDestroy().
1.346 +
1.347 +@param aCount The number of cleanup items to be popped from
1.348 + the cleanup stack.
1.349 +@param aDestroy ETrue, if cleanup is to be performed; EFalse, otherwise.
1.350 +*/
1.351 + {
1.352 +
1.353 + __ASSERT_ALWAYS(aCount>=0,Panic(EClnPopCountNegative));
1.354 + __ASSERT_ALWAYS((iNext-aCount)>=iBase,Panic(EClnPopUnderflow));
1.355 + while (aCount--)
1.356 + {
1.357 + --iNext;
1.358 + __ASSERT_ALWAYS(!iNext->IsLevelMarker(),Panic(EClnPopAcrossLevels));
1.359 + if (aDestroy)
1.360 + {
1.361 + TInt offset = iNext - iBase;
1.362 + iNext->Cleanup();
1.363 + // Check that there are no extra items on the cleanup stack
1.364 + // (if there are, we will not be deleting the right aCount items)
1.365 + __ASSERT_ALWAYS((iNext - iBase) == offset,Panic(EClnStackModified));
1.366 + }
1.367 + }
1.368 + }
1.369 +
1.370 +
1.371 +
1.372 +
1.373 +EXPORT_C void CCleanup::DoPopAll(TBool aDestroy)
1.374 +/**
1.375 +Provides an implementation for PopAll() and PopAndDestroyAll().
1.376 +
1.377 +@param aDestroy ETrue, if cleanup is to be performed; EFalse, otherwise.
1.378 +*/
1.379 + {
1.380 +
1.381 + __ASSERT_ALWAYS(iNext>iBase,Panic(EClnLevelUnderflow));
1.382 + while (!(--iNext)->IsLevelMarker())
1.383 + {
1.384 + if (aDestroy)
1.385 + iNext->Cleanup();
1.386 + }
1.387 + if (iNext->PopLevel())
1.388 + ++iNext; // still marks a level
1.389 + }
1.390 +
1.391 +
1.392 +
1.393 +
1.394 +EXPORT_C void CCleanup::Pop()
1.395 +/**
1.396 +Pops a single cleanup item from the cleanup stack.
1.397 +
1.398 +@panic E32USER-CBase 64 If there are no items on the cleanup stack.
1.399 +@panic E32USER-CBase 63 If a cleanup level is crossed.
1.400 +*/
1.401 + {
1.402 +
1.403 + DoPop(1,EFalse);
1.404 + }
1.405 +
1.406 +
1.407 +
1.408 +
1.409 +EXPORT_C void CCleanup::Pop(TInt aCount)
1.410 +/**
1.411 +Pops the specified number of cleanup items from the cleanup stack.
1.412 +
1.413 +@param aCount The number of cleanup items to be popped from the cleanup stack.
1.414 +
1.415 +@panic E32USER-CBase 70 If the specified number of cleanup items is negative.
1.416 +@panic E32USER-CBase 64 If the specifed number of items is greater than the
1.417 + number of items on the cleanup stack.
1.418 +@panic E32USER-CBase 63 If the specified number of items is such that it causes
1.419 + a cleanup level to be crossed.
1.420 +*/
1.421 + {
1.422 +
1.423 + DoPop(aCount,EFalse);
1.424 + }
1.425 +
1.426 +
1.427 +
1.428 +
1.429 +EXPORT_C void CCleanup::PopAll()
1.430 +/**
1.431 +Pops all cleanup items at the current level, and then decrements the level.
1.432 +*/
1.433 + {
1.434 +
1.435 + DoPopAll(EFalse);
1.436 + }
1.437 +
1.438 +
1.439 +
1.440 +
1.441 +EXPORT_C void CCleanup::PopAndDestroy()
1.442 +/**
1.443 +Pops a single cleanup item from the cleanup stack, and invokes its cleanup
1.444 +operation.
1.445 +
1.446 +@panic E32USER-CBase 64 If there are no items on the cleanup stack.
1.447 +@panic E32USER-CBase 63 If a cleanup level is crossed.
1.448 +*/
1.449 + {
1.450 +
1.451 + DoPop(1,ETrue);
1.452 + }
1.453 +
1.454 +
1.455 +
1.456 +
1.457 +EXPORT_C void CCleanup::PopAndDestroy(TInt aCount)
1.458 +/**
1.459 +Pops the specified number of cleanup items from the cleanup stack, and invokes
1.460 +their cleanup operations.
1.461 +
1.462 +@param aCount The number of cleanup items to be popped from the cleanup stack.
1.463 +
1.464 +@panic E32USER-CBase 70 If the specified number of cleanup items is negative.
1.465 +@panic E32USER-CBase 64 If the specifed number of items is greater than the
1.466 + number of items on the cleanup stack.
1.467 +@panic E32USER-CBase 63 If the specified number of items is such that it causes
1.468 + a cleanup level to be crossed.
1.469 +*/
1.470 + {
1.471 +
1.472 + DoPop(aCount,ETrue);
1.473 + }
1.474 +
1.475 +
1.476 +
1.477 +
1.478 +EXPORT_C void CCleanup::PopAndDestroyAll()
1.479 +/**
1.480 +Pops all cleanup items at the current level, invokes their cleanup operations
1.481 +and then decrements the level.
1.482 +*/
1.483 + {
1.484 +
1.485 + DoPopAll(ETrue);
1.486 + }
1.487 +
1.488 +
1.489 +
1.490 +
1.491 +EXPORT_C void CCleanup::Check(TAny* aExpectedItem)
1.492 +/**
1.493 +Checks that the cleanup item at the top of the cleanup stack
1.494 +represents a cleanup operation for the specified object.
1.495 +
1.496 +@param aExpectedItem The object which is the subject of the test.
1.497 +*/
1.498 + {
1.499 +
1.500 + TCleanupStackItem* last=iNext-1;
1.501 + __ASSERT_ALWAYS(last>=iBase && last->Check(aExpectedItem), Panic(EClnCheckFailed));
1.502 + }
1.503 +
1.504 +
1.505 +
1.506 +
1.507 +EXPORT_C CTrapCleanup *CTrapCleanup::New()
1.508 +/**
1.509 +Allocates and constructs a cleanup stack.
1.510 +
1.511 +If successfully constructed, this cleanup stack becomes
1.512 +the current cleanup stack.
1.513 +
1.514 +@return A pointer to the new cleanup stack. This pointer is NULL, if allocation
1.515 + fails.
1.516 +*/
1.517 + {
1.518 +
1.519 + CTrapCleanup *pT=new CTrapCleanup;
1.520 + if (pT!=NULL)
1.521 + {
1.522 + CCleanup *pC=CCleanup::New();
1.523 + if (pC!=NULL)
1.524 + {
1.525 + pT->iHandler.iCleanup=pC;
1.526 + pT->iOldHandler=User::SetTrapHandler(&pT->iHandler);
1.527 + }
1.528 + else
1.529 + {
1.530 + delete pT;
1.531 + pT=NULL;
1.532 + }
1.533 + }
1.534 + return(pT);
1.535 + }
1.536 +
1.537 +
1.538 +
1.539 +
1.540 +EXPORT_C CTrapCleanup::CTrapCleanup()
1.541 +/**
1.542 +Default constructor.
1.543 +*/
1.544 +// : iHandler()
1.545 + {
1.546 + }
1.547 +
1.548 +
1.549 +
1.550 +
1.551 +EXPORT_C CTrapCleanup::~CTrapCleanup()
1.552 +/**
1.553 +Destructor.
1.554 +
1.555 +Frees resources owned by the object, prior to its destruction. This cleanup
1.556 +stack ceases to be the current cleanup stack.
1.557 +
1.558 +If there is a stack of cleanup stacks, then the next cleanup stack becomes
1.559 +the current cleanup stack.
1.560 +*/
1.561 + {
1.562 +
1.563 + if (iHandler.iCleanup!=NULL)
1.564 + {
1.565 + User::SetTrapHandler(iOldHandler);
1.566 + delete iHandler.iCleanup;
1.567 + }
1.568 + }
1.569 +
1.570 +
1.571 +
1.572 +
1.573 +EXPORT_C void CleanupStack::PushL(TAny *aPtr)
1.574 +/**
1.575 +Pushes a pointer to an object onto the cleanup stack.
1.576 +
1.577 +If a leave occurs while an object is on the stack, it is cleaned
1.578 +up automatically. Untyped objects are cleaned up with User::Free()
1.579 +(a rather limited form of cleanup, not even the C++ destructor is called).
1.580 +
1.581 +Typically, when an object has been fully constructed and it can be guaranteed
1.582 +that a pointer to this new object is stored in some other object before a leave
1.583 +occurs, issue CleanupStack::Pop() to pop it back off the stack.
1.584 +
1.585 +If no cleanup stack has been allocated, a panic occurs.
1.586 +
1.587 +It is guaranteed that the object is pushed onto the cleanup stack. However,
1.588 +this function may leave if a stack frame for the next PushL() cannot be
1.589 +allocated. In this case, the cleanup stack will be cleaned up as normal, and
1.590 +no extra programmer intervention is needed.
1.591 +
1.592 +@param aPtr Pointer to any object. If cleanup is necessary, the object will be
1.593 + freed by User::Free(), which does not invoke any destructor: it
1.594 + simply frees its memory
1.595 +
1.596 +@panic E32USER-CBase 66 if a call to this function is made when no prior
1.597 + call to TRAP has been made.
1.598 +*/
1.599 + {
1.600 +
1.601 + cleanup().PushL(aPtr);
1.602 + }
1.603 +
1.604 +
1.605 +
1.606 +
1.607 +EXPORT_C void CleanupStack::PushL(CBase *aPtr)
1.608 +/**
1.609 +Pushes a pointer to an object onto the cleanup stack.
1.610 +
1.611 +If a leave occurs while an object is on the stack, it is cleaned
1.612 +up automatically. CBase derived objects are cleaned up with delete.
1.613 +
1.614 +Typically, when an object has been fully constructed and it can be guaranteed
1.615 +that a pointer to this new object is stored in some other object before a leave
1.616 +occurs, issue CleanupStack::Pop() to pop it back off the stack.
1.617 +
1.618 +If no cleanup stack has been allocated, a panic occurs.
1.619 +
1.620 +It is guaranteed that the object is pushed onto the cleanup stack. However,
1.621 +this function may leave if a stack frame for the next PushL() cannot be
1.622 +allocated. In this case, the cleanup stack will be cleaned up as normal,
1.623 +and no extra programmer intervention is needed.
1.624 +
1.625 +@param aPtr Pointer to a CBase-derived object. If cleanup is necessary, the
1.626 + object will be freed by delete, thus invoking its destructor,
1.627 + and freeing its memory.
1.628 +
1.629 +@panic E32USER-CBase 66 if a call to this function is made when no prior
1.630 + call to TRAP has been made.
1.631 +*/
1.632 + {
1.633 +
1.634 + cleanup().PushL(aPtr);
1.635 + }
1.636 +
1.637 +
1.638 +
1.639 +
1.640 +EXPORT_C void CleanupStack::PushL(TCleanupItem anItem)
1.641 +/**
1.642 +Pushes a cleanup item onto the cleanup stack.
1.643 +
1.644 +If a leave occurs while a cleanup item is on the stack, the cleanup operation
1.645 +defined in the construction of the TCleanupItem, is invoked.
1.646 +
1.647 +Typically, when an object has been fully constructed and it can be guaranteed
1.648 +that a pointer to this new object is stored in some other object before a leave
1.649 +occurs, issue CleanupStack::Pop() to pop it back off the stack.
1.650 +
1.651 +If no cleanup stack has been allocated, a panic occurs.
1.652 +
1.653 +It is guaranteed that the object is pushed onto the cleanup stack. However,
1.654 +this function may leave if a stack frame for the next PushL() cannot be
1.655 +allocated. In this case, the cleanup stack will be cleaned up as normal,
1.656 +and no extra programmer intervention is needed.
1.657 +
1.658 +@param anItem A cleanup item. If cleanup is necessary, the cleanup operation
1.659 + defined in the construction of anItem is called.
1.660 +
1.661 +@panic E32USER-CBase 66 if a call to this function is made when no prior
1.662 + call to TRAP has been made.
1.663 +*/
1.664 + {
1.665 +
1.666 + cleanup().PushL(anItem);
1.667 + }
1.668 +
1.669 +
1.670 +
1.671 +
1.672 +EXPORT_C void CleanupStack::Pop()
1.673 +/**
1.674 +Pops an object previously pushed onto the cleanup stack
1.675 +by CleanupStack::PushL().
1.676 +
1.677 +After an object has been successfully constructed and stored within
1.678 +another object, it cannot be orphaned and, therefore, the object
1.679 +(i.e. a pointer or a cleanup item) can be popped from the cleanup stack.
1.680 +
1.681 +If no cleanup stack has been allocated, or there is nothing on the stack,
1.682 +a panic is raised.
1.683 +*/
1.684 + {
1.685 +
1.686 + cleanup().Pop();
1.687 + }
1.688 +
1.689 +
1.690 +
1.691 +
1.692 +EXPORT_C void CleanupStack::Pop(TInt aCount)
1.693 +/**
1.694 +Pops a specified number of objects previously pushed onto the
1.695 +cleanup stack by CleanupStack::PushL().
1.696 +
1.697 +After an object has been successfully constructed and stored within another
1.698 +object, it cannot be orphaned and, therefore, the object(s), that is, pointers
1.699 +and cleanup items can be popped from the cleanup stack.
1.700 +
1.701 +If no cleanup stack has been allocated, or there is nothing on the stack,
1.702 +a panic is raised.
1.703 +
1.704 +@param aCount The number of objects to be popped off the cleanup stack.
1.705 +*/
1.706 + {
1.707 +
1.708 + cleanup().Pop(aCount);
1.709 + }
1.710 +
1.711 +
1.712 +
1.713 +
1.714 +EXPORT_C void CleanupStack::PopAndDestroy()
1.715 +/**
1.716 +Pops and cleans up an item pushed onto the stack.
1.717 +
1.718 +If the item on the stack is a CBase* pointer, the pointer is removed from
1.719 +the stack and the object is destroyed with delete.
1.720 +
1.721 +If the item on the stack is a TAny* pointer, the pointer is removed from
1.722 +the stack and the memory occupied by the object is freed with User::Free().
1.723 +
1.724 +If the item on the stack is a cleanup item, i.e. an object of
1.725 +type TCleanupItem, the item is removed from the stack and the cleanup
1.726 +operation defined during construction of the TCleanupItem object is invoked.
1.727 +
1.728 +If no cleanup stack has been allocated, or there is nothing on the stack,
1.729 +a panic occurs.
1.730 +*/
1.731 + {
1.732 +
1.733 + cleanup().PopAndDestroy();
1.734 + }
1.735 +
1.736 +
1.737 +
1.738 +
1.739 +EXPORT_C void CleanupStack::PopAndDestroy(TInt aCount)
1.740 +/**
1.741 +Pops and cleans up the specified number of items pushed onto the stack.
1.742 +
1.743 +If an item on the stack is a CBase* pointer, the pointer is removed from
1.744 +the stack and the object is destroyed with delete.
1.745 +
1.746 +If an item on the stack is a TAny* pointer, the pointer is removed from the
1.747 +stack and the memory occupied by the object is freed with User::Free().
1.748 +
1.749 +If an item on the stack is a cleanup item, i.e. an object of type TCleanupItem,
1.750 +the item is removed from the stack and the cleanup operation defined during
1.751 +construction of the TCleanupItem object is invoked.
1.752 +
1.753 +If no cleanup stack has been allocated, or there is nothing on the stack,
1.754 +a panic occurs.
1.755 +
1.756 +@param aCount The number of objects to be popped off the cleanup stack and
1.757 +destroyed.
1.758 +*/
1.759 + {
1.760 +
1.761 + cleanup().PopAndDestroy(aCount);
1.762 + }
1.763 +
1.764 +
1.765 +
1.766 +
1.767 +EXPORT_C void CleanupStack::Check(TAny* aExpectedItem)
1.768 +/**
1.769 +Checks that the specified object is at the top of the cleanup stack.
1.770 +
1.771 +If the specified item is not at the top of the cleanup stack, then the function
1.772 +raises an E32USER-CBase 90 panic.
1.773 +
1.774 +The function is part of Symbian OS in both debug and release builds, and is
1.775 +an aid to debugging.
1.776 +
1.777 +@param aExpectedItem A pointer to the item expected to be at the top of the
1.778 + cleanup stack.
1.779 +*/
1.780 + {
1.781 +
1.782 + cleanup().Check(aExpectedItem);
1.783 + }