~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
13
package org.eclipse.linuxtools.ctf.core.event.types;
 
14
 
 
15
import java.nio.ByteOrder;
 
16
 
 
17
/**
 
18
 * A CTF integer declaration.
 
19
 * 
 
20
 * The declaration of a integer basic data type.
 
21
 *
 
22
 * @version 1.0
 
23
 * @author Matthew Khouzam
 
24
 * @author Simon Marchi
 
25
 */
 
26
public class IntegerDeclaration implements IDeclaration {
 
27
 
 
28
    // ------------------------------------------------------------------------
 
29
    // Attributes
 
30
    // ------------------------------------------------------------------------
 
31
 
 
32
    final private int length;
 
33
    final private boolean signed;
 
34
    final private int base;
 
35
    final private ByteOrder byteOrder;
 
36
    final private Encoding encoding;
 
37
    final private long alignment;
 
38
    final private String clock;
 
39
 
 
40
    // ------------------------------------------------------------------------
 
41
    // Constructors
 
42
    // ------------------------------------------------------------------------
 
43
 
 
44
    /**
 
45
     * Contructor
 
46
     * @param len the length in bits
 
47
     * @param signed is the integer signed? false == unsigned
 
48
     * @param base the base (10-16 are most common)
 
49
     * @param byteOrder Big endian little endian or other
 
50
     * @param encoding ascii, utf8 or none.
 
51
     * @param clock the clock path, can be null
 
52
     * @param alignment the minimum alignment
 
53
     */
 
54
    public IntegerDeclaration(int len, boolean signed, int base,
 
55
            ByteOrder byteOrder, Encoding encoding, String clock, long alignment) {
 
56
        this.length = len;
 
57
        this.signed = signed;
 
58
        this.base = base;
 
59
        this.byteOrder = byteOrder;
 
60
        this.encoding = encoding;
 
61
        this.clock = clock;
 
62
        this.alignment = alignment;
 
63
    }
 
64
 
 
65
    // ------------------------------------------------------------------------
 
66
    // Gettters/Setters/Predicates
 
67
    // ------------------------------------------------------------------------
 
68
 
 
69
    /**
 
70
     * Is the integer signed?
 
71
     * @return the is the integer signed
 
72
     */
 
73
    public boolean isSigned() {
 
74
        return signed;
 
75
    }
 
76
 
 
77
    /**
 
78
     * get the integer base commonly decimal or hex
 
79
     * @return the integer base
 
80
     */
 
81
    public int getBase() {
 
82
        return base;
 
83
    }
 
84
 
 
85
    /**
 
86
     * gets the byte order
 
87
     * @return the byte order
 
88
     */
 
89
    public ByteOrder getByteOrder() {
 
90
        return byteOrder;
 
91
    }
 
92
 
 
93
    /**
 
94
     * get encoding, chars are 8 bit ints
 
95
     * @return the encoding
 
96
     */
 
97
    public Encoding getEncoding() {
 
98
        return encoding;
 
99
    }
 
100
 
 
101
    /**
 
102
     * is the integer a character (8 bits and encoded?)
 
103
     * @return is the integer a char
 
104
     */
 
105
   public boolean isCharacter() {
 
106
        return (length == 8) && (encoding != Encoding.NONE);
 
107
    }
 
108
 
 
109
   /**
 
110
    * How many bits is this int
 
111
    * @return the length of the int
 
112
    */
 
113
    public int getLength() {
 
114
        return length;
 
115
    }
 
116
 
 
117
    @Override
 
118
    public long getAlignment(){
 
119
        return alignment;
 
120
    }
 
121
 
 
122
    /**
 
123
     * The integer's clock, since timestamps are stored in ints
 
124
     * @return the integer's clock, can be null. (most often it is)
 
125
     */
 
126
    public String getClock(){
 
127
        return clock;
 
128
    }
 
129
    // ------------------------------------------------------------------------
 
130
    // Operations
 
131
    // ------------------------------------------------------------------------
 
132
 
 
133
    @Override
 
134
    public IntegerDefinition createDefinition(IDefinitionScope definitionScope,
 
135
            String fieldName) {
 
136
        return new IntegerDefinition(this, definitionScope, fieldName);
 
137
    }
 
138
 
 
139
    @Override
 
140
    public String toString() {
 
141
        /* Only used for debugging */
 
142
        return "[declaration] integer[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
 
143
    }
 
144
 
 
145
}