1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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
.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 SimpleDatatypeDefinition
{
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
= declaration
.query(integerValue
.getValue());
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 public String
getStringValue(){
78 * Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return 0
79 * @return the value of the enum.
82 public Long
getIntegerValue() {
83 return integerValue
.getValue();
87 * Sets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will set 0
88 * @param value The value of the enum.
90 public void setIntegerValue(long value
) {
91 integerValue
.setValue(value
);
92 this.value
= declaration
.query(value
);
96 public EnumDeclaration
getDeclaration() {
100 // ------------------------------------------------------------------------
102 // ------------------------------------------------------------------------
105 public void read(BitBuffer input
) {
106 int align
= (int) declaration
.getAlignment();
107 long pos
= input
.position() + ((align
- (input
.position() % align
)) % align
);
109 integerValue
.read(input
);
110 long val
= integerValue
.getValue();
112 // TODO: what to do if the integer value maps to no string for this
114 value
= declaration
.query(val
);
118 public String
toString() {
119 return "{ value = " + getValue() + //$NON-NLS-1$
120 ", container = " + integerValue
.toString() + //$NON-NLS-1$