Angband
z-bitflag.h
Go to the documentation of this file.
1 
19 #ifndef INCLUDED_Z_BITFLAG_H
20 #define INCLUDED_Z_BITFLAG_H
21 
22 #include "h-basic.h"
23 #include "z-form.h"
24 #include "z-virt.h"
25 
26 /* The basic datatype of bitflags */
27 typedef byte bitflag;
28 #define FLAG_WIDTH (sizeof(bitflag)*8)
29 
34 #define FLAG_START 1
35 
39 #define FLAG_END (FLAG_START - 1)
40 
44 #define FLAG_SIZE(n) (((n) + FLAG_WIDTH - 1) / FLAG_WIDTH)
45 
49 #define FLAG_MAX(n) (int)((n) * FLAG_WIDTH + FLAG_START)
50 
54 #define FLAG_OFFSET(id) (((id) - FLAG_START) / FLAG_WIDTH)
55 
59 #define FLAG_BINARY(id) (1 << ((id) - FLAG_START) % FLAG_WIDTH)
60 
61 
62 bool flag_has (const bitflag *flags, const size_t size, const int flag);
63 bool flag_has_dbg (const bitflag *flags, const size_t size, const int flag,
64  const char *fi, const char *fl);
65 int flag_next (const bitflag *flags, const size_t size, const int flag);
66 bool flag_is_empty (const bitflag *flags, const size_t size);
67 bool flag_is_full (const bitflag *flags, const size_t size);
68 bool flag_is_inter (const bitflag *flags1, const bitflag *flags2,
69  const size_t size);
70 bool flag_is_subset (const bitflag *flags1, const bitflag *flags2,
71  const size_t size);
72 bool flag_is_equal (const bitflag *flags1, const bitflag *flags2,
73  const size_t size);
74 bool flag_on (bitflag *flags, const size_t size, const int flag);
75 bool flag_on_dbg (bitflag *flags, const size_t size, const int flag,
76  const char *fi, const char *fl);
77 bool flag_off (bitflag *flags, const size_t size, const int flag);
78 void flag_wipe (bitflag *flags, const size_t size);
79 void flag_setall (bitflag *flags, const size_t size);
80 void flag_negate (bitflag *flags, const size_t size);
81 void flag_copy (bitflag *flags1, const bitflag *flags2, const size_t size);
82 bool flag_union (bitflag *flags1, const bitflag *flags2, const size_t size);
83 bool flag_comp_union(bitflag *flags1, const bitflag *flags2, const size_t size);
84 bool flag_inter (bitflag *flags1, const bitflag *flags2, const size_t size);
85 bool flag_diff (bitflag *flags1, const bitflag *flags2, const size_t size);
86 
87 bool flags_test (const bitflag *flags, const size_t size, ...);
88 bool flags_test_all (const bitflag *flags, const size_t size, ...);
89 bool flags_clear (bitflag *flags, const size_t size, ...);
90 bool flags_set (bitflag *flags, const size_t size, ...);
91 void flags_init (bitflag *flags, const size_t size, ...);
92 bool flags_mask (bitflag *flags, const size_t size, ...);
93 
94 #endif