972d2829a694895be865ea4d308b01690234151f
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / StringDeclaration.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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 /**
16 * A CTF string declaration.
17 *
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.
21 *
22 * @version 1.0
23 * @author Matthew Khouzam
24 * @author Simon Marchi
25 */
26 public class StringDeclaration implements IDeclaration {
27
28 // ------------------------------------------------------------------------
29 // Attributes
30 // ------------------------------------------------------------------------
31
32 private Encoding encoding = Encoding.UTF8;
33
34 // ------------------------------------------------------------------------
35 // Constructors
36 // ------------------------------------------------------------------------
37
38 /**
39 * Generate a UTF8 string declaration
40 */
41 public StringDeclaration() {
42 }
43
44 /**
45 * Generate an encoded string declaration
46 * @param encoding the encoding, utf8 or ascii
47 */
48 public StringDeclaration(Encoding encoding) {
49 this.encoding = encoding;
50 }
51
52 // ------------------------------------------------------------------------
53 // Getters/Setters/Predicates
54 // ------------------------------------------------------------------------
55
56 /**
57 *
58 * @return the character encoding.
59 */
60 public Encoding getEncoding() {
61 return encoding;
62 }
63
64 /**
65 *
66 * @param encoding the character encoding to set
67 */
68 public void setEncoding(Encoding encoding) {
69 this.encoding = encoding;
70 }
71
72 @Override
73 public long getAlignment() {
74 // See ctf 4.2.5: Strings are always aligned on byte size.
75 return 8;
76 }
77 // ------------------------------------------------------------------------
78 // Operations
79 // ------------------------------------------------------------------------
80
81 @Override
82 public StringDefinition createDefinition(IDefinitionScope definitionScope,
83 String fieldName) {
84 return new StringDefinition(this, definitionScope, fieldName);
85 }
86
87 @Override
88 public String toString() {
89 /* Only used for debugging */
90 return "[declaration] string[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
91 }
92
93 }
This page took 0.031623 seconds and 4 git commands to generate.