Commit | Line | Data |
---|---|---|
866e5b51 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others |
866e5b51 FC |
3 | * |
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 | |
8 | * | |
9 | * Contributors: Matthew Khouzam - Initial API and implementation | |
10 | * Contributors: Simon Marchi - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
f357bcd4 | 13 | package org.eclipse.tracecompass.ctf.core.event.types; |
866e5b51 | 14 | |
a4fa4e36 | 15 | import org.eclipse.jdt.annotation.NonNull; |
f357bcd4 | 16 | import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; |
866e5b51 FC |
17 | |
18 | /** | |
d37aaa7f | 19 | * A CTF enum definition. |
21fb02fa | 20 | * |
a4fa4e36 MK |
21 | * The definition of a enum point basic data type. It will take the data from a |
22 | * trace and store it (and make it fit) as an integer and a string. | |
d37aaa7f FC |
23 | * |
24 | * @version 1.0 | |
25 | * @author Matthew Khouzam | |
26 | * @author Simon Marchi | |
866e5b51 | 27 | */ |
a4fa4e36 | 28 | public final class EnumDefinition extends SimpleDatatypeDefinition { |
866e5b51 FC |
29 | |
30 | // ------------------------------------------------------------------------ | |
31 | // Attributes | |
32 | // ------------------------------------------------------------------------ | |
33 | ||
a4fa4e36 | 34 | private final long fIntegerValue; |
866e5b51 | 35 | |
a4fa4e36 | 36 | private final String fValue; |
866e5b51 FC |
37 | |
38 | // ------------------------------------------------------------------------ | |
39 | // Constructors | |
40 | // ------------------------------------------------------------------------ | |
41 | ||
9ac2eb62 MK |
42 | /** |
43 | * Constructor | |
a4fa4e36 MK |
44 | * |
45 | * @param declaration | |
46 | * the parent declaration | |
47 | * @param definitionScope | |
48 | * the parent scope | |
49 | * @param fieldName | |
50 | * the field name | |
51 | * @param intValue | |
52 | * the value of the enum | |
9ac2eb62 | 53 | */ |
a4fa4e36 MK |
54 | public EnumDefinition(@NonNull EnumDeclaration declaration, |
55 | IDefinitionScope definitionScope, @NonNull String fieldName, IntegerDefinition intValue) { | |
56 | super(declaration, definitionScope, fieldName); | |
866e5b51 | 57 | |
a4fa4e36 MK |
58 | fIntegerValue = intValue.getValue(); |
59 | fValue = declaration.query(fIntegerValue); | |
866e5b51 FC |
60 | } |
61 | ||
62 | // ------------------------------------------------------------------------ | |
63 | // Getters/Setters/Predicates | |
64 | // ------------------------------------------------------------------------ | |
65 | ||
9ac2eb62 | 66 | /** |
a4fa4e36 MK |
67 | * Gets the value of the enum in string format so |
68 | * "Enum a{DAY="0", NIGHT="1"}; will return "DAY" | |
69 | * | |
9ac2eb62 MK |
70 | * @return the value of the enum. |
71 | */ | |
866e5b51 | 72 | public String getValue() { |
a4fa4e36 | 73 | return fValue; |
866e5b51 FC |
74 | } |
75 | ||
21fb02fa | 76 | @Override |
a4fa4e36 | 77 | public String getStringValue() { |
21fb02fa MK |
78 | return getValue(); |
79 | } | |
80 | ||
9ac2eb62 | 81 | /** |
a4fa4e36 MK |
82 | * Gets the value of the enum in string format so |
83 | * "Enum a{DAY="0", NIGHT="1"}; will return 0 | |
84 | * | |
9ac2eb62 MK |
85 | * @return the value of the enum. |
86 | */ | |
21fb02fa MK |
87 | @Override |
88 | public Long getIntegerValue() { | |
a4fa4e36 | 89 | return fIntegerValue; |
866e5b51 FC |
90 | } |
91 | ||
9ac2eb62 MK |
92 | @Override |
93 | public EnumDeclaration getDeclaration() { | |
a4fa4e36 | 94 | return (EnumDeclaration) super.getDeclaration(); |
9ac2eb62 MK |
95 | } |
96 | ||
866e5b51 FC |
97 | // ------------------------------------------------------------------------ |
98 | // Operations | |
99 | // ------------------------------------------------------------------------ | |
100 | ||
419f09a8 SM |
101 | @Override |
102 | public String toString() { | |
103 | return "{ value = " + getValue() + //$NON-NLS-1$ | |
a4fa4e36 | 104 | ", container = " + fIntegerValue + //$NON-NLS-1$ |
419f09a8 SM |
105 | " }"; //$NON-NLS-1$ |
106 | } | |
866e5b51 | 107 | } |