rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / ctf / core / event / types / CompoundDeclaration.java
1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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:
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.ctf.core.event.types;
14
15 /**
16 * Parent of sequences and arrays
17 *
18 * @author Matthew Khouzam
19 */
20 public abstract class CompoundDeclaration extends Declaration {
21
22 private static final int BIT_MASK = 0x03;
23 private static final int BITS_PER_BYTE = 8;
24
25 /**
26 * Get the element type
27 *
28 * @return the type of element in the array
29 */
30 public abstract IDeclaration getElementType();
31
32 @Override
33 public long getAlignment() {
34 return getElementType().getAlignment();
35 }
36
37 /**
38 * Sometimes, strings are encoded as an array of 1-byte integers (each one
39 * being an UTF-8 byte).
40 *
41 * @return true if this array is in fact an UTF-8 string. false if it's a
42 * "normal" array of generic Definition's.
43 */
44 public boolean isString() {
45 IDeclaration elementType = getElementType();
46 if (elementType instanceof IntegerDeclaration) {
47 IntegerDeclaration elemInt = (IntegerDeclaration) elementType;
48 return elemInt.isCharacter();
49 }
50 return false;
51 }
52
53 /**
54 * If an array contains 8 bit aligned 8 bit ints, it can be bulk read.
55 *
56 * @return true if this array 1 byte aligned. false if it's a "normal" array
57 * of generic Definition's.
58 * @since 1.0
59 */
60 public boolean isAlignedBytes() {
61 IDeclaration elementType = getElementType();
62 if (elementType instanceof IntegerDeclaration) {
63 IntegerDeclaration elemInt = (IntegerDeclaration) elementType;
64 return (elemInt.getLength() == BITS_PER_BYTE) && ((getAlignment() & BIT_MASK) == 0);
65 }
66 return false;
67 }
68
69 }
This page took 0.036846 seconds and 5 git commands to generate.