1 /*******************************************************************************
2 * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.event
.types
;
15 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
.io
.BitBuffer
;
18 * A CTF enum definition.
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.
24 * @author Matthew Khouzam
25 * @author Simon Marchi
27 public class EnumDefinition
extends Definition
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 private final EnumDeclaration declaration
;
35 private final IntegerDefinition integerValue
;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
45 * @param declaration the parent declaration
46 * @param definitionScope the parent scope
47 * @param fieldName the field name
49 public EnumDefinition(EnumDeclaration declaration
,
50 IDefinitionScope definitionScope
, String fieldName
) {
51 super(definitionScope
, fieldName
);
53 this.declaration
= declaration
;
55 integerValue
= declaration
.getContainerType().createDefinition(
56 definitionScope
, fieldName
);
57 value
= ((Long
) integerValue
.getValue()).toString();
60 // ------------------------------------------------------------------------
61 // Getters/Setters/Predicates
62 // ------------------------------------------------------------------------
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.
68 public String
getValue() {
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.
76 public long getIntegerValue() {
77 return integerValue
.getValue();
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.
84 public void setIntegerValue(long Value
) {
85 integerValue
.setValue(Value
);
86 value
= ((Long
) integerValue
.getValue()).toString();
90 public EnumDeclaration
getDeclaration() {
94 // ------------------------------------------------------------------------
96 // ------------------------------------------------------------------------
99 public void read(BitBuffer input
) {
100 int align
= (int) declaration
.getAlignment();
101 int pos
= input
.position() + ((align
-(input
.position() % align
))%align
);
103 integerValue
.read(input
);
104 long val
= integerValue
.getValue();
106 // TODO: what to do if the integer value maps to no string for this
108 value
= declaration
.query(val
);