1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.event
.types
;
15 import java
.util
.HashMap
;
19 * A CTFC variant declaration.
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.
26 * @author Matthew Khouzam
27 * @author Simon Marchi
29 public class VariantDeclaration
implements IDeclaration
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 private String tag
= null;
36 private static final long alignment
= 1;
37 private final Map
<String
, IDeclaration
> fields
= new HashMap
<>();
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
46 public VariantDeclaration() {
49 // ------------------------------------------------------------------------
50 // Getters/Setters/Predicates
51 // ------------------------------------------------------------------------
54 * @return Does the variant have a tag
56 public boolean isTagged() {
61 * Lookup if a field exists in the variant
62 * @param fieldTag the field tag name
63 * @return true = field tag exists
65 public boolean hasField(String fieldTag
) {
66 return fields
.containsKey(fieldTag
);
70 * Sets the tag in a variant
73 public void setTag(String tag
) {
78 * Gets current variant tag
79 * @return the variant tag.
81 public String
getTag() {
86 * Gets the fields of the variant
87 * @return the fields of the variant
90 public Map
<String
, IDeclaration
> getFields() {
95 public long getAlignment() {
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
103 public VariantDefinition
createDefinition(IDefinitionScope definitionScope
,
105 return new VariantDefinition(this, definitionScope
, fieldName
);
110 * Add a field to this CTF Variant
113 * The tag of the new field
115 * The Declaration of this new field
117 public void addField(String fieldTag
, IDeclaration declaration
) {
118 fields
.put(fieldTag
, declaration
);
122 public String
toString() {
123 /* Only used for debugging */
124 return "[declaration] variant[" + Integer
.toHexString(hashCode()) + ']'; //$NON-NLS-1$