1 /*******************************************************************************
2 * Copyright (c) 2011-2012 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
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
19 * A CTF string definition (similar to a C null-terminated byte array).
21 * Strings are an array of bytes of variable size and are terminated by a '\0'
22 * "NULL" character. Their encoding is described in the TSDL meta-data. In
23 * absence of encoding attribute information, the default encoding is UTF-8.
26 * @author Matthew Khouzam
27 * @author Simon Marchi
29 public class StringDefinition
extends Definition
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 private StringDeclaration fDeclaration
;
37 private String fString
;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
47 * the parent declaration
48 * @param definitionScope
53 public StringDefinition(StringDeclaration declaration
,
54 IDefinitionScope definitionScope
, String fieldName
) {
55 super(definitionScope
, fieldName
);
57 fDeclaration
= declaration
;
59 fString
= ""; //$NON-NLS-1$
62 // ------------------------------------------------------------------------
63 // Getters/Setters/Predicates
64 // ------------------------------------------------------------------------
67 public StringDeclaration
getDeclaration() {
72 * Sets the string declaration
77 public void setDeclaration(StringDeclaration declaration
) {
78 fDeclaration
= declaration
;
82 * Gets the string (value)
86 public String
getValue() {
91 * Sets the string (value)
93 * @param str the string
95 public void setValue(String str
) {
99 // ------------------------------------------------------------------------
101 // ------------------------------------------------------------------------
104 public void read(BitBuffer input
) throws CTFReaderException
{
105 /* Offset the buffer position wrt the current alignment */
106 alignRead(input
, fDeclaration
);
108 StringBuilder sb
= new StringBuilder();
109 char c
= (char) input
.get(8, false);
112 c
= (char) input
.get(8, false);
114 fString
= sb
.toString();
118 public String
toString() {
119 return '\"' + getValue() + '\"';