internalize some CTF API
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / StringDefinition.java
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 org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
16
17 /**
18 * <b><u>StringDefinition</u></b>
19 */
20 public class StringDefinition extends Definition {
21
22 // ------------------------------------------------------------------------
23 // Attributes
24 // ------------------------------------------------------------------------
25
26 private StringDeclaration declaration;
27
28 private StringBuilder string;
29
30 // ------------------------------------------------------------------------
31 // Constructors
32 // ------------------------------------------------------------------------
33
34 public StringDefinition(StringDeclaration declaration,
35 IDefinitionScope definitionScope, String fieldName) {
36 super(definitionScope, fieldName);
37
38 this.declaration = declaration;
39
40 string = new StringBuilder();
41 }
42
43 // ------------------------------------------------------------------------
44 // Getters/Setters/Predicates
45 // ------------------------------------------------------------------------
46
47 public StringDeclaration getDeclaration() {
48 return declaration;
49 }
50
51 public void setDeclaration(StringDeclaration declaration) {
52 this.declaration = declaration;
53 }
54
55 public StringBuilder getString() {
56 return string;
57 }
58
59 public void setString(StringBuilder string) {
60 this.string = string;
61 }
62
63 public String getValue() {
64 return string.toString();
65 }
66
67 // ------------------------------------------------------------------------
68 // Operations
69 // ------------------------------------------------------------------------
70
71 @Override
72 public void read(BitBuffer input) {
73 string.setLength(0);
74
75 char c = (char) input.getInt(8, false);
76 while (c != 0) {
77 string.append(c);
78 c = (char) input.getInt(8, false);
79 }
80 }
81
82 @Override
83 public String toString() {
84 return '\"' + getValue() + '\"';
85 }
86
87 }
This page took 0.056493 seconds and 6 git commands to generate.