ctf: fix performance issue with fighting optimisations
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / ctf / core / event / types / CompoundDeclaration.java
CommitLineData
7b4f13e6
MK
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
f357bcd4 13package org.eclipse.tracecompass.ctf.core.event.types;
7b4f13e6 14
7b4f13e6
MK
15/**
16 * Parent of sequences and arrays
17 *
18 * @author Matthew Khouzam
7b4f13e6
MK
19 */
20public abstract class CompoundDeclaration extends Declaration {
21
15f6223a
MK
22 private static final int BIT_MASK = 0x03;
23 private static final int BITS_PER_BYTE = 8;
24
7b4f13e6
MK
25 /**
26 * Get the element type
27 *
28 * @return the type of element in the array
29 */
30 public abstract IDeclaration getElementType();
31
9377d173
MK
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 */
15f6223a 44 public boolean isString() {
9377d173
MK
45 IDeclaration elementType = getElementType();
46 if (elementType instanceof IntegerDeclaration) {
47 IntegerDeclaration elemInt = (IntegerDeclaration) elementType;
48 return elemInt.isCharacter();
49 }
50 return false;
51 }
52
15f6223a
MK
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 */
59 public boolean isAlignedBytes() {
60 IDeclaration elementType = getElementType();
61 if (elementType instanceof IntegerDeclaration) {
62 IntegerDeclaration elemInt = (IntegerDeclaration) elementType;
63 return (elemInt.getLength() == BITS_PER_BYTE) && ((getAlignment() & BIT_MASK) == 0);
64 }
65 return false;
66 }
67
7b4f13e6 68}
This page took 0.046718 seconds and 5 git commands to generate.