Add shared copyright to EfficiOS Inc. and Linux Foundation
[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
25static
26struct definition *_string_definition_new(struct declaration *declaration,
27 struct definition_scope *parent_scope,
28 GQuark field_name, int index,
29 const char *root_name);
30static
31void _string_definition_free(struct definition *definition);
32
33static
34void _string_declaration_free(struct declaration *declaration)
35{
36 struct declaration_string *string_declaration =
37 container_of(declaration, struct declaration_string, p);
38 g_free(string_declaration);
39}
40
41struct declaration_string *
42 string_declaration_new(enum ctf_string_encoding encoding)
43{
44 struct declaration_string *string_declaration;
45
46 string_declaration = g_new(struct declaration_string, 1);
47 string_declaration->p.id = CTF_TYPE_STRING;
48 string_declaration->p.alignment = CHAR_BIT;
49 string_declaration->p.declaration_free = _string_declaration_free;
50 string_declaration->p.definition_new = _string_definition_new;
51 string_declaration->p.definition_free = _string_definition_free;
52 string_declaration->p.ref = 1;
53 string_declaration->encoding = encoding;
54 return string_declaration;
55}
56
57static
58struct definition *
59 _string_definition_new(struct declaration *declaration,
60 struct definition_scope *parent_scope,
61 GQuark field_name, int index,
62 const char *root_name)
63{
64 struct declaration_string *string_declaration =
65 container_of(declaration, struct declaration_string, p);
66 struct definition_string *string;
67 int ret;
68
69 string = g_new(struct definition_string, 1);
70 declaration_ref(&string_declaration->p);
71 string->p.declaration = declaration;
72 string->declaration = string_declaration;
73 string->p.ref = 1;
74 /*
75 * Use INT_MAX order to ensure that all fields of the parent
76 * scope are seen as being prior to this scope.
77 */
78 string->p.index = root_name ? INT_MAX : index;
79 string->p.name = field_name;
80 string->p.path = new_definition_path(parent_scope, field_name,
81 root_name);
82 string->p.scope = NULL;
83 string->value = NULL;
84 string->len = 0;
85 string->alloc_len = 0;
86 ret = register_field_definition(field_name, &string->p,
87 parent_scope);
88 assert(!ret);
89 return &string->p;
90}
91
92static
93void _string_definition_free(struct definition *definition)
94{
95 struct definition_string *string =
96 container_of(definition, struct definition_string, p);
97
98 declaration_unref(string->p.declaration);
99 g_free(string->value);
100 g_free(string);
101}
This page took 0.022006 seconds and 4 git commands to generate.