Commit | Line | Data |
---|---|---|
866e5b51 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011-2012 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 java.util.HashMap; | |
16 | ||
17 | /** | |
18 | * <b><u>VariantDeclaration</u></b> | |
19 | */ | |
20 | public class VariantDeclaration implements IDeclaration { | |
21 | ||
22 | // ------------------------------------------------------------------------ | |
23 | // Attributes | |
24 | // ------------------------------------------------------------------------ | |
25 | ||
26 | private String tag = null; | |
fd74e6c1 | 27 | private long alignment; |
866e5b51 FC |
28 | private final HashMap<String, IDeclaration> fields = new HashMap<String, IDeclaration>(); |
29 | ||
30 | // ------------------------------------------------------------------------ | |
31 | // Constructors | |
32 | // ------------------------------------------------------------------------ | |
33 | ||
34 | public VariantDeclaration() { | |
35 | } | |
36 | ||
37 | // ------------------------------------------------------------------------ | |
38 | // Getters/Setters/Predicates | |
39 | // ------------------------------------------------------------------------ | |
40 | ||
41 | public boolean isTagged() { | |
42 | return tag != null; | |
43 | } | |
44 | ||
45 | public boolean hasField(String fieldTag) { | |
46 | return fields.containsKey(fieldTag); | |
47 | } | |
48 | ||
49 | public void setTag(String tag) { | |
50 | this.tag = tag; | |
51 | } | |
52 | ||
53 | public String getTag() { | |
54 | return this.tag; | |
55 | } | |
56 | ||
57 | public HashMap<String, IDeclaration> getFields() { | |
58 | return this.fields; | |
59 | } | |
60 | ||
fd74e6c1 MK |
61 | @Override |
62 | public long getAlignment() { | |
63 | return alignment; | |
64 | } | |
866e5b51 FC |
65 | // ------------------------------------------------------------------------ |
66 | // Operations | |
67 | // ------------------------------------------------------------------------ | |
68 | ||
69 | @Override | |
70 | public VariantDefinition createDefinition(IDefinitionScope definitionScope, | |
71 | String fieldName) { | |
72 | return new VariantDefinition(this, definitionScope, fieldName); | |
73 | } | |
74 | ||
75 | public void addField(String fieldTag, IDeclaration declaration) { | |
76 | fields.put(fieldTag, declaration); | |
fd74e6c1 | 77 | alignment = Math.max(alignment, declaration.getAlignment()); |
866e5b51 FC |
78 | } |
79 | ||
80 | @Override | |
81 | public String toString() { | |
82 | /* Only used for debugging */ | |
83 | return "[declaration] variant[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ | |
84 | } | |
85 | ||
86 | } |