|
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 the License "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-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 |
|
24 #ifndef __CLEANUPRESETANDDESTROY_H__ |
|
25 #define __CLEANUPRESETANDDESTROY_H__ |
|
26 |
|
27 /** |
|
28 * A utility class used by the templated function CleanupResetAndDestroyPushL() |
|
29 * to create a TCleanupItem item that will perform a close type operation on |
|
30 * the class T type object. |
|
31 **/ |
|
32 template <class T> |
|
33 class CleanupResetAndDestroy |
|
34 { |
|
35 public: |
|
36 inline static void PushL(T& aRef); |
|
37 |
|
38 private: |
|
39 static void ResetAndDestroy(TAny *aPtr); |
|
40 |
|
41 }; |
|
42 |
|
43 /** |
|
44 * Constructs and pushes a TCleanupItem object onto the cleanup stack. |
|
45 * |
|
46 * The TCleanupItem encapsulates: |
|
47 * |
|
48 * 1. a reference aRef to the object of type class T which is to be cleaned up |
|
49 * 2. an associated cleanup operation. |
|
50 * |
|
51 * The cleanup operation is the private static function ResetAndDestroy() of |
|
52 * the templated class CleanupResetAndDestroy and is invoked as a result of |
|
53 * a subsequent call to CleanupStack::PopAndDestroy(). |
|
54 * |
|
55 * CleanupResetAndDestroy::ResetAndDestroy() is passed a pointer to the |
|
56 * class T object to be cleaned up, and the function implements cleanup by |
|
57 * calling ResetAndDestroy() on the passed object. |
|
58 * The class T object must, therefore, define and implement (or inherit) a |
|
59 * ResetAndDestroy() member function. |
|
60 * |
|
61 * RPointerArray<HBufC> buffers; |
|
62 * CleanupResetAndDestroyPushL( buffers ); |
|
63 * buffers.Append( HBufC::NewL(100) ); |
|
64 * ... |
|
65 * CleanupStack::PopAndDestroy(); // <--- results in ResetAndDestroy() being called on "buffers". |
|
66 * ... |
|
67 * @endcode |
|
68 * |
|
69 * @param aRef A reference to a class T type object for which the cleanup item is being created. |
|
70 * @see TCleanupItem |
|
71 * @see CleanupResetAndDestroy |
|
72 * @see CleanupStack::PopAndDestroy() |
|
73 **/ |
|
74 template <class T> |
|
75 inline void CleanupResetAndDestroyPushL(T& aRef); |
|
76 |
|
77 #include "CleanupResetAndDestroy.inl" |
|
78 |
|
79 |
|
80 #endif //__CLEANUPRESETANDDESTROY_H__ |
|
81 |
|
82 // End of File |