|
1 /* |
|
2 * Copyright (c) 2006-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 #include <stdexcept> |
|
20 #include "cardinality.h" |
|
21 #include "deserialiser.h" |
|
22 #include "serialiser.h" |
|
23 |
|
24 const TInt KShiftCardinality8=1; |
|
25 const TInt KShiftCardinality16=2; |
|
26 const TInt KShiftCardinality32=3; |
|
27 |
|
28 const TUint8 KMaxTUint8=0xFF; |
|
29 const TUint16 KMaxTUint16=0xFFFF; |
|
30 |
|
31 Cardinality::Cardinality () |
|
32 { |
|
33 } |
|
34 |
|
35 Cardinality::~Cardinality () |
|
36 { |
|
37 } |
|
38 |
|
39 void Cardinality::Internalize(Deserialiser& des) |
|
40 { |
|
41 TUint8 x; |
|
42 des >> x; |
|
43 TUint32 n=x; |
|
44 if ((n&0x1)==0) |
|
45 n>>=KShiftCardinality8; |
|
46 else if ((n&0x2)==0) |
|
47 { |
|
48 des >> x; |
|
49 n+=x<<8; |
|
50 n>>=KShiftCardinality16; |
|
51 } |
|
52 else if ((n&0x4)==0) |
|
53 { |
|
54 des >> x; |
|
55 TUint32 t = x << 16; |
|
56 des >> x; |
|
57 t += x << 8; |
|
58 des >> x; |
|
59 t += x; |
|
60 n+=TUint32(iSize)<<8; // platform dependency |
|
61 n>>=KShiftCardinality32; |
|
62 } |
|
63 else |
|
64 { |
|
65 throw std::runtime_error("corrupt cardinality"); |
|
66 } |
|
67 iSize=n; |
|
68 } |
|
69 void Cardinality::Externalize(Serialiser& ser) |
|
70 { |
|
71 TUint32 n=iSize; |
|
72 if (n<=(KMaxTUint8>>KShiftCardinality8)) |
|
73 { |
|
74 TUint8 x = n<<KShiftCardinality8; |
|
75 ser << x; |
|
76 } |
|
77 else if (n<=(KMaxTUint16>>KShiftCardinality16)) |
|
78 { |
|
79 TUint16 x = (TUint16)(n<<KShiftCardinality16)+0x1; |
|
80 ser << x; |
|
81 } |
|
82 else |
|
83 { |
|
84 n = (n<<KShiftCardinality32)+0x3; |
|
85 ser << n; |
|
86 } |
|
87 |
|
88 } |
|
89 |