1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.event
.types
;
16 * A CTF string declaration.
18 * Strings are an array of bytes of variable size and are terminated by a '\0'
19 * "NULL" character. Their encoding is described in the TSDL meta-data. In
20 * absence of encoding attribute information, the default encoding is UTF-8.
23 * @author Matthew Khouzam
24 * @author Simon Marchi
26 public class StringDeclaration
implements IDeclaration
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 private Encoding encoding
= Encoding
.UTF8
;
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
39 * Generate a UTF8 string declaration
41 public StringDeclaration() {
45 * Generate an encoded string declaration
46 * @param encoding the encoding, utf8 or ascii
48 public StringDeclaration(Encoding encoding
) {
49 this.encoding
= encoding
;
52 // ------------------------------------------------------------------------
53 // Getters/Setters/Predicates
54 // ------------------------------------------------------------------------
58 * @return the character encoding.
60 public Encoding
getEncoding() {
66 * @param encoding the character encoding to set
68 public void setEncoding(Encoding encoding
) {
69 this.encoding
= encoding
;
73 public long getAlignment() {
74 // See ctf 4.2.5: Strings are always aligned on byte size.
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
82 public StringDefinition
createDefinition(IDefinitionScope definitionScope
,
84 return new StringDefinition(this, definitionScope
, fieldName
);
88 public String
toString() {
89 /* Only used for debugging */
90 return "[declaration] string[" + Integer
.toHexString(hashCode()) + ']'; //$NON-NLS-1$