[ctf] Fixes multiple coding style issues while reading ctf Types.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / Definition.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
486efb2e 15import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
866e5b51
FC
16
17/**
a511da0d 18 * A CTF definition
d37aaa7f
FC
19 *
20 * A definition is like an object of a declaration class. It fills the declaration
21 * with values. <br>
9ac2eb62
MK
22 * An example: <br>
23 * int i = 0; <br>
24 * <b>int</b> is the declaration.<br>
25 * <b>i</b> is the definition.<br>
26 * <b>0</b> is the value assigned to the definition, not the declaration.<br>
27 *
d37aaa7f
FC
28 * @version 1.0
29 * @author Matthew Khouzam
30 * @author Simon Marchi
866e5b51
FC
31 */
32public abstract class Definition {
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
37
0594c61c 38 private final String fieldName;
866e5b51 39
07002e0a 40 /** The complete path of this field */
0594c61c 41 private final String path;
866e5b51 42
0594c61c 43 private final IDefinitionScope definitionScope;
866e5b51
FC
44
45 // ------------------------------------------------------------------------
46 // Constructors
47 // ------------------------------------------------------------------------
48
9ac2eb62
MK
49 /**
50 * Constructor
51 *
52 * @param definitionScope
53 * the definition is in a scope, (normally a struct) what is it?
54 * @param fieldName
55 * the name of the definition. (it is a field in the parent
56 * scope)
57 */
866e5b51
FC
58 public Definition(IDefinitionScope definitionScope, String fieldName) {
59 this.definitionScope = definitionScope;
60 this.fieldName = fieldName;
61 if (definitionScope != null) {
62 String parentPath = definitionScope.getPath();
63 if (parentPath.length() > 0) {
64 path = parentPath + "." + fieldName; //$NON-NLS-1$
65 } else {
66 path = fieldName;
67 }
68 } else {
69 path = fieldName;
70 }
0594c61c 71 }
866e5b51 72
0594c61c
AM
73 // ------------------------------------------------------------------------
74 // Getters
75 // ------------------------------------------------------------------------
76
77 /**
78 * Get the field name in its container.
79 *
80 * @return The field name
81 * @since 2.0
82 */
83 protected String getFieldName() {
84 return fieldName;
85 }
86
87 /**
88 * Get the complete path of this field.
89 *
90 * @return The path
91 * @since 2.0
92 */
93 public String getPath() {
94 return path;
95 }
96
97 /**
98 * Get the definition scope in which this definition is found.
99 *
100 * The complete path of a definition is thus the path of the definition
101 * scope DOT the name of the definition (name of the field in its container)
102 *
103 * @return The definition scope
104 * @since 2.0
105 */
106 protected IDefinitionScope getDefinitionScope() {
107 return definitionScope;
866e5b51
FC
108 }
109
110 // ------------------------------------------------------------------------
111 // Operations
112 // ------------------------------------------------------------------------
113
9ac2eb62
MK
114 /**
115 *
116 * @return gets the declaration of a datatype
117 *
118 */
119 public abstract IDeclaration getDeclaration();
120
121 /**
122 * Read the definition from a bitbuffer
123 *
124 * @param input
125 * the bitbuffer containing the data to read.
486efb2e 126 * @since 2.0
9ac2eb62 127 */
866e5b51
FC
128 public abstract void read(BitBuffer input);
129
d6205f97
MK
130 /**
131 * Offset the buffer position wrt the current alignment.
132 *
133 * @param input
134 * The bitbuffer that is being read
135 * @param declaration
136 * The declaration which has an alignment
137 * @since 2.2
138 */
139 protected static void alignRead(BitBuffer input, IDeclaration declaration){
9f3709a8
AM
140 long align = declaration.getAlignment();
141 long pos = input.position() + ((align - (input.position() % align)) % align);
d6205f97
MK
142 input.position(pos);
143 }
144
866e5b51
FC
145 @Override
146 public String toString() {
147 return path + '[' + Integer.toHexString(hashCode()) + ']';
148 }
149}
This page took 0.037649 seconds and 5 git commands to generate.