Cleanup: bt namespace for compat glib
[babeltrace.git] / include / babeltrace / compat / glib.h
CommitLineData
bc26fd5e
MJ
1#ifndef _BABELTRACE_COMPAT_GLIB_H
2#define _BABELTRACE_COMPAT_GLIB_H
3
4/*
5 * babeltrace/compat/glib.h
6 *
7 * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28#include <glib.h>
29
30#if GLIB_CHECK_VERSION(2,31,8)
31
32static inline gboolean
5d5982ab 33bt_g_hash_table_contains(GHashTable *hash_table, gconstpointer key)
bc26fd5e
MJ
34{
35 return g_hash_table_contains(hash_table, key);
36}
37
38#else
39
40static inline gboolean
5d5982ab 41bt_g_hash_table_contains(GHashTable *hash_table, gconstpointer key)
bc26fd5e
MJ
42{
43 const char *value;
44
45 value = g_hash_table_lookup(hash_table, key);
46 if (value == NULL) {
47 return FALSE;
48 }
49
50 return TRUE;
51}
52
53#endif
54
55
56#if GLIB_CHECK_VERSION(2,29,16)
57
58static inline GPtrArray *
5d5982ab 59bt_g_ptr_array_new_full(guint reserved_size,
bc26fd5e
MJ
60 GDestroyNotify element_free_func)
61{
62 return g_ptr_array_new_full(reserved_size, element_free_func);
63}
64
65#else
66
67static inline GPtrArray *
5d5982ab 68bt_g_ptr_array_new_full(guint reserved_size,
bc26fd5e
MJ
69 GDestroyNotify element_free_func)
70{
71 GPtrArray *array;
72
73 array = g_ptr_array_sized_new(reserved_size);
74 if (!array) {
75 goto end;
76 }
77 g_ptr_array_set_free_func(array, element_free_func);
78end:
79 return array;
80}
81#endif
82
83#endif /* _BABELTRACE_COMPAT_GLIB_H */
This page took 0.026886 seconds and 4 git commands to generate.