Contribute native CTF Parser (bug370499)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / StructDeclaration.java
CommitLineData
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
13package org.eclipse.linuxtools.ctf.core.event.types;
14
15import java.util.HashMap;
16import java.util.LinkedList;
17import java.util.List;
18
19/**
20 * <b><u>StructDeclaration</u></b>
21 */
22public class StructDeclaration implements IDeclaration {
23
24 // ------------------------------------------------------------------------
25 // Attributes
26 // ------------------------------------------------------------------------
27
28 private final HashMap<String, IDeclaration> fields = new HashMap<String, IDeclaration>();
29 private final List<String> fieldsList = new LinkedList<String>();
30 private long minAlign;
31
32 // ------------------------------------------------------------------------
33 // Constructors
34 // ------------------------------------------------------------------------
35
36 public StructDeclaration(long minAlign) {
37 this.minAlign = minAlign;
38 }
39
40 // ------------------------------------------------------------------------
41 // Getters/Setters/Predicates
42 // ------------------------------------------------------------------------
43
44 public long getMinAlign() {
45 return this.minAlign;
46 }
47
48 public void setMinAlign(long minAlign) {
49 this.minAlign = minAlign;
50 }
51
52 public boolean hasField(String name) {
53 return this.fields.containsKey(name);
54 }
55
56 public HashMap<String, IDeclaration> getFields() {
57 return this.fields;
58 }
59
60 public List<String> getFieldsList() {
61 return this.fieldsList;
62 }
63
64 // ------------------------------------------------------------------------
65 // Operations
66 // ------------------------------------------------------------------------
67
68 @Override
69 public StructDefinition createDefinition(IDefinitionScope definitionScope,
70 String fieldName) {
71 return new StructDefinition(this, definitionScope, fieldName);
72 }
73
74 public void addField(String name, IDeclaration declaration) {
75 // TODO: update the minAlign to be the max of minAlign and the align
76 // value of the new field.
77 this.fields.put(name, declaration);
78 this.fieldsList.add(name);
79 }
80
81 @Override
82 public String toString() {
83 /* Only used for debugging */
84 return "[declaration] struct[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
85 }
86
87}
This page took 0.027808 seconds and 5 git commands to generate.