1 /*******************************************************************************
2 * Copyright (c) 2011-2012 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 org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
20 * A definition is like an object of a declaration class. It fills the
21 * declaration with values. <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>
29 * @author Matthew Khouzam
30 * @author Simon Marchi
32 public abstract class Definition
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 private final String fieldName
;
40 /** The complete path of this field */
41 private final String path
;
43 private final IDefinitionScope definitionScope
;
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
52 * @param definitionScope
53 * the definition is in a scope, (normally a struct) what is it?
55 * the name of the definition. (it is a field in the parent
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$
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
78 * Get the field name in its container.
80 * @return The field name
83 protected String
getFieldName() {
88 * Get the complete path of this field.
93 public String
getPath() {
98 * Get the definition scope in which this definition is found.
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)
103 * @return The definition scope
106 protected IDefinitionScope
getDefinitionScope() {
107 return definitionScope
;
110 // ------------------------------------------------------------------------
112 // ------------------------------------------------------------------------
116 * @return gets the declaration of a datatype
119 public abstract IDeclaration
getDeclaration();
122 * Read the definition from a bitbuffer
125 * the bitbuffer containing the data to read.
128 public abstract void read(BitBuffer input
);
131 * Offset the buffer position wrt the current alignment.
134 * The bitbuffer that is being read
136 * The declaration which has an alignment
139 protected static void alignRead(BitBuffer input
, IDeclaration declaration
){
140 long mask
= declaration
.getAlignment() -1;
142 * The alignment is a power of 2
144 long pos
= input
.position();
145 if ((pos
& mask
) == 0) {
148 pos
= (pos
+ mask
) & ~mask
;
154 public String
toString() {
155 return path
+ '[' + Integer
.toHexString(hashCode()) + ']';