package org.eclipse.linuxtools.ctf.core.event.types;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
/**
* A CTF string definition (similar to a C null-terminated byte array).
// Attributes
// ------------------------------------------------------------------------
- private StringDeclaration declaration;
+ private StringDeclaration fDeclaration;
- private StringBuilder string;
+ private String fString;
// ------------------------------------------------------------------------
// Constructors
/**
* Constructor
- * @param declaration the parent declaration
- * @param definitionScope the parent scope
- * @param fieldName the field name
+ *
+ * @param declaration
+ * the parent declaration
+ * @param definitionScope
+ * the parent scope
+ * @param fieldName
+ * the field name
*/
public StringDefinition(StringDeclaration declaration,
IDefinitionScope definitionScope, String fieldName) {
super(definitionScope, fieldName);
- this.declaration = declaration;
+ fDeclaration = declaration;
- string = new StringBuilder();
+ fString = ""; //$NON-NLS-1$
}
// ------------------------------------------------------------------------
@Override
public StringDeclaration getDeclaration() {
- return declaration;
+ return fDeclaration;
}
/**
* Sets the string declaration
- * @param declaration the declaration
+ *
+ * @param declaration
+ * the declaration
*/
public void setDeclaration(StringDeclaration declaration) {
- this.declaration = declaration;
+ fDeclaration = declaration;
}
/**
- * Gets the string
- * @return the stringbuilder
- */
- public StringBuilder getString() {
- return string;
- }
-
- /**
- * Sets a stringbuilder for the definition
- * @param string the stringbuilder
+ * Gets the string (value)
+ *
+ * @return the string
*/
- public void setString(StringBuilder string) {
- this.string = string;
+ public String getValue() {
+ return fString;
}
/**
- * Gets the string (value)
- * @return the string
+ * Sets the string (value)
+ *
+ * @param str the string
*/
- public String getValue() {
- return string.toString();
+ public void setValue(String str) {
+ fString = str;
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
@Override
- public void read(BitBuffer input) {
+ public void read(BitBuffer input) throws CTFReaderException {
/* Offset the buffer position wrt the current alignment */
- int align = (int) declaration.getAlignment();
- long pos = input.position() + ((align - (input.position() % align)) % align);
- input.position(pos);
-
- string.setLength(0);
+ alignRead(input, fDeclaration);
- char c = (char) input.getInt(8, false);
+ StringBuilder sb = new StringBuilder();
+ char c = (char) input.get(8, false);
while (c != 0) {
- string.append(c);
- c = (char) input.getInt(8, false);
+ sb.append(c);
+ c = (char) input.get(8, false);
}
+ fString = sb.toString();
}
@Override