|
1 /* |
|
2 * Copyright (c) 2008-2009 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 "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CLEANUPUTILS_INL |
|
20 #define CLEANUPUTILS_INL |
|
21 |
|
22 #include <scs/cleanuputils.h> |
|
23 |
|
24 template <class T> |
|
25 class CleanupResetAndDestroy |
|
26 { |
|
27 public: |
|
28 inline static void PushL(T& aRef); |
|
29 private: |
|
30 static void ResetAndDestroy(TAny *aPtr); |
|
31 }; |
|
32 |
|
33 template <class T> |
|
34 inline void CleanupResetAndDestroy<T>::PushL(T& aRef) |
|
35 { |
|
36 CleanupStack::PushL(TCleanupItem(&ResetAndDestroy,&aRef)); |
|
37 } |
|
38 |
|
39 template <class T> |
|
40 void CleanupResetAndDestroy<T>::ResetAndDestroy(TAny *aPtr) |
|
41 { |
|
42 static_cast<T*>(aPtr)->ResetAndDestroy(); |
|
43 } |
|
44 |
|
45 template <class T> |
|
46 inline void CleanupResetAndDestroyPushL(T& aRef) |
|
47 { |
|
48 CleanupResetAndDestroy<T>::PushL(aRef); |
|
49 } |
|
50 |
|
51 template <typename T> |
|
52 inline void DeleteObjectZ(T*& aPtr) |
|
53 { |
|
54 delete aPtr; |
|
55 aPtr=NULL; |
|
56 } |
|
57 |
|
58 inline HBufC8* ConvertBufferTo8bitL(const TDesC& aBuffer) |
|
59 { |
|
60 HBufC8* buf8 = HBufC8::NewLC(aBuffer.Length()); |
|
61 TPtr8 bufPtr8(buf8->Des()); |
|
62 bufPtr8.Copy(aBuffer); |
|
63 CleanupStack::Pop(buf8); |
|
64 return buf8; |
|
65 } |
|
66 |
|
67 inline HBufC* ConvertBufferTo16bitL(const TDesC8& aBuffer) |
|
68 { |
|
69 HBufC* buf = HBufC::NewLC(aBuffer.Length()); |
|
70 TPtr bufPtr(buf->Des()); |
|
71 bufPtr.Copy(aBuffer); |
|
72 CleanupStack::Pop(buf); |
|
73 return buf; |
|
74 } |
|
75 |
|
76 #endif /* CLEANUPUTILS_INL */ |