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 | |
53 | * @since 3.0 | |
9ac2eb62 | 54 | */ |
a4fa4e36 MK |
55 | public EnumDefinition(@NonNull EnumDeclaration declaration, |
56 | IDefinitionScope definitionScope, @NonNull String fieldName, IntegerDefinition intValue) { | |
57 | super(declaration, definitionScope, fieldName); | |
866e5b51 | 58 | |
a4fa4e36 MK |
59 | fIntegerValue = intValue.getValue(); |
60 | fValue = declaration.query(fIntegerValue); | |
866e5b51 FC |
61 | } |
62 | ||
63 | // ------------------------------------------------------------------------ | |
64 | // Getters/Setters/Predicates | |
65 | // ------------------------------------------------------------------------ | |
66 | ||
9ac2eb62 | 67 | /** |
a4fa4e36 MK |
68 | * Gets the value of the enum in string format so |
69 | * "Enum a{DAY="0", NIGHT="1"}; will return "DAY" | |
70 | * | |
9ac2eb62 MK |
71 | * @return the value of the enum. |
72 | */ | |
866e5b51 | 73 | public String getValue() { |
a4fa4e36 | 74 | return fValue; |
866e5b51 FC |
75 | } |
76 | ||
21fb02fa | 77 | @Override |
a4fa4e36 | 78 | public String getStringValue() { |
21fb02fa MK |
79 | return getValue(); |
80 | } | |
81 | ||
9ac2eb62 | 82 | /** |
a4fa4e36 MK |
83 | * Gets the value of the enum in string format so |
84 | * "Enum a{DAY="0", NIGHT="1"}; will return 0 | |
85 | * | |
9ac2eb62 MK |
86 | * @return the value of the enum. |
87 | */ | |
21fb02fa MK |
88 | @Override |
89 | public Long getIntegerValue() { | |
a4fa4e36 | 90 | return fIntegerValue; |
866e5b51 FC |
91 | } |
92 | ||
9ac2eb62 MK |
93 | @Override |
94 | public EnumDeclaration getDeclaration() { | |
a4fa4e36 | 95 | return (EnumDeclaration) super.getDeclaration(); |
9ac2eb62 MK |
96 | } |
97 | ||
866e5b51 FC |
98 | // ------------------------------------------------------------------------ |
99 | // Operations | |
100 | // ------------------------------------------------------------------------ | |
101 | ||
419f09a8 SM |
102 | @Override |
103 | public String toString() { | |
104 | return "{ value = " + getValue() + //$NON-NLS-1$ | |
a4fa4e36 | 105 | ", container = " + fIntegerValue + //$NON-NLS-1$ |
419f09a8 SM |
106 | " }"; //$NON-NLS-1$ |
107 | } | |
866e5b51 | 108 | } |