|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Thin cleanup wrapper |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // include guard for the whole file content |
|
22 #ifndef __TSHWCLEANUPWRAPPER_H__ |
|
23 #define __TSHWCLEANUPWRAPPER_H__ |
|
24 |
|
25 /** |
|
26 * Helper class to construct a TCleanupItem from any |
|
27 * public non static void (*method)() of a class |
|
28 * Usage: |
|
29 * TShwCleanupWrapper< %ClassName%, %MethodName% >( |
|
30 * %ClassPointer% ) |
|
31 * Example: |
|
32 * RPointerArray< MInterface > array; |
|
33 * CleanupStack::PushL( |
|
34 * TShwCleanupWrapper< |
|
35 * RPointerArray<MInterface>, |
|
36 * RPointerArray<MInterface>::ResetAndDestroy >( array ) ); |
|
37 */ |
|
38 template< class Object, void (Object::*Method)()> |
|
39 NONSHARABLE_CLASS( TShwCleanupWrapper ) : public TCleanupItem |
|
40 { |
|
41 public: |
|
42 /** |
|
43 * Constructor. |
|
44 * @param aInstance the object instance of the class |
|
45 */ |
|
46 inline TShwCleanupWrapper( Object& aInstance ) |
|
47 : TCleanupItem( &Cleanup, &aInstance ) |
|
48 {} |
|
49 |
|
50 private: |
|
51 /** |
|
52 * The cleanup callback delegator. Inlined as we dont want |
|
53 * extra method to be created, static so that base |
|
54 * class can call it without pointer to this. |
|
55 * @param aInstance the instance of TShwCallBack |
|
56 * @return the return value for the TCallBack |
|
57 */ |
|
58 inline static void Cleanup( TAny* aInstance ) |
|
59 { |
|
60 ( static_cast< Object* >( aInstance )->*Method )(); |
|
61 } |
|
62 }; |
|
63 |
|
64 /** |
|
65 * Helper function to create cleanup item without ugly template notations |
|
66 * @param aObject the object to call ResetAndDestroy in case of leave |
|
67 * |
|
68 * Usage: |
|
69 * ShwCleanupResetAndDestroyPushL( array ); |
|
70 * Example: |
|
71 * RPointerArray< MShwEffect > effects; |
|
72 * // put the array in cleanupstack in case CreateEffectsL leaves |
|
73 * ShwCleanupResetAndDestroyPushL( effects ); |
|
74 */ |
|
75 template< class T > |
|
76 void ShwCleanupResetAndDestroyPushL( T& aObject ) |
|
77 { |
|
78 CleanupStack::PushL( |
|
79 TShwCleanupWrapper< T, T::ResetAndDestroy >( aObject ) ); |
|
80 } |
|
81 |
|
82 #endif // __TSHWCLEANUPWRAPPER_H__ |