Commit | Line | Data |
---|---|---|
53047a66 MK |
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 | *******************************************************************************/ | |
fd74e6c1 | 11 | |
53047a66 MK |
12 | package org.eclipse.linuxtools.ctf.core.event.types; |
13 | ||
14 | import java.nio.ByteOrder; | |
15 | ||
9ac2eb62 | 16 | /** |
d37aaa7f | 17 | * A CTF float declaration. |
056ebaf1 | 18 | * |
d37aaa7f | 19 | * The declaration of a floating point basic data type. |
9ac2eb62 | 20 | * |
d37aaa7f | 21 | * @version 1.0 |
9ac2eb62 | 22 | * @author Matthew Khouzam |
9ac2eb62 | 23 | */ |
53047a66 MK |
24 | public class FloatDeclaration implements IDeclaration { |
25 | ||
26 | // ------------------------------------------------------------------------ | |
27 | // Attributes | |
28 | // ------------------------------------------------------------------------ | |
29 | ||
30 | private final int mant; | |
31 | private final int exp; | |
32 | private final ByteOrder byteOrder; | |
fd74e6c1 | 33 | private final long alignment; |
53047a66 MK |
34 | |
35 | // ------------------------------------------------------------------------ | |
36 | // Constructors | |
37 | // ------------------------------------------------------------------------ | |
38 | ||
9ac2eb62 MK |
39 | /** |
40 | * Constructor | |
056ebaf1 AM |
41 | * |
42 | * @param exponent | |
43 | * The exponent size in bits | |
44 | * @param mantissa | |
45 | * The mantissa size in bits (+1 for sign) (see CTF spec) | |
46 | * @param byteOrder | |
47 | * The byte order | |
48 | * @param alignment | |
49 | * The alignment. Should be >= 1 | |
9ac2eb62 | 50 | */ |
53047a66 | 51 | public FloatDeclaration(int exponent, int mantissa, ByteOrder byteOrder, |
07002e0a | 52 | long alignment) { |
53047a66 MK |
53 | mant = mantissa; |
54 | exp = exponent; | |
55 | this.byteOrder = byteOrder; | |
056ebaf1 | 56 | this.alignment = Math.max(alignment, 1); |
53047a66 MK |
57 | |
58 | } | |
59 | ||
60 | // ------------------------------------------------------------------------ | |
a511da0d | 61 | // Getters/Setters/Predicates |
53047a66 MK |
62 | // ------------------------------------------------------------------------ |
63 | ||
53047a66 MK |
64 | /** |
65 | * @return the mant | |
66 | */ | |
67 | public int getMantissa() { | |
68 | return mant; | |
69 | } | |
70 | ||
71 | /** | |
72 | * @return the exp | |
73 | */ | |
74 | public int getExponent() { | |
75 | return exp; | |
76 | } | |
77 | ||
78 | /** | |
79 | * @return the byteOrder | |
80 | */ | |
81 | public ByteOrder getByteOrder() { | |
82 | return byteOrder; | |
83 | } | |
84 | ||
81c8e6f7 | 85 | @Override |
fd74e6c1 MK |
86 | public long getAlignment() { |
87 | return alignment; | |
88 | } | |
89 | ||
53047a66 MK |
90 | // ------------------------------------------------------------------------ |
91 | // Operations | |
92 | // ------------------------------------------------------------------------ | |
93 | ||
94 | @Override | |
81c8e6f7 | 95 | public FloatDefinition createDefinition(IDefinitionScope definitionScope, |
53047a66 MK |
96 | String fieldName) { |
97 | return new FloatDefinition(this, definitionScope, fieldName); | |
98 | } | |
99 | ||
100 | @Override | |
101 | public String toString() { | |
102 | /* Only used for debugging */ | |
103 | return "[declaration] float[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ | |
104 | } | |
105 | } |