Debian Codegraph @

src/dex-object.h

raw symbols SCIP
1 /*
2 * dex-object.h
3 *
4 * Copyright 2022 Christian Hergert <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library; if not, see <http://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: LGPL-2.1-or-later
20 */
21
22 #pragma once
23
24 #include <glib-object.h>
25
26 #include "dex-version-macros.h"
27
28 G_BEGIN_DECLS
29
30 #define DEX_TYPE_OBJECT (dex_object_get_type())
31 #define DEX_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, DEX_TYPE_OBJECT, DexObject))
32 #define DEX_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE(obj, DEX_TYPE_OBJECT))
33 #define DEX_OBJECT_TYPE(obj) (G_TYPE_FROM_INSTANCE(obj))
34 #define DEX_OBJECT_TYPE_NAME(obj) (g_type_name(DEX_OBJECT_TYPE(obj)))
35
36 typedef struct _DexObject DexObject;
37
38 DEX_AVAILABLE_IN_ALL
39 GType dex_object_get_type (void);
40 DEX_AVAILABLE_IN_ALL
41 GParamSpec *dex_param_spec_object (const char *name,
42 const char *nick,
43 const char *blurb,
44 GType object_type,
45 GParamFlags flags);
46 DEX_AVAILABLE_IN_ALL
47 gpointer dex_ref (gpointer object);
48 DEX_AVAILABLE_IN_ALL
49 void dex_unref (gpointer object);
50
51 #ifndef __GI_SCANNER__
52 static inline void
53 dex_clear (gpointer data)
54 {
55 DexObject **objptr = (DexObject **)data;
56 DexObject *obj = *objptr;
57 *objptr = NULL;
58 if (obj != NULL)
59 dex_unref (obj);
60 }
61
62 static inline gboolean
63 dex_set_object (DexObject **object_ptr,
64 DexObject *new_object)
65 {
66 DexObject *old_object = *object_ptr;
67
68 if (old_object == new_object)
69 return FALSE;
70
71 if (new_object != NULL)
72 dex_ref (new_object);
73
74 *object_ptr = new_object;
75
76 if (old_object != NULL)
77 dex_unref (old_object);
78
79 return TRUE;
80 }
81
82 #if defined(__GNUC__)
83 # define dex_set_object(object_ptr, new_object) \
84 (G_GNUC_EXTENSION ({ \
85 G_STATIC_ASSERT (sizeof *(object_ptr) == sizeof (new_object)); \
86 union { char *in; DexObject **out; } _object_ptr; \
87 _object_ptr.in = (char *) (object_ptr); \
88 (void) (0 ? *(object_ptr) = (new_object), FALSE : FALSE); \
89 (dex_set_object) (_object_ptr.out, (DexObject *) new_object); \
90 }))
91 #else
92 # define dex_set_object(object_ptr, new_object) \
93 (0 ? *(object_ptr) = (new_object), FALSE : \
94 (dex_set_object) ((DexObject **) (object_ptr), (DexObject *) (new_object)))
95 #endif
96 #endif
97
98 DEX_AVAILABLE_IN_ALL
99 DexObject *dex_value_dup_object (const GValue *value);
100 DEX_AVAILABLE_IN_ALL
101 DexObject *dex_value_get_object (const GValue *value);
102 DEX_AVAILABLE_IN_ALL
103 void dex_value_set_object (GValue *value,
104 DexObject *object);
105 DEX_AVAILABLE_IN_ALL
106 void dex_value_take_object (GValue *value,
107 DexObject *object);
108
109 G_DEFINE_AUTOPTR_CLEANUP_FUNC (DexObject, dex_unref)
110
111 G_END_DECLS