blob: f04f1d118cfcc789b1328cb9b50a4992781b6d6f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*******************************************************************************
* Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Matthew Khouzam - Initial API and implementation
* Contributors: Simon Marchi - Initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.ctf.core.event.types;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
/**
* A CTF enum definition.
*
* The definition of a enum point basic data type. It will take the data
* from a trace and store it (and make it fit) as an integer and a string.
*
* @version 1.0
* @author Matthew Khouzam
* @author Simon Marchi
*/
public class EnumDefinition extends SimpleDatatypeDefinition {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
private final EnumDeclaration declaration;
private final IntegerDefinition integerValue;
private String value;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
/**
* Constructor
* @param declaration the parent declaration
* @param definitionScope the parent scope
* @param fieldName the field name
*/
public EnumDefinition(EnumDeclaration declaration,
IDefinitionScope definitionScope, String fieldName) {
super(definitionScope, fieldName);
this.declaration = declaration;
integerValue = declaration.getContainerType().createDefinition(
definitionScope, fieldName);
value = ((Long) integerValue.getValue()).toString();
}
// ------------------------------------------------------------------------
// Getters/Setters/Predicates
// ------------------------------------------------------------------------
/**
* Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return "DAY"
* @return the value of the enum.
*/
public String getValue() {
return value;
}
@Override
public String getStringValue(){
return getValue();
}
/**
* Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return 0
* @return the value of the enum.
*/
@Override
public Long getIntegerValue() {
return integerValue.getValue();
}
/**
* Sets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will set 0
* @param Value The value of the enum.
*/
public void setIntegerValue(long Value) {
integerValue.setValue(Value);
value = ((Long) integerValue.getValue()).toString();
}
@Override
public EnumDeclaration getDeclaration() {
return declaration;
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@Override
public void read(BitBuffer input) {
int align = (int) declaration.getAlignment();
int pos = input.position() + ((align-(input.position() % align))%align);
input.position(pos);
integerValue.read(input);
long val = integerValue.getValue();
// TODO: what to do if the integer value maps to no string for this
// integer ?
value = declaration.query(val);
}
}
|