|
1 /* |
|
2 * Copyright (c) 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: Implementation of cleanup for pointer arrays |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef SVTMATCHINGCLEANUP_H |
|
20 #define SVTMATCHINGCLEANUP_H |
|
21 |
|
22 #include <e32base.h> |
|
23 |
|
24 /** |
|
25 * Template class for cleaning up arrays that have a ResetAndDestroy() function. |
|
26 * To be used with the CleanupStack. |
|
27 * |
|
28 * @lib svtmatching.lib |
|
29 * @since S60 v5.0 |
|
30 */ |
|
31 template <class T> |
|
32 class CleanupResetAndDestroy |
|
33 { |
|
34 public: // New functions |
|
35 |
|
36 inline static void PushL( T& aRef ); |
|
37 |
|
38 private: // New functions |
|
39 |
|
40 static void ResetAndDestroy( TAny *aPtr ); |
|
41 |
|
42 }; |
|
43 |
|
44 // INLINE FUNCTIONS |
|
45 template <class T> |
|
46 inline void CleanupResetAndDestroy< T >::PushL( T& aRef ) |
|
47 { |
|
48 CleanupStack::PushL( TCleanupItem( &ResetAndDestroy, &aRef ) ); |
|
49 } |
|
50 |
|
51 template <class T> |
|
52 void CleanupResetAndDestroy<T>::ResetAndDestroy( TAny *aPtr ) |
|
53 { |
|
54 ( static_cast< T* >( aPtr ) )->ResetAndDestroy(); |
|
55 ( static_cast< T* >( aPtr ) )->Close(); |
|
56 } |
|
57 |
|
58 template <class T> |
|
59 inline void CleanupResetAndDestroyPushL( T& aRef ) |
|
60 { CleanupResetAndDestroy< T >::PushL( aRef ); } |
|
61 |
|
62 #endif // SVTMATCHINGCLEANUP_H |