-
Notifications
You must be signed in to change notification settings - Fork 0
/
rjd_resource_types.h
101 lines (81 loc) · 2.79 KB
/
rjd_resource_types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once
#define RJD_RESOURCE_TYPES_H 1
struct rjd_resource_id
{
struct rjd_strhash hash;
};
struct rjd_resource_type_id
{
struct rjd_strhash hash;
};
struct rjd_resource_handle
{
struct rjd_slot slot;
};
static inline struct rjd_resource_id rjd_resource_id_from_str(const char* str);
static inline struct rjd_resource_id rjd_resource_id_none(void);
static inline bool rjd_resource_id_equals(struct rjd_resource_id a, struct rjd_resource_id b);
static inline bool rjd_resource_id_isvalid(struct rjd_resource_id id);
static inline struct rjd_resource_type_id rjd_resource_type_id_from_str(const char* str);
static inline struct rjd_resource_type_id rjd_resource_type_id_none(void);
static inline bool rjd_resource_type_id_equals(struct rjd_resource_type_id a, struct rjd_resource_type_id b);
static inline bool rjd_resource_type_id_isvalid(struct rjd_resource_type_id id);
static inline struct rjd_resource_handle rjd_resource_handle_none(void);
static inline bool rjd_resource_handle_equals(struct rjd_resource_handle a, struct rjd_resource_handle b);
static inline bool rjd_resource_handle_isvalid(struct rjd_resource_handle handle);
////////////////////////////////////////////////////////////////////////////////
// static inline implementation
static inline struct rjd_resource_id rjd_resource_id_from_str(const char* str)
{
struct rjd_resource_id id = {
.hash = rjd_strhash_init(str),
};
return id;
}
static inline struct rjd_resource_id rjd_resource_id_none(void)
{
return rjd_resource_id_from_str(NULL);
}
static inline bool rjd_resource_id_equals(struct rjd_resource_id a, struct rjd_resource_id b)
{
return a.hash.hash.value == b.hash.hash.value;
}
static inline bool rjd_resource_id_isvalid(struct rjd_resource_id id)
{
return id.hash.hash.value != 0;
}
static inline struct rjd_resource_type_id rjd_resource_type_id_from_str(const char* str)
{
struct rjd_resource_type_id id = {
.hash = rjd_strhash_init(str),
};
return id;
}
static inline struct rjd_resource_type_id rjd_resource_type_id_none(void)
{
return rjd_resource_type_id_from_str(NULL);
}
static inline bool rjd_resource_type_id_equals(struct rjd_resource_type_id a, struct rjd_resource_type_id b)
{
return a.hash.hash.value == b.hash.hash.value;
}
static inline bool rjd_resource_type_id_isvalid(struct rjd_resource_type_id id)
{
return id.hash.hash.value != 0;
}
static inline struct rjd_resource_handle rjd_resource_handle_none(void)
{
struct rjd_resource_handle handle;
handle.slot.index = 0;
handle.slot.salt = 0;
return handle;
}
static inline bool rjd_resource_handle_equals(struct rjd_resource_handle a, struct rjd_resource_handle b)
{
return a.slot.index == b.slot.index &&
a.slot.salt == b.slot.salt;
}
static inline bool rjd_resource_handle_isvalid(struct rjd_resource_handle handle)
{
return rjd_slot_isvalid(handle.slot);
}