Python bindings: add has_intersection property to TraceCollection
[babeltrace.git] / types / enum.c
index 6fcbe683a9ab12a9c11042e5c2c809332dd3cca8..8394e1b35b70b4e2c58b2a9d9ed97d1293eb2c3c 100644 (file)
@@ -3,7 +3,9 @@
  *
  * BabelTrace - Enumeration Type
  *
- * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  *
  * 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 <babeltrace/compiler.h>
 #include <babeltrace/format.h>
+#include <babeltrace/types.h>
 #include <stdint.h>
 #include <glib.h>
 
+#if (__LONG_MAX__ == 2147483647L)
+#define WORD_SIZE      32
+#elif (__LONG_MAX__ == 9223372036854775807L)
+#define WORD_SIZE      64
+#else
+#error "Unknown long size."
+#endif
+
 static
-struct definition *_enum_definition_new(struct declaration *declaration,
+struct bt_definition *_enum_definition_new(struct bt_declaration *declaration,
                                        struct definition_scope *parent_scope,
                                        GQuark field_name, int index,
                                        const char *root_name);
 static
-void _enum_definition_free(struct definition *definition);
+void _enum_definition_free(struct bt_definition *definition);
 
 static
 void enum_range_set_free(void *ptr)
@@ -35,7 +54,7 @@ void enum_range_set_free(void *ptr)
        g_array_unref(ptr);
 }
 
-#if (__WORDSIZE == 32)
+#if (WORD_SIZE == 32)
 static inline
 gpointer get_uint_v(uint64_t *v)
 {
@@ -70,7 +89,7 @@ void enum_val_free(void *ptr)
 {
        g_free(ptr);
 }
-#else  /* __WORDSIZE != 32 */
+#else  /* WORD_SIZE != 32 */
 static inline
 gpointer get_uint_v(uint64_t *v)
 {
@@ -99,13 +118,13 @@ static
 void enum_val_free(void *ptr)
 {
 }
-#endif /* __WORDSIZE != 32 */
+#endif /* WORD_SIZE != 32 */
 
 /*
  * Returns a GArray or NULL.
  * Caller must release the GArray with g_array_unref().
  */
-GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
                               uint64_t v)
 {
        struct enum_range_to_quark *iter;
@@ -116,7 +135,7 @@ GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
                                 get_uint_v(&v));
 
        /* Range lookup */
-       cds_list_for_each_entry(iter, &enum_declaration->table.range_to_quark, node) {
+       bt_list_for_each_entry(iter, &enum_declaration->table.range_to_quark, node) {
                if (iter->range.start._unsigned > v || iter->range.end._unsigned < v)
                        continue;
                if (!ranges) {
@@ -125,18 +144,18 @@ GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
                        if (qs)
                                qs_len = qs->len;
                        ranges = g_array_sized_new(FALSE, TRUE,
-                                       sizeof(struct enum_range),
+                                       sizeof(GQuark),
                                        qs_len + 1);
                        g_array_set_size(ranges, qs_len + 1);
                        if (qs)
                                memcpy(ranges->data, qs->data,
-                                      sizeof(struct enum_range) * qs_len);
-                       g_array_index(ranges, struct enum_range, qs_len) = iter->range;
+                                      sizeof(GQuark) * qs_len);
+                       g_array_index(ranges, GQuark, qs_len) = iter->quark;
                } else {
                        size_t qs_len = ranges->len;
 
                        g_array_set_size(ranges, qs_len + 1);
-                       g_array_index(ranges, struct enum_range, qs_len) = iter->range;
+                       g_array_index(ranges, GQuark, qs_len) = iter->quark;
                }
        }
        if (!ranges) {
@@ -152,7 +171,7 @@ GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
  * Returns a GArray or NULL.
  * Caller must release the GArray with g_array_unref().
  */
-GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
                              int64_t v)
 {
        struct enum_range_to_quark *iter;
@@ -163,7 +182,7 @@ GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
                                 get_int_v(&v));
 
        /* Range lookup */
-       cds_list_for_each_entry(iter, &enum_declaration->table.range_to_quark, node) {
+       bt_list_for_each_entry(iter, &enum_declaration->table.range_to_quark, node) {
                if (iter->range.start._signed > v || iter->range.end._signed < v)
                        continue;
                if (!ranges) {
@@ -172,18 +191,18 @@ GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
                        if (qs)
                                qs_len = qs->len;
                        ranges = g_array_sized_new(FALSE, TRUE,
-                                       sizeof(struct enum_range),
+                                       sizeof(GQuark),
                                        qs_len + 1);
                        g_array_set_size(ranges, qs_len + 1);
                        if (qs)
                                memcpy(ranges->data, qs->data,
-                                      sizeof(struct enum_range) * qs_len);
-                       g_array_index(ranges, struct enum_range, qs_len) = iter->range;
+                                      sizeof(GQuark) * qs_len);
+                       g_array_index(ranges, GQuark, qs_len) = iter->quark;
                } else {
                        size_t qs_len = ranges->len;
 
                        g_array_set_size(ranges, qs_len + 1);
-                       g_array_index(ranges, struct enum_range, qs_len) = iter->range;
+                       g_array_index(ranges, GQuark, qs_len) = iter->quark;
                }
        }
        if (!ranges) {
@@ -196,7 +215,7 @@ GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
 }
 
 static
-void enum_unsigned_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
+void bt_enum_unsigned_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
                         uint64_t v, GQuark q)
 {
        uint64_t *valuep;
@@ -208,12 +227,12 @@ void enum_unsigned_insert_value_to_quark_set(struct declaration_enum *enum_decla
                array = g_array_sized_new(FALSE, TRUE, sizeof(GQuark), 1);
                g_array_set_size(array, 1);
                g_array_index(array, GQuark, array->len - 1) = q;
-#if (__WORDSIZE == 32)
+#if (WORD_SIZE == 32)
                valuep = g_new(uint64_t, 1);
                *valuep = v;
-#else  /* __WORDSIZE != 32 */
+#else  /* WORD_SIZE != 32 */
                valuep = get_uint_v(&v);
-#endif /* __WORDSIZE != 32 */
+#endif /* WORD_SIZE != 32 */
                g_hash_table_insert(enum_declaration->table.value_to_quark_set, valuep, array);
        } else {
                g_array_set_size(array, array->len + 1);
@@ -222,7 +241,7 @@ void enum_unsigned_insert_value_to_quark_set(struct declaration_enum *enum_decla
 }
 
 static
-void enum_signed_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
+void bt_enum_signed_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
                        int64_t v, GQuark q)
 {
        int64_t *valuep;
@@ -234,12 +253,12 @@ void enum_signed_insert_value_to_quark_set(struct declaration_enum *enum_declara
                array = g_array_sized_new(FALSE, TRUE, sizeof(GQuark), 1);
                g_array_set_size(array, 1);
                g_array_index(array, GQuark, array->len - 1) = q;
-#if (__WORDSIZE == 32)
+#if (WORD_SIZE == 32)
                valuep = g_new(int64_t, 1);
                *valuep = v;
-#else  /* __WORDSIZE != 32 */
+#else  /* WORD_SIZE != 32 */
                valuep = get_int_v(&v);
-#endif /* __WORDSIZE != 32 */
+#endif /* WORD_SIZE != 32 */
                g_hash_table_insert(enum_declaration->table.value_to_quark_set, valuep, array);
        } else {
                g_array_set_size(array, array->len + 1);
@@ -247,7 +266,7 @@ void enum_signed_insert_value_to_quark_set(struct declaration_enum *enum_declara
        }
 }
 
-GArray *enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
                                GQuark q)
 {
        return g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
@@ -255,39 +274,39 @@ GArray *enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
 }
 
 static
-void enum_signed_insert_range_to_quark(struct declaration_enum *enum_declaration,
+void bt_enum_signed_insert_range_to_quark(struct declaration_enum *enum_declaration,
                         int64_t start, int64_t end, GQuark q)
 {
        struct enum_range_to_quark *rtoq;
 
        rtoq = g_new(struct enum_range_to_quark, 1);
-       cds_list_add(&rtoq->node, &enum_declaration->table.range_to_quark);
+       bt_list_add(&rtoq->node, &enum_declaration->table.range_to_quark);
        rtoq->range.start._signed = start;
        rtoq->range.end._signed = end;
        rtoq->quark = q;
 }
 
 static
-void enum_unsigned_insert_range_to_quark(struct declaration_enum *enum_declaration,
+void bt_enum_unsigned_insert_range_to_quark(struct declaration_enum *enum_declaration,
                         uint64_t start, uint64_t end, GQuark q)
 {
        struct enum_range_to_quark *rtoq;
 
        rtoq = g_new(struct enum_range_to_quark, 1);
-       cds_list_add(&rtoq->node, &enum_declaration->table.range_to_quark);
+       bt_list_add(&rtoq->node, &enum_declaration->table.range_to_quark);
        rtoq->range.start._unsigned = start;
        rtoq->range.end._unsigned = end;
        rtoq->quark = q;
 }
 
-void enum_signed_insert(struct declaration_enum *enum_declaration,
+void bt_enum_signed_insert(struct declaration_enum *enum_declaration,
                         int64_t start, int64_t end, GQuark q)
 {
        GArray *array;
        struct enum_range *range;
 
        if (start == end) {
-               enum_signed_insert_value_to_quark_set(enum_declaration, start, q);
+               bt_enum_signed_insert_value_to_quark_set(enum_declaration, start, q);
        } else {
                if (start > end) {
                        uint64_t tmp;
@@ -296,7 +315,7 @@ void enum_signed_insert(struct declaration_enum *enum_declaration,
                        start = end;
                        end = tmp;
                }
-               enum_signed_insert_range_to_quark(enum_declaration, start, end, q);
+               bt_enum_signed_insert_range_to_quark(enum_declaration, start, end, q);
        }
 
        array = g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
@@ -314,7 +333,7 @@ void enum_signed_insert(struct declaration_enum *enum_declaration,
        range->end._signed = end;
 }
 
-void enum_unsigned_insert(struct declaration_enum *enum_declaration,
+void bt_enum_unsigned_insert(struct declaration_enum *enum_declaration,
                          uint64_t start, uint64_t end, GQuark q)
 {
        GArray *array;
@@ -322,7 +341,7 @@ void enum_unsigned_insert(struct declaration_enum *enum_declaration,
 
 
        if (start == end) {
-               enum_unsigned_insert_value_to_quark_set(enum_declaration, start, q);
+               bt_enum_unsigned_insert_value_to_quark_set(enum_declaration, start, q);
        } else {
                if (start > end) {
                        uint64_t tmp;
@@ -331,7 +350,7 @@ void enum_unsigned_insert(struct declaration_enum *enum_declaration,
                        start = end;
                        end = tmp;
                }
-               enum_unsigned_insert_range_to_quark(enum_declaration, start, end, q);
+               bt_enum_unsigned_insert_range_to_quark(enum_declaration, start, end, q);
        }
 
        array = g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
@@ -349,30 +368,30 @@ void enum_unsigned_insert(struct declaration_enum *enum_declaration,
        range->end._unsigned = end;
 }
 
-size_t enum_get_nr_enumerators(struct declaration_enum *enum_declaration)
+size_t bt_enum_get_nr_enumerators(struct declaration_enum *enum_declaration)
 {
        return g_hash_table_size(enum_declaration->table.quark_to_range_set);
 }
 
 static
-void _enum_declaration_free(struct declaration *declaration)
+void _enum_declaration_free(struct bt_declaration *declaration)
 {
        struct declaration_enum *enum_declaration =
                container_of(declaration, struct declaration_enum, p);
        struct enum_range_to_quark *iter, *tmp;
 
        g_hash_table_destroy(enum_declaration->table.value_to_quark_set);
-       cds_list_for_each_entry_safe(iter, tmp, &enum_declaration->table.range_to_quark, node) {
-               cds_list_del(&iter->node);
+       bt_list_for_each_entry_safe(iter, tmp, &enum_declaration->table.range_to_quark, node) {
+               bt_list_del(&iter->node);
                g_free(iter);
        }
        g_hash_table_destroy(enum_declaration->table.quark_to_range_set);
-       declaration_unref(&enum_declaration->integer_declaration->p);
+       bt_declaration_unref(&enum_declaration->integer_declaration->p);
        g_free(enum_declaration);
 }
 
 struct declaration_enum *
-       enum_declaration_new(struct declaration_integer *integer_declaration)
+       bt_enum_declaration_new(struct declaration_integer *integer_declaration)
 {
        struct declaration_enum *enum_declaration;
 
@@ -382,11 +401,11 @@ struct declaration_enum *
                                                            enum_val_equal,
                                                            enum_val_free,
                                                            enum_range_set_free);
-       CDS_INIT_LIST_HEAD(&enum_declaration->table.range_to_quark);
+       BT_INIT_LIST_HEAD(&enum_declaration->table.range_to_quark);
        enum_declaration->table.quark_to_range_set = g_hash_table_new_full(g_direct_hash,
                                                        g_direct_equal,
                                                        NULL, enum_range_set_free);
-       declaration_ref(&integer_declaration->p);
+       bt_declaration_ref(&integer_declaration->p);
        enum_declaration->integer_declaration = integer_declaration;
        enum_declaration->p.id = CTF_TYPE_ENUM;
        enum_declaration->p.alignment = 1;
@@ -398,8 +417,8 @@ struct declaration_enum *
 }
 
 static
-struct definition *
-       _enum_definition_new(struct declaration *declaration,
+struct bt_definition *
+       _enum_definition_new(struct bt_declaration *declaration,
                             struct definition_scope *parent_scope,
                             GQuark field_name, int index,
                             const char *root_name)
@@ -407,11 +426,11 @@ struct definition *
        struct declaration_enum *enum_declaration =
                container_of(declaration, struct declaration_enum, p);
        struct definition_enum *_enum;
-       struct definition *definition_integer_parent;
+       struct bt_definition *definition_integer_parent;
        int ret;
 
        _enum = g_new(struct definition_enum, 1);
-       declaration_ref(&enum_declaration->p);
+       bt_declaration_ref(&enum_declaration->p);
        _enum->p.declaration = declaration;
        _enum->declaration = enum_declaration;
        _enum->p.ref = 1;
@@ -421,10 +440,10 @@ struct definition *
         */
        _enum->p.index = root_name ? INT_MAX : index;
        _enum->p.name = field_name;
-       _enum->p.path = new_definition_path(parent_scope, field_name, root_name);
-       _enum->p.scope = new_definition_scope(parent_scope, field_name, root_name);
+       _enum->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+       _enum->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
        _enum->value = NULL;
-       ret = register_field_definition(field_name, &_enum->p,
+       ret = bt_register_field_definition(field_name, &_enum->p,
                                        parent_scope);
        assert(!ret);
        definition_integer_parent =
@@ -437,14 +456,14 @@ struct definition *
 }
 
 static
-void _enum_definition_free(struct definition *definition)
+void _enum_definition_free(struct bt_definition *definition)
 {
        struct definition_enum *_enum =
                container_of(definition, struct definition_enum, p);
 
-       definition_unref(&_enum->integer->p);
-       free_definition_scope(_enum->p.scope);
-       declaration_unref(_enum->p.declaration);
+       bt_definition_unref(&_enum->integer->p);
+       bt_free_definition_scope(_enum->p.scope);
+       bt_declaration_unref(_enum->p.declaration);
        if (_enum->value)
                g_array_unref(_enum->value);
        g_free(_enum);
This page took 0.029608 seconds and 4 git commands to generate.