Adding a test which do a sequence of seek BEGIN, LAST, BEGIN, LAST
[babeltrace.git] / types / string.c
... / ...
CommitLineData
1/*
2 * string.c
3 *
4 * BabelTrace - String Type Converter
5 *
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
7 *
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 */
20
21#include <babeltrace/compiler.h>
22#include <babeltrace/align.h>
23#include <babeltrace/format.h>
24#include <babeltrace/types.h>
25
26static
27struct definition *_string_definition_new(struct declaration *declaration,
28 struct definition_scope *parent_scope,
29 GQuark field_name, int index,
30 const char *root_name);
31static
32void _string_definition_free(struct definition *definition);
33
34static
35void _string_declaration_free(struct declaration *declaration)
36{
37 struct declaration_string *string_declaration =
38 container_of(declaration, struct declaration_string, p);
39 g_free(string_declaration);
40}
41
42struct declaration_string *
43 string_declaration_new(enum ctf_string_encoding encoding)
44{
45 struct declaration_string *string_declaration;
46
47 string_declaration = g_new(struct declaration_string, 1);
48 string_declaration->p.id = CTF_TYPE_STRING;
49 string_declaration->p.alignment = CHAR_BIT;
50 string_declaration->p.declaration_free = _string_declaration_free;
51 string_declaration->p.definition_new = _string_definition_new;
52 string_declaration->p.definition_free = _string_definition_free;
53 string_declaration->p.ref = 1;
54 string_declaration->encoding = encoding;
55 return string_declaration;
56}
57
58static
59struct definition *
60 _string_definition_new(struct declaration *declaration,
61 struct definition_scope *parent_scope,
62 GQuark field_name, int index,
63 const char *root_name)
64{
65 struct declaration_string *string_declaration =
66 container_of(declaration, struct declaration_string, p);
67 struct definition_string *string;
68 int ret;
69
70 string = g_new(struct definition_string, 1);
71 declaration_ref(&string_declaration->p);
72 string->p.declaration = declaration;
73 string->declaration = string_declaration;
74 string->p.ref = 1;
75 /*
76 * Use INT_MAX order to ensure that all fields of the parent
77 * scope are seen as being prior to this scope.
78 */
79 string->p.index = root_name ? INT_MAX : index;
80 string->p.name = field_name;
81 string->p.path = new_definition_path(parent_scope, field_name,
82 root_name);
83 string->p.scope = NULL;
84 string->value = NULL;
85 string->len = 0;
86 string->alloc_len = 0;
87 ret = register_field_definition(field_name, &string->p,
88 parent_scope);
89 assert(!ret);
90 return &string->p;
91}
92
93static
94void _string_definition_free(struct definition *definition)
95{
96 struct definition_string *string =
97 container_of(definition, struct definition_string, p);
98
99 declaration_unref(string->p.declaration);
100 g_free(string->value);
101 g_free(string);
102}
103
104enum ctf_string_encoding get_string_encoding(const struct definition *field)
105{
106 struct definition_string *string_definition;
107 const struct declaration_string *string_declaration;
108
109 string_definition = container_of(field, struct definition_string, p);
110 string_declaration = string_definition->declaration;
111
112 return string_declaration->encoding;
113}
114
115char *get_string(const struct definition *field)
116{
117 struct definition_string *string_definition =
118 container_of(field, struct definition_string, p);
119
120 assert(string_definition->value != NULL);
121
122 return string_definition->value;
123}
This page took 0.0229 seconds and 4 git commands to generate.