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 * <b><u>EnumDefinition</u></b>
20 public class EnumDefinition
extends Definition
{
22 // ------------------------------------------------------------------------
24 // ------------------------------------------------------------------------
26 private final EnumDeclaration declaration
;
28 private final IntegerDefinition integerValue
;
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 public EnumDefinition(EnumDeclaration declaration
,
37 IDefinitionScope definitionScope
, String fieldName
) {
38 super(definitionScope
, fieldName
);
40 this.declaration
= declaration
;
42 integerValue
= declaration
.getContainerType().createDefinition(
43 definitionScope
, fieldName
);
44 value
= ((Long
) integerValue
.getValue()).toString();
47 // ------------------------------------------------------------------------
48 // Getters/Setters/Predicates
49 // ------------------------------------------------------------------------
51 public String
getValue() {
55 public long getIntegerValue() {
56 return integerValue
.getValue();
59 public void setIntegerValue(long Value
) {
60 integerValue
.setValue(Value
);
61 value
= ((Long
) integerValue
.getValue()).toString();
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
69 public void read(BitBuffer input
) {
70 int align
= (int) declaration
.getAlignment();
71 int pos
= input
.position() + ((align
-(input
.position() % align
))%align
);
73 integerValue
.read(input
);
74 long val
= integerValue
.getValue();
76 // TODO: what to do if the integer value maps to no string for this
78 value
= declaration
.query(val
);