Improve javadoc for ctfAdapter in Tmf.Core
[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 * <b><u>EnumDefinition</u></b>
19 */
20 public class EnumDefinition extends Definition {
21
22 // ------------------------------------------------------------------------
23 // Attributes
24 // ------------------------------------------------------------------------
25
26 private final EnumDeclaration declaration;
27
28 private final IntegerDefinition integerValue;
29
30 private String value;
31
32 // ------------------------------------------------------------------------
33 // Constructors
34 // ------------------------------------------------------------------------
35
36 /**
37 * Constructor
38 * @param declaration the parent declaration
39 * @param definitionScope the parent scope
40 * @param fieldName the field name
41 */
42 public EnumDefinition(EnumDeclaration declaration,
43 IDefinitionScope definitionScope, String fieldName) {
44 super(definitionScope, fieldName);
45
46 this.declaration = declaration;
47
48 integerValue = declaration.getContainerType().createDefinition(
49 definitionScope, fieldName);
50 value = ((Long) integerValue.getValue()).toString();
51 }
52
53 // ------------------------------------------------------------------------
54 // Getters/Setters/Predicates
55 // ------------------------------------------------------------------------
56
57 /**
58 * Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return "DAY"
59 * @return the value of the enum.
60 */
61 public String getValue() {
62 return value;
63 }
64
65 /**
66 * Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return 0
67 * @return the value of the enum.
68 */
69 public long getIntegerValue() {
70 return integerValue.getValue();
71 }
72
73 /**
74 * Sets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will set 0
75 * @param Value The value of the enum.
76 */
77 public void setIntegerValue(long Value) {
78 integerValue.setValue(Value);
79 value = ((Long) integerValue.getValue()).toString();
80 }
81
82 @Override
83 public EnumDeclaration getDeclaration() {
84 return declaration;
85 }
86
87 // ------------------------------------------------------------------------
88 // Operations
89 // ------------------------------------------------------------------------
90
91 @Override
92 public void read(BitBuffer input) {
93 int align = (int) declaration.getAlignment();
94 int pos = input.position() + ((align-(input.position() % align))%align);
95 input.position(pos);
96 integerValue.read(input);
97 long val = integerValue.getValue();
98
99 // TODO: what to do if the integer value maps to no string for this
100 // integer ?
101 value = declaration.query(val);
102 }
103
104 }
This page took 0.033236 seconds and 5 git commands to generate.