Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 26a8976d51cc36f81bba63e87673bc553a51f0aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
 * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
 *
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: Matthew Khouzam - Initial API and implementation
 * Contributors: Simon Marchi - Initial API and implementation
 *******************************************************************************/

package org.eclipse.linuxtools.ctf.core.event.types;

import java.nio.ByteOrder;

/**
 * A CTF integer declaration.
 * 
 * The declaration of a integer basic data type.
 *
 * @version 1.0
 * @author Matthew Khouzam
 * @author Simon Marchi
 */
public class IntegerDeclaration implements IDeclaration {

    // ------------------------------------------------------------------------
    // Attributes
    // ------------------------------------------------------------------------

    final private int length;
    final private boolean signed;
    final private int base;
    final private ByteOrder byteOrder;
    final private Encoding encoding;
    final private long alignment;
    final private String clock;

    // ------------------------------------------------------------------------
    // Constructors
    // ------------------------------------------------------------------------

    /**
     * Contructor
     * @param len the length in bits
     * @param signed is the integer signed? false == unsigned
     * @param base the base (10-16 are most common)
     * @param byteOrder Big endian little endian or other
     * @param encoding ascii, utf8 or none.
     * @param clock the clock path, can be null
     * @param alignment the minimum alignment
     */
    public IntegerDeclaration(int len, boolean signed, int base,
            ByteOrder byteOrder, Encoding encoding, String clock, long alignment) {
        this.length = len;
        this.signed = signed;
        this.base = base;
        this.byteOrder = byteOrder;
        this.encoding = encoding;
        this.clock = clock;
        this.alignment = alignment;
    }

    // ------------------------------------------------------------------------
    // Gettters/Setters/Predicates
    // ------------------------------------------------------------------------

    /**
     * Is the integer signed?
     * @return the is the integer signed
     */
    public boolean isSigned() {
        return signed;
    }

    /**
     * get the integer base commonly decimal or hex
     * @return the integer base
     */
    public int getBase() {
        return base;
    }

    /**
     * gets the byte order
     * @return the byte order
     */
    public ByteOrder getByteOrder() {
        return byteOrder;
    }

    /**
     * get encoding, chars are 8 bit ints
     * @return the encoding
     */
    public Encoding getEncoding() {
        return encoding;
    }

    /**
     * is the integer a character (8 bits and encoded?)
     * @return is the integer a char
     */
   public boolean isCharacter() {
        return (length == 8) && (encoding != Encoding.NONE);
    }

   /**
    * How many bits is this int
    * @return the length of the int
    */
    public int getLength() {
        return length;
    }

    @Override
    public long getAlignment(){
        return alignment;
    }

    /**
     * The integer's clock, since timestamps are stored in ints
     * @return the integer's clock, can be null. (most often it is)
     */
    public String getClock(){
        return clock;
    }
    // ------------------------------------------------------------------------
    // Operations
    // ------------------------------------------------------------------------

    @Override
    public IntegerDefinition createDefinition(IDefinitionScope definitionScope,
            String fieldName) {
        return new IntegerDefinition(this, definitionScope, fieldName);
    }

    @Override
    public String toString() {
        /* Only used for debugging */
        return "[declaration] integer[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
    }

}

Back to the top