X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Finteger.c;h=337641d7a3123018f14fc3f933285da8d35484ad;hp=5f9989b2111493ad0bdfe98c27805faf33d598e9;hb=c462e188f3e7819c7bc74f671038cdbf36e8c3c0;hpb=a35173fe7e72fe456cbd19db34a5ff7a09a0c7ff diff --git a/types/integer.c b/types/integer.c index 5f9989b2..337641d7 100644 --- a/types/integer.c +++ b/types/integer.c @@ -3,7 +3,9 @@ * * BabelTrace - Integer Type Converter * - * Copyright 2010, 2011 - Mathieu Desnoyers + * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation + * + * Author: Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -14,11 +16,20 @@ * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ #include #include #include +#include #include static @@ -40,7 +51,8 @@ void _integer_declaration_free(struct declaration *declaration) struct declaration_integer * integer_declaration_new(size_t len, int byte_order, int signedness, size_t alignment, int base, - enum ctf_string_encoding encoding) + enum ctf_string_encoding encoding, + struct ctf_clock *clock) { struct declaration_integer *integer_declaration; @@ -56,6 +68,7 @@ struct declaration_integer * integer_declaration->signedness = signedness; integer_declaration->base = base; integer_declaration->encoding = encoding; + integer_declaration->clock = clock; return integer_declaration; } @@ -101,3 +114,90 @@ void _integer_definition_free(struct definition *definition) declaration_unref(integer->p.declaration); g_free(integer); } + +enum ctf_string_encoding get_int_encoding(const struct definition *field) +{ + struct definition_integer *integer_definition; + const struct declaration_integer *integer_declaration; + + integer_definition = container_of(field, struct definition_integer, p); + integer_declaration = integer_definition->declaration; + + return integer_declaration->encoding; +} + +int get_int_base(const struct definition *field) +{ + struct definition_integer *integer_definition; + const struct declaration_integer *integer_declaration; + + integer_definition = container_of(field, struct definition_integer, p); + integer_declaration = integer_definition->declaration; + + return integer_declaration->base; +} + +size_t get_int_len(const struct definition *field) +{ + struct definition_integer *integer_definition; + const struct declaration_integer *integer_declaration; + + integer_definition = container_of(field, struct definition_integer, p); + integer_declaration = integer_definition->declaration; + + return integer_declaration->len; +} + +int get_int_byte_order(const struct definition *field) +{ + struct definition_integer *integer_definition; + const struct declaration_integer *integer_declaration; + + integer_definition = container_of(field, struct definition_integer, p); + integer_declaration = integer_definition->declaration; + + return integer_declaration->byte_order; +} + +int get_int_signedness(const struct definition *field) +{ + struct definition_integer *integer_definition; + const struct declaration_integer *integer_declaration; + + integer_definition = container_of(field, struct definition_integer, p); + integer_declaration = integer_definition->declaration; + + return integer_declaration->signedness; +} + +uint64_t get_unsigned_int(const struct definition *field) +{ + struct definition_integer *integer_definition; + const struct declaration_integer *integer_declaration; + + integer_definition = container_of(field, struct definition_integer, p); + integer_declaration = integer_definition->declaration; + + if (!integer_declaration->signedness) { + return integer_definition->value._unsigned; + } + fprintf(stderr, "[warning] Extracting unsigned value from a signed int (%s)\n", + g_quark_to_string(field->name)); + return (uint64_t)integer_definition->value._signed; +} + +int64_t get_signed_int(const struct definition *field) +{ + struct definition_integer *integer_definition; + const struct declaration_integer *integer_declaration; + + integer_definition = container_of(field, struct definition_integer, p); + integer_declaration = integer_definition->declaration; + + if (integer_declaration->signedness) { + return integer_definition->value._signed; + } + fprintf(stderr, "[warning] Extracting signed value from an unsigned int (%s)\n", + g_quark_to_string(field->name)); + return (int64_t)integer_definition->value._unsigned; +}