Fix babeltrace-log incorrect timestamp type
[babeltrace.git] / types / integer.c
CommitLineData
fc93b2bd 1/*
ccd7e1c8 2 * integer.c
fc93b2bd 3 *
ccd7e1c8 4 * BabelTrace - Integer Type Converter
fc93b2bd 5 *
c054553d 6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
fc93b2bd 7 *
ccd7e1c8
MD
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:
fc93b2bd 14 *
ccd7e1c8
MD
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
fc93b2bd
MD
17 */
18
19#include <babeltrace/compiler.h>
698f0fe4 20#include <babeltrace/align.h>
4c8bfb7e 21#include <babeltrace/format.h>
fc93b2bd
MD
22#include <stdint.h>
23
c054553d 24static
f6625916 25struct definition *_integer_definition_new(struct declaration *declaration,
05c749e5 26 struct definition_scope *parent_scope,
98df1c9f
MD
27 GQuark field_name, int index,
28 const char *root_name);
c054553d 29static
e1151715 30void _integer_definition_free(struct definition *definition);
c054553d 31
c054553d 32static
f6625916 33void _integer_declaration_free(struct declaration *declaration)
90b676d7 34{
f6625916
MD
35 struct declaration_integer *integer_declaration =
36 container_of(declaration, struct declaration_integer, p);
37 g_free(integer_declaration);
90b676d7
MD
38}
39
f6625916 40struct declaration_integer *
add40b62 41 integer_declaration_new(size_t len, int byte_order,
81dee1bb
MD
42 int signedness, size_t alignment, int base,
43 enum ctf_string_encoding encoding)
698f0fe4 44{
f6625916 45 struct declaration_integer *integer_declaration;
698f0fe4 46
f6625916
MD
47 integer_declaration = g_new(struct declaration_integer, 1);
48 integer_declaration->p.id = CTF_TYPE_INTEGER;
f6625916 49 integer_declaration->p.alignment = alignment;
f6625916
MD
50 integer_declaration->p.declaration_free = _integer_declaration_free;
51 integer_declaration->p.definition_free = _integer_definition_free;
52 integer_declaration->p.definition_new = _integer_definition_new;
53 integer_declaration->p.ref = 1;
54 integer_declaration->len = len;
55 integer_declaration->byte_order = byte_order;
56 integer_declaration->signedness = signedness;
164078da 57 integer_declaration->base = base;
81dee1bb 58 integer_declaration->encoding = encoding;
f6625916 59 return integer_declaration;
698f0fe4 60}
c054553d
MD
61
62static
e1151715 63struct definition *
f6625916 64 _integer_definition_new(struct declaration *declaration,
05c749e5 65 struct definition_scope *parent_scope,
98df1c9f
MD
66 GQuark field_name, int index,
67 const char *root_name)
c054553d 68{
f6625916
MD
69 struct declaration_integer *integer_declaration =
70 container_of(declaration, struct declaration_integer, p);
e1151715 71 struct definition_integer *integer;
98df1c9f 72 int ret;
c054553d 73
e1151715 74 integer = g_new(struct definition_integer, 1);
f6625916
MD
75 declaration_ref(&integer_declaration->p);
76 integer->p.declaration = declaration;
77 integer->declaration = integer_declaration;
c054553d 78 integer->p.ref = 1;
98df1c9f
MD
79 /*
80 * Use INT_MAX order to ensure that all fields of the parent
81 * scope are seen as being prior to this scope.
82 */
83 integer->p.index = root_name ? INT_MAX : index;
b1a2f580 84 integer->p.name = field_name;
98df1c9f
MD
85 integer->p.path = new_definition_path(parent_scope, field_name,
86 root_name);
a35173fe 87 integer->p.scope = NULL;
c054553d 88 integer->value._unsigned = 0;
98df1c9f
MD
89 ret = register_field_definition(field_name, &integer->p,
90 parent_scope);
91 assert(!ret);
c054553d
MD
92 return &integer->p;
93}
94
95static
e1151715 96void _integer_definition_free(struct definition *definition)
c054553d 97{
e1151715
MD
98 struct definition_integer *integer =
99 container_of(definition, struct definition_integer, p);
c054553d 100
f6625916 101 declaration_unref(integer->p.declaration);
c054553d
MD
102 g_free(integer);
103}
This page took 0.028082 seconds and 4 git commands to generate.