Fix missing header
[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
MD
26 struct definition_scope *parent_scope,
27 GQuark field_name, int index);
c054553d 28static
e1151715 29void _integer_definition_free(struct definition *definition);
c054553d 30
c054553d 31static
f6625916 32void _integer_declaration_free(struct declaration *declaration)
90b676d7 33{
f6625916
MD
34 struct declaration_integer *integer_declaration =
35 container_of(declaration, struct declaration_integer, p);
36 g_free(integer_declaration);
90b676d7
MD
37}
38
f6625916 39struct declaration_integer *
add40b62 40 integer_declaration_new(size_t len, int byte_order,
e19c3d69 41 int signedness, size_t alignment)
698f0fe4 42{
f6625916 43 struct declaration_integer *integer_declaration;
698f0fe4 44
f6625916
MD
45 integer_declaration = g_new(struct declaration_integer, 1);
46 integer_declaration->p.id = CTF_TYPE_INTEGER;
f6625916 47 integer_declaration->p.alignment = alignment;
f6625916
MD
48 integer_declaration->p.declaration_free = _integer_declaration_free;
49 integer_declaration->p.definition_free = _integer_definition_free;
50 integer_declaration->p.definition_new = _integer_definition_new;
51 integer_declaration->p.ref = 1;
52 integer_declaration->len = len;
53 integer_declaration->byte_order = byte_order;
54 integer_declaration->signedness = signedness;
55 return integer_declaration;
698f0fe4 56}
c054553d
MD
57
58static
e1151715 59struct definition *
f6625916 60 _integer_definition_new(struct declaration *declaration,
05c749e5
MD
61 struct definition_scope *parent_scope,
62 GQuark field_name, int index)
c054553d 63{
f6625916
MD
64 struct declaration_integer *integer_declaration =
65 container_of(declaration, struct declaration_integer, p);
e1151715 66 struct definition_integer *integer;
c054553d 67
e1151715 68 integer = g_new(struct definition_integer, 1);
f6625916
MD
69 declaration_ref(&integer_declaration->p);
70 integer->p.declaration = declaration;
71 integer->declaration = integer_declaration;
c054553d 72 integer->p.ref = 1;
05c749e5 73 integer->p.index = index;
c054553d
MD
74 integer->value._unsigned = 0;
75 return &integer->p;
76}
77
78static
e1151715 79void _integer_definition_free(struct definition *definition)
c054553d 80{
e1151715
MD
81 struct definition_integer *integer =
82 container_of(definition, struct definition_integer, p);
c054553d 83
f6625916 84 declaration_unref(integer->p.declaration);
c054553d
MD
85 g_free(integer);
86}
This page took 0.0262 seconds and 4 git commands to generate.