]> git.lizzy.rs Git - nothing.git/blob - src/system/lt.h
(#347) Implement slide down animation
[nothing.git] / src / system / lt.h
1 #ifndef LT_H_
2 #define LT_H_
3
4 #define PUSH_LT(lt, resource, resource_destroy) \
5     lt_push(lt, (void*)resource, (Lt_destroy)resource_destroy)
6
7 #define RESET_LT(lt, old_resource, new_resource)    \
8     lt_reset(lt, (void*)old_resource, (void*)new_resource)
9
10 #define REPLACE_LT(lt, old_resource, new_resource)  \
11     lt_replace(lt, (void*)old_resource, (void*)new_resource)
12
13 #define RELEASE_LT(lt, resource)                \
14     lt_release(lt, (void*) resource)
15
16 #define RETURN_LT(lt, result)               \
17     do {                                    \
18         destroy_lt(lt);                     \
19         return result;                      \
20     } while (0)
21
22 #define RETURN_LT0(lt)                          \
23     do {                                        \
24         destroy_lt(lt);                         \
25         return;                                 \
26     } while (0)
27
28 typedef struct Lt Lt;
29 typedef void (*Lt_destroy)(void*);
30
31 Lt *create_lt(void);
32 void destroy_lt(Lt *lt);
33
34 /** \brief Pushes the resource onto the Life Time creating a new Life Time frame.
35  */
36 void *lt_push(Lt *lt, void *resource, Lt_destroy resource_destroy);
37
38 /** \brief Destroys old_resource preserving its LT frame and assigns the new_resource to the LT frame.
39  */
40 void *lt_reset(Lt *lt, void *old_resource, void *new_resource);
41
42 /** \brief Replaces old_resource with new_resource in the LT frame without destroying old_resource.
43  */
44 void *lt_replace(Lt *lt, void *old_resource, void *new_resource);
45
46 /** \brief Removes the LT frame of resource without destroying the resource.
47  */
48 void *lt_release(Lt *lt, void *resource);
49
50 #endif  // LT_H_