|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <string> |
|
17 #include <iostream> |
|
18 #include <sstream> |
|
19 #include <iomanip> |
|
20 |
|
21 #include "messagedefparser\enumidentifier.h" |
|
22 |
|
23 namespace Parser |
|
24 { |
|
25 void CEnumTypeIdentifier::AddValue(CEnumValueIdentifier* aEnumValue) |
|
26 { |
|
27 iEnumValues.push_back(aEnumValue); |
|
28 } |
|
29 |
|
30 |
|
31 void CEnumTypeIdentifier::Describe(const unsigned char* aData, unsigned int aLength, const void* aOptions, std::ostream& aOutput) const |
|
32 { |
|
33 unsigned int i; |
|
34 union |
|
35 { |
|
36 unsigned int u32; |
|
37 signed int i32; |
|
38 } value; |
|
39 |
|
40 if (iSigned) |
|
41 { |
|
42 if (iSize == 1) |
|
43 { |
|
44 char n = (char)(*aData); |
|
45 value.i32 = n; |
|
46 } |
|
47 else if (iSize == 2) |
|
48 { |
|
49 short int n = *reinterpret_cast<const short int*>(aData); |
|
50 value.i32 = n; |
|
51 } |
|
52 else if (iSize == 4) |
|
53 { |
|
54 value.i32 = *reinterpret_cast<const int*>(aData); |
|
55 } |
|
56 } |
|
57 else |
|
58 { |
|
59 unsigned int mask = ~0UL >> (32 - (iSize << 3)); |
|
60 value.u32 = *reinterpret_cast<const unsigned int*>(aData) & mask; |
|
61 } |
|
62 |
|
63 for (i=0; i<iEnumValues.size(); i++) |
|
64 { |
|
65 if (iEnumValues.at(i)->iValue == value.u32) |
|
66 { |
|
67 iEnumValues.at(i)->Describe(NULL, 0, aOptions, aOutput); |
|
68 return; |
|
69 } |
|
70 } |
|
71 |
|
72 CIntegerTypeIdentifier::Describe(aData, aLength, &iFormatOptions, aOutput); |
|
73 } |
|
74 |
|
75 /* |
|
76 void CEnumValueIdentifier::Describe(const unsigned char* aData, unsigned int aLength, const void* aOptions, std::ostream& aOutput) const |
|
77 { |
|
78 (void)aData; |
|
79 (void)aLength; |
|
80 (void)aOptions; |
|
81 aOutput << Name(); |
|
82 } |
|
83 */ |
|
84 |
|
85 } |
|
86 // namespace Parser |
|
87 |