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
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
19 * A CTF enum definition.
21 * The definition of a enum point basic data type. It will take the data
22 * from a trace and store it (and make it fit) as an integer and a string.
25 * @author Matthew Khouzam
26 * @author Simon Marchi
28 public class EnumDefinition
extends SimpleDatatypeDefinition
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
34 private final EnumDeclaration declaration
;
36 private final IntegerDefinition integerValue
;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
46 * @param declaration the parent declaration
47 * @param definitionScope the parent scope
48 * @param fieldName the field name
50 public EnumDefinition(EnumDeclaration declaration
,
51 IDefinitionScope definitionScope
, String fieldName
) {
52 super(definitionScope
, fieldName
);
54 this.declaration
= declaration
;
56 integerValue
= declaration
.getContainerType().createDefinition(
57 definitionScope
, fieldName
);
58 value
= declaration
.query(integerValue
.getValue());
61 // ------------------------------------------------------------------------
62 // Getters/Setters/Predicates
63 // ------------------------------------------------------------------------
66 * Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return "DAY"
67 * @return the value of the enum.
69 public String
getValue() {
74 public String
getStringValue(){
79 * Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return 0
80 * @return the value of the enum.
83 public Long
getIntegerValue() {
84 return integerValue
.getValue();
88 * Sets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will set 0
89 * @param value The value of the enum.
91 public void setIntegerValue(long value
) {
92 integerValue
.setValue(value
);
93 this.value
= declaration
.query(value
);
97 public EnumDeclaration
getDeclaration() {
101 // ------------------------------------------------------------------------
103 // ------------------------------------------------------------------------
106 public void read(BitBuffer input
) throws CTFReaderException
{
107 alignRead(input
, this.declaration
);
108 integerValue
.read(input
);
109 long val
= integerValue
.getValue();
111 // TODO: what to do if the integer value maps to no string for this
113 value
= declaration
.query(val
);
117 public String
toString() {
118 return "{ value = " + getValue() + //$NON-NLS-1$
119 ", container = " + integerValue
.toString() + //$NON-NLS-1$