|
1 /* |
|
2 * Copyright (c) 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 "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 using System; |
|
18 using System.Text; |
|
19 using System.Collections.Generic; |
|
20 using CrashItemLib.Crash; |
|
21 using CrashItemLib.Crash.Base; |
|
22 using CrashItemLib.Crash.Container; |
|
23 using CrashItemLib.Crash.Registers; |
|
24 |
|
25 namespace CrashItemLib.Crash.Registers.Visualization.Bits |
|
26 { |
|
27 public class CIRegisterVisBit : CIElement |
|
28 { |
|
29 #region Constructors |
|
30 public CIRegisterVisBit( CIContainer aContainer ) |
|
31 : base( aContainer ) |
|
32 { |
|
33 } |
|
34 |
|
35 public CIRegisterVisBit( CIContainer aContainer, int aIndex, TBit aValue, string aCategory, string aInterpretation ) |
|
36 : base( aContainer ) |
|
37 { |
|
38 Index = aIndex; |
|
39 Value = aValue; |
|
40 Category = aCategory; |
|
41 Interpretation = aInterpretation; |
|
42 } |
|
43 #endregion |
|
44 |
|
45 #region Constants |
|
46 public const string KReserved = "Reserved"; |
|
47 #endregion |
|
48 |
|
49 #region API |
|
50 #endregion |
|
51 |
|
52 #region Properties |
|
53 public override string Name |
|
54 { |
|
55 get { return Category; } |
|
56 set |
|
57 { |
|
58 Category = value; |
|
59 } |
|
60 } |
|
61 |
|
62 public string Category |
|
63 { |
|
64 get |
|
65 { |
|
66 // Return the "Reserved" category if we are reserved |
|
67 if ( IsReserved ) |
|
68 { |
|
69 return KReserved; |
|
70 } |
|
71 |
|
72 return iCategory; |
|
73 } |
|
74 set |
|
75 { |
|
76 iCategory = value; |
|
77 } |
|
78 } |
|
79 |
|
80 public int Index |
|
81 { |
|
82 get { return iIndex; } |
|
83 set { iIndex = value; } |
|
84 } |
|
85 |
|
86 public TBit Value |
|
87 { |
|
88 get { return iValue; } |
|
89 set { iValue = value; } |
|
90 } |
|
91 |
|
92 public string ValueString |
|
93 { |
|
94 get |
|
95 { |
|
96 switch ( Value ) |
|
97 { |
|
98 default: |
|
99 case TBit.EBitClear: |
|
100 return KBitClear; |
|
101 case TBit.EBitSet: |
|
102 return KBitSet; |
|
103 } |
|
104 } |
|
105 } |
|
106 |
|
107 public string Interpretation |
|
108 { |
|
109 get |
|
110 { |
|
111 // Don't return any interpretation if the bit is reserved |
|
112 if ( IsReserved ) |
|
113 { |
|
114 return string.Empty; |
|
115 } |
|
116 |
|
117 return iInterpretation; |
|
118 } |
|
119 set { iInterpretation = value; } |
|
120 } |
|
121 |
|
122 public bool IsReserved |
|
123 { |
|
124 get { return iIsReserved; } |
|
125 set { iIsReserved = value; } |
|
126 } |
|
127 |
|
128 public string ValueCharacter |
|
129 { |
|
130 get |
|
131 { |
|
132 if ( IsReserved ) |
|
133 { |
|
134 return KBitNotApplicable; |
|
135 } |
|
136 else |
|
137 { |
|
138 switch ( Value ) |
|
139 { |
|
140 case TBit.EBitSet: |
|
141 return iValueCharacters[ 0 ]; |
|
142 default: |
|
143 case TBit.EBitClear: |
|
144 return iValueCharacters[ 1 ]; |
|
145 } |
|
146 } |
|
147 } |
|
148 } |
|
149 |
|
150 public string this[ TBit aBit ] |
|
151 { |
|
152 get |
|
153 { |
|
154 switch( aBit ) |
|
155 { |
|
156 case TBit.EBitSet: |
|
157 return iValueCharacters[ 0 ]; |
|
158 default: |
|
159 case TBit.EBitClear: |
|
160 return iValueCharacters[ 1 ]; |
|
161 } |
|
162 } |
|
163 set |
|
164 { |
|
165 string bitVal = value; |
|
166 // |
|
167 if ( bitVal.Length > 1 ) |
|
168 { |
|
169 throw new ArgumentException( "Bit value must be a maximum of one character" ); |
|
170 } |
|
171 // |
|
172 switch ( aBit ) |
|
173 { |
|
174 case TBit.EBitSet: |
|
175 iValueCharacters[ 0 ] = bitVal; |
|
176 break; |
|
177 default: |
|
178 case TBit.EBitClear: |
|
179 iValueCharacters[ 1 ] = bitVal; |
|
180 break; |
|
181 } |
|
182 } |
|
183 } |
|
184 #endregion |
|
185 |
|
186 #region Internal methods |
|
187 #endregion |
|
188 |
|
189 #region Internal constants |
|
190 private const string KBitNotApplicable = "-"; |
|
191 private const string KBitClear = "0"; |
|
192 private const string KBitSet = "1"; |
|
193 #endregion |
|
194 |
|
195 #region From System.Object |
|
196 public override string ToString() |
|
197 { |
|
198 return ValueString; |
|
199 } |
|
200 #endregion |
|
201 |
|
202 #region Data members |
|
203 private string iCategory = string.Empty; |
|
204 private string iInterpretation = string.Empty; |
|
205 private int iIndex = 0; |
|
206 private TBit iValue = TBit.EBitClear; |
|
207 private bool iIsReserved = false; |
|
208 private string[] iValueCharacters = new string[] { "1", "" }; |
|
209 #endregion |
|
210 } |
|
211 } |