Add missing _Imaginary 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,
e1151715 26 struct definition_scope *parent_scope);
c054553d 27static
e1151715 28void _integer_definition_free(struct definition *definition);
c054553d 29
4c8bfb7e
MD
30void integer_copy(struct stream_pos *dest, const struct format *fdest,
31 struct stream_pos *src, const struct format *fsrc,
e1151715 32 struct definition *definition)
fc93b2bd 33{
e1151715
MD
34 struct definition_integer *integer =
35 container_of(definition, struct definition_integer, p);
f6625916 36 struct declaration_integer *integer_declaration = integer->declaration;
fc93b2bd 37
f6625916 38 if (!integer_declaration->signedness) {
fc93b2bd
MD
39 uint64_t v;
40
f6625916
MD
41 v = fsrc->uint_read(src, integer_declaration);
42 fdest->uint_write(dest, integer_declaration, v);
fc93b2bd
MD
43 } else {
44 int64_t v;
45
f6625916
MD
46 v = fsrc->int_read(src, integer_declaration);
47 fdest->int_write(dest, integer_declaration, v);
fc93b2bd
MD
48 }
49}
698f0fe4 50
c054553d 51static
f6625916 52void _integer_declaration_free(struct declaration *declaration)
90b676d7 53{
f6625916
MD
54 struct declaration_integer *integer_declaration =
55 container_of(declaration, struct declaration_integer, p);
56 g_free(integer_declaration);
90b676d7
MD
57}
58
f6625916
MD
59struct declaration_integer *
60 integer_declaration_new(const char *name, size_t len, int byte_order,
e19c3d69 61 int signedness, size_t alignment)
698f0fe4 62{
f6625916 63 struct declaration_integer *integer_declaration;
698f0fe4 64
f6625916
MD
65 integer_declaration = g_new(struct declaration_integer, 1);
66 integer_declaration->p.id = CTF_TYPE_INTEGER;
67 integer_declaration->p.name = g_quark_from_string(name);
68 integer_declaration->p.alignment = alignment;
69 integer_declaration->p.copy = integer_copy;
70 integer_declaration->p.declaration_free = _integer_declaration_free;
71 integer_declaration->p.definition_free = _integer_definition_free;
72 integer_declaration->p.definition_new = _integer_definition_new;
73 integer_declaration->p.ref = 1;
74 integer_declaration->len = len;
75 integer_declaration->byte_order = byte_order;
76 integer_declaration->signedness = signedness;
77 return integer_declaration;
698f0fe4 78}
c054553d
MD
79
80static
e1151715 81struct definition *
f6625916 82 _integer_definition_new(struct declaration *declaration,
e1151715 83 struct definition_scope *parent_scope)
c054553d 84{
f6625916
MD
85 struct declaration_integer *integer_declaration =
86 container_of(declaration, struct declaration_integer, p);
e1151715 87 struct definition_integer *integer;
c054553d 88
e1151715 89 integer = g_new(struct definition_integer, 1);
f6625916
MD
90 declaration_ref(&integer_declaration->p);
91 integer->p.declaration = declaration;
92 integer->declaration = integer_declaration;
c054553d
MD
93 integer->p.ref = 1;
94 integer->value._unsigned = 0;
95 return &integer->p;
96}
97
98static
e1151715 99void _integer_definition_free(struct definition *definition)
c054553d 100{
e1151715
MD
101 struct definition_integer *integer =
102 container_of(definition, struct definition_integer, p);
c054553d 103
f6625916 104 declaration_unref(integer->p.declaration);
c054553d
MD
105 g_free(integer);
106}
This page took 0.027341 seconds and 4 git commands to generate.