ctf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / VariantDefinition.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 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 variant definition (similar to a C union).
20 *
21 * A variant is similar to a C union, only taking the minimum size of the types,
22 * it is a compound data type that contains other datatypes in fields. they are
23 * stored in an hashmap and indexed by names which are strings.
24 *
25 * @version 1.0
26 * @author Matthew Khouzam
27 * @author Simon Marchi
28 */
29 public final class VariantDefinition extends ScopedDefinition {
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34
35 private final Definition fDefinition;
36 private final String fCurrentField;
37 private final String fFieldName;
38
39 // ------------------------------------------------------------------------
40 // Constructors
41 // ------------------------------------------------------------------------
42
43 /**
44 * Constructor
45 *
46 * @param declaration
47 * the parent declaration
48 * @param definitionScope
49 * the parent scope
50 * @param selectedField
51 * the selected field
52 * @param fieldName
53 * the field name
54 * @param fieldValue
55 * the field value
56 * @since 3.0
57 */
58 public VariantDefinition(@NonNull VariantDeclaration declaration,
59 IDefinitionScope definitionScope, String selectedField, @NonNull String fieldName, Definition fieldValue) {
60 super(declaration, definitionScope, fieldName);
61
62 fFieldName = fieldName;
63 fCurrentField = selectedField;
64 fDefinition = fieldValue;
65
66 }
67
68 // ------------------------------------------------------------------------
69 // Getters/Setters/Predicates
70 // ------------------------------------------------------------------------
71
72 @Override
73 public VariantDeclaration getDeclaration() {
74 return (VariantDeclaration) super.getDeclaration();
75 }
76
77 /**
78 * Get the current field name
79 *
80 * @return the current field name
81 */
82 public String getCurrentFieldName() {
83 return fCurrentField;
84 }
85
86 /**
87 * Get the current field
88 *
89 * @return the current field
90 */
91 public Definition getCurrentField() {
92 return fDefinition;
93 }
94
95 // ------------------------------------------------------------------------
96 // Operations
97 // ------------------------------------------------------------------------
98
99 @Override
100 public Definition lookupDefinition(String lookupPath) {
101 if (lookupPath == null) {
102 return null;
103 }
104 if (lookupPath.equals(fFieldName)) {
105 return fDefinition;
106 }
107 return getDefinitionScope().lookupDefinition(lookupPath);
108 }
109
110 @Override
111 public String toString() {
112 return "{ " + getCurrentFieldName() + //$NON-NLS-1$
113 " = " + getCurrentField() + //$NON-NLS-1$
114 " }"; //$NON-NLS-1$
115 }
116 }
This page took 0.033149 seconds and 5 git commands to generate.