Debian Codegraph @

src/dex-static-future.c

raw symbols SCIP
1 /* dex-static-future.c
2 *
3 * Copyright 2022 Christian Hergert <[email protected]>
4 *
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2.1 of the
8 * License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: LGPL-2.1-or-later
19 */
20
21 #include "config.h"
22
23 #include "dex-future-private.h"
24 #include "dex-static-future-private.h"
25
26 /**
27 * DexStaticFuture:
28 *
29 * `DexStaticFuture` represents a future that is resolved from the initial
30 * state.
31 *
32 * Use this when you need to create a future for API reasons but already have
33 * the value or rejection at that point.
34 *
35 * `DexStaticFuture` is used internally by functions like
36 * [[email protected]_for_boolean] and similar.
37 */
38
39 struct _DexStaticFuture
40 {
41 DexFuture parent_instance;
42 };
43
44 typedef struct _DexStaticFutureClass
45 {
46 DexFutureClass parent_class;
47 } DexStaticFutureClass;
48
49 DEX_DEFINE_FINAL_TYPE (DexStaticFuture, dex_static_future, DEX_TYPE_FUTURE)
50
51 #undef DEX_TYPE_STATIC_FUTURE
52 #define DEX_TYPE_STATIC_FUTURE dex_static_future_type
53
54 static void
55 dex_static_future_class_init (DexStaticFutureClass *static_future_class)
56 {
57 }
58
59 static void
60 dex_static_future_init (DexStaticFuture *static_future)
61 {
62 }
63
64 DexFuture *
65 dex_static_future_new_rejected (GError *error)
66 {
67 DexFuture *ret;
68
69 g_return_val_if_fail (error != NULL, NULL);
70
71 ret = (DexFuture *)dex_object_create_instance (DEX_TYPE_STATIC_FUTURE);
72 ret->rejected = error;
73 ret->status = DEX_FUTURE_STATUS_REJECTED;
74
75 return DEX_FUTURE (ret);
76 }
77
78 DexFuture *
79 dex_static_future_new_resolved (const GValue *value)
80 {
81 DexFuture *ret;
82
83 g_return_val_if_fail (G_IS_VALUE (value), NULL);
84
85 ret = (DexFuture *)dex_object_create_instance (DEX_TYPE_STATIC_FUTURE);
86 g_value_init (&ret->resolved, G_VALUE_TYPE (value));
87 g_value_copy (value, &ret->resolved);
88 ret->status = DEX_FUTURE_STATUS_RESOLVED;
89
90 return DEX_FUTURE (ret);
91 }
92
93 DexFuture *
94 dex_static_future_new_steal (GValue *value)
95 {
96 DexFuture *ret;
97
98 g_return_val_if_fail (G_IS_VALUE (value), NULL);
99
100 ret = (DexFuture *)dex_object_create_instance (DEX_TYPE_STATIC_FUTURE);
101 ret->status = DEX_FUTURE_STATUS_RESOLVED;
102
103 ret->resolved = *value;
104 memset (value, 0, sizeof *value);
105
106 return DEX_FUTURE (ret);
107 }