More javadoc updates
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / EnumDefinition.java
1 /*******************************************************************************
2 * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.ctf.core.event.types;
14
15 import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
16
17 /**
18 * A CTF enum definition.
19 *
20 * The definition of a enum point basic data type. It will take the data
21 * from a trace and store it (and make it fit) as an integer and a string.
22 *
23 * @version 1.0
24 * @author Matthew Khouzam
25 * @author Simon Marchi
26 */
27 public class EnumDefinition extends Definition {
28
29 // ------------------------------------------------------------------------
30 // Attributes
31 // ------------------------------------------------------------------------
32
33 private final EnumDeclaration declaration;
34
35 private final IntegerDefinition integerValue;
36
37 private String value;
38
39 // ------------------------------------------------------------------------
40 // Constructors
41 // ------------------------------------------------------------------------
42
43 /**
44 * Constructor
45 * @param declaration the parent declaration
46 * @param definitionScope the parent scope
47 * @param fieldName the field name
48 */
49 public EnumDefinition(EnumDeclaration declaration,
50 IDefinitionScope definitionScope, String fieldName) {
51 super(definitionScope, fieldName);
52
53 this.declaration = declaration;
54
55 integerValue = declaration.getContainerType().createDefinition(
56 definitionScope, fieldName);
57 value = ((Long) integerValue.getValue()).toString();
58 }
59
60 // ------------------------------------------------------------------------
61 // Getters/Setters/Predicates
62 // ------------------------------------------------------------------------
63
64 /**
65 * Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return "DAY"
66 * @return the value of the enum.
67 */
68 public String getValue() {
69 return value;
70 }
71
72 /**
73 * Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return 0
74 * @return the value of the enum.
75 */
76 public long getIntegerValue() {
77 return integerValue.getValue();
78 }
79
80 /**
81 * Sets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will set 0
82 * @param Value The value of the enum.
83 */
84 public void setIntegerValue(long Value) {
85 integerValue.setValue(Value);
86 value = ((Long) integerValue.getValue()).toString();
87 }
88
89 @Override
90 public EnumDeclaration getDeclaration() {
91 return declaration;
92 }
93
94 // ------------------------------------------------------------------------
95 // Operations
96 // ------------------------------------------------------------------------
97
98 @Override
99 public void read(BitBuffer input) {
100 int align = (int) declaration.getAlignment();
101 int pos = input.position() + ((align-(input.position() % align))%align);
102 input.position(pos);
103 integerValue.read(input);
104 long val = integerValue.getValue();
105
106 // TODO: what to do if the integer value maps to no string for this
107 // integer ?
108 value = declaration.query(val);
109 }
110
111 }
This page took 0.033792 seconds and 5 git commands to generate.