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