Commit | Line | Data |
---|---|---|
866e5b51 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others |
866e5b51 FC |
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 | /** | |
d37aaa7f | 16 | * A CTF string declaration. |
a511da0d | 17 | * |
d37aaa7f FC |
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 | |
866e5b51 FC |
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 | ||
9ac2eb62 MK |
38 | /** |
39 | * Generate a UTF8 string declaration | |
40 | */ | |
866e5b51 FC |
41 | public StringDeclaration() { |
42 | } | |
43 | ||
9ac2eb62 | 44 | /** |
a511da0d | 45 | * Generate an encoded string declaration |
9ac2eb62 MK |
46 | * @param encoding the encoding, utf8 or ascii |
47 | */ | |
866e5b51 FC |
48 | public StringDeclaration(Encoding encoding) { |
49 | this.encoding = encoding; | |
50 | } | |
51 | ||
52 | // ------------------------------------------------------------------------ | |
53 | // Getters/Setters/Predicates | |
54 | // ------------------------------------------------------------------------ | |
55 | ||
9ac2eb62 MK |
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 | */ | |
866e5b51 FC |
68 | public void setEncoding(Encoding encoding) { |
69 | this.encoding = encoding; | |
70 | } | |
71 | ||
fd74e6c1 MK |
72 | @Override |
73 | public long getAlignment() { | |
818bd3de EB |
74 | // See ctf 4.2.5: Strings are always aligned on byte size. |
75 | return 8; | |
fd74e6c1 | 76 | } |
866e5b51 FC |
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 | } |