|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Provides cleanup item to push ResetAndDestroy calls to |
|
15 * cleanup stack. It is heavily used for RPointerArrays, |
|
16 * which are used all over Symbian's CalenInterimAPI. |
|
17 * Implementation is more or less copy-paste of |
|
18 * cleanup item of Close method and CleanupClosePushL |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 #ifndef __CLEANUPRESETANDDESTROY_H__ |
|
24 #define __CLEANUPRESETANDDESTROY_H__ |
|
25 |
|
26 /** |
|
27 * A utility class used by the templated function CleanupResetAndDestroyPushL() |
|
28 * to create a TCleanupItem item that will perform a close type operation on |
|
29 * the class T type object. |
|
30 **/ |
|
31 template <class T> |
|
32 class CleanupResetAndDestroy |
|
33 { |
|
34 public: |
|
35 inline static void PushL(T& aRef); |
|
36 |
|
37 private: |
|
38 static void ResetAndDestroy(TAny *aPtr); |
|
39 |
|
40 }; |
|
41 |
|
42 /** |
|
43 * Constructs and pushes a TCleanupItem object onto the cleanup stack. |
|
44 * |
|
45 * The TCleanupItem encapsulates: |
|
46 * |
|
47 * 1. a reference aRef to the object of type class T which is to be cleaned up |
|
48 * 2. an associated cleanup operation. |
|
49 * |
|
50 * The cleanup operation is the private static function ResetAndDestroy() of |
|
51 * the templated class CleanupResetAndDestroy and is invoked as a result of |
|
52 * a subsequent call to CleanupStack::PopAndDestroy(). |
|
53 * |
|
54 * CleanupResetAndDestroy::ResetAndDestroy() is passed a pointer to the |
|
55 * class T object to be cleaned up, and the function implements cleanup by |
|
56 * calling ResetAndDestroy() on the passed object. |
|
57 * The class T object must, therefore, define and implement (or inherit) a |
|
58 * ResetAndDestroy() member function. |
|
59 * |
|
60 * RPointerArray<HBufC> buffers; |
|
61 * CleanupResetAndDestroyPushL( buffers ); |
|
62 * buffers.Append( HBufC::NewL(100) ); |
|
63 * ... |
|
64 * CleanupStack::PopAndDestroy(); // <--- results in ResetAndDestroy() being called on "buffers". |
|
65 * ... |
|
66 * @endcode |
|
67 * |
|
68 * @param aRef A reference to a class T type object for which the cleanup item is being created. |
|
69 * @see TCleanupItem |
|
70 * @see CleanupResetAndDestroy |
|
71 * @see CleanupStack::PopAndDestroy() |
|
72 **/ |
|
73 template <class T> |
|
74 inline void CleanupResetAndDestroyPushL(T& aRef); |
|
75 |
|
76 #include "CleanupResetAndDestroy.inl" |
|
77 |
|
78 |
|
79 #endif //__CLEANUPRESETANDDESTROY_H__ |
|
80 |
|
81 // End of File |