|
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: Templated algorithms to simplify object handling |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 |
|
21 |
|
22 // ----------------------------------------------------------------------------- |
|
23 // TCacheObjectPacker::PackL() implementation. |
|
24 // ----------------------------------------------------------------------------- |
|
25 // |
|
26 template< class T > |
|
27 HBufC8* TCacheObjectPacker<T>::PackL( const T& aObj ) |
|
28 { |
|
29 // we don't know how large the returned descriptor is going to be |
|
30 CBufFlat* packBuf = CBufFlat::NewL( KObjectBufGranurality ); |
|
31 CleanupStack::PushL( packBuf ); |
|
32 |
|
33 RBufWriteStream ws; |
|
34 ws.Open( *packBuf ); // CSI: 65 # |
|
35 CleanupClosePushL( ws ); |
|
36 |
|
37 aObj.ExternalizeL( ws ); |
|
38 |
|
39 ws.CommitL(); |
|
40 CleanupStack::PopAndDestroy(); //ws |
|
41 |
|
42 // now CBufFlat contains the descriptor |
|
43 HBufC8* packBufDesc = packBuf->Ptr(0).AllocL(); |
|
44 |
|
45 CleanupStack::PopAndDestroy( packBuf ); |
|
46 return packBufDesc; |
|
47 |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // TCacheObjectPacker::UnPackL() implementation. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 template< class T > |
|
55 void TCacheObjectPacker<T>::UnPackL( T& aObj, const TDesC8& aPack ) |
|
56 { |
|
57 if ( ! aPack.Length() ) |
|
58 { |
|
59 // empty, don't attempt to unpack. |
|
60 return; |
|
61 } |
|
62 |
|
63 RDesReadStream rs; |
|
64 CleanupClosePushL( rs ); |
|
65 rs.Open( aPack ); // CSI: 65 # |
|
66 aObj.InternalizeL( rs ); |
|
67 CleanupStack::PopAndDestroy(); // rs |
|
68 |
|
69 } |
|
70 |