ctf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / EnumDefinition.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others
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
13 package org.eclipse.linuxtools.ctf.core.event.types;
14
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
17
18 /**
19 * A CTF enum definition.
20 *
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.
23 *
24 * @version 1.0
25 * @author Matthew Khouzam
26 * @author Simon Marchi
27 */
28 public final class EnumDefinition extends SimpleDatatypeDefinition {
29
30 // ------------------------------------------------------------------------
31 // Attributes
32 // ------------------------------------------------------------------------
33
34 private final long fIntegerValue;
35
36 private final String fValue;
37
38 // ------------------------------------------------------------------------
39 // Constructors
40 // ------------------------------------------------------------------------
41
42 /**
43 * Constructor
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
54 */
55 public EnumDefinition(@NonNull EnumDeclaration declaration,
56 IDefinitionScope definitionScope, @NonNull String fieldName, IntegerDefinition intValue) {
57 super(declaration, definitionScope, fieldName);
58
59 fIntegerValue = intValue.getValue();
60 fValue = declaration.query(fIntegerValue);
61 }
62
63 // ------------------------------------------------------------------------
64 // Getters/Setters/Predicates
65 // ------------------------------------------------------------------------
66
67 /**
68 * Gets the value of the enum in string format so
69 * "Enum a{DAY="0", NIGHT="1"}; will return "DAY"
70 *
71 * @return the value of the enum.
72 */
73 public String getValue() {
74 return fValue;
75 }
76
77 @Override
78 public String getStringValue() {
79 return getValue();
80 }
81
82 /**
83 * Gets the value of the enum in string format so
84 * "Enum a{DAY="0", NIGHT="1"}; will return 0
85 *
86 * @return the value of the enum.
87 */
88 @Override
89 public Long getIntegerValue() {
90 return fIntegerValue;
91 }
92
93 @Override
94 public EnumDeclaration getDeclaration() {
95 return (EnumDeclaration) super.getDeclaration();
96 }
97
98 // ------------------------------------------------------------------------
99 // Operations
100 // ------------------------------------------------------------------------
101
102 @Override
103 public String toString() {
104 return "{ value = " + getValue() + //$NON-NLS-1$
105 ", container = " + fIntegerValue + //$NON-NLS-1$
106 " }"; //$NON-NLS-1$
107 }
108 }
This page took 0.0327539999999999 seconds and 5 git commands to generate.