Update pretty-print
[babeltrace.git] / types / string.c
1 /*
2 * string.c
3 *
4 * BabelTrace - String Type Converter
5 *
6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 */
18
19 #include <babeltrace/compiler.h>
20 #include <babeltrace/align.h>
21 #include <babeltrace/format.h>
22
23 static
24 struct definition *_string_definition_new(struct declaration *declaration,
25 struct definition_scope *parent_scope,
26 GQuark field_name, int index);
27 static
28 void _string_definition_free(struct definition *definition);
29
30 static
31 void _string_declaration_free(struct declaration *declaration)
32 {
33 struct declaration_string *string_declaration =
34 container_of(declaration, struct declaration_string, p);
35 g_free(string_declaration);
36 }
37
38 struct declaration_string *
39 string_declaration_new(enum ctf_string_encoding encoding)
40 {
41 struct declaration_string *string_declaration;
42
43 string_declaration = g_new(struct declaration_string, 1);
44 string_declaration->p.id = CTF_TYPE_STRING;
45 string_declaration->p.alignment = CHAR_BIT;
46 string_declaration->p.declaration_free = _string_declaration_free;
47 string_declaration->p.definition_new = _string_definition_new;
48 string_declaration->p.definition_free = _string_definition_free;
49 string_declaration->p.ref = 1;
50 string_declaration->encoding = encoding;
51 return string_declaration;
52 }
53
54 static
55 struct definition *
56 _string_definition_new(struct declaration *declaration,
57 struct definition_scope *parent_scope,
58 GQuark field_name, int index)
59 {
60 struct declaration_string *string_declaration =
61 container_of(declaration, struct declaration_string, p);
62 struct definition_string *string;
63
64 string = g_new(struct definition_string, 1);
65 declaration_ref(&string_declaration->p);
66 string->p.declaration = declaration;
67 string->declaration = string_declaration;
68 string->p.ref = 1;
69 string->p.index = index;
70 string->p.name = field_name;
71 string->p.path = new_definition_path(parent_scope, field_name);
72 string->value = NULL;
73 string->len = 0;
74 string->alloc_len = 0;
75 return &string->p;
76 }
77
78 static
79 void _string_definition_free(struct definition *definition)
80 {
81 struct definition_string *string =
82 container_of(definition, struct definition_string, p);
83
84 declaration_unref(string->p.declaration);
85 g_free(string->value);
86 g_free(string);
87 }
This page took 0.031553 seconds and 5 git commands to generate.