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 int flag_count (const bitflag *flags, const size_t size);
67 bool flag_is_empty (const bitflag *flags, const size_t size);
68 bool flag_is_full (const bitflag *flags, const size_t size);
69 bool flag_is_inter (const bitflag *flags1, const bitflag *flags2,
70  const size_t size);
71 bool flag_is_subset (const bitflag *flags1, const bitflag *flags2,
72  const size_t size);
73 bool flag_is_equal (const bitflag *flags1, const bitflag *flags2,
74  const size_t size);
75 bool flag_on (bitflag *flags, const size_t size, const int flag);
76 bool flag_on_dbg (bitflag *flags, const size_t size, const int flag,
77  const char *fi, const char *fl);
78 bool flag_off (bitflag *flags, const size_t size, const int flag);
79 void flag_wipe (bitflag *flags, const size_t size);
80 void flag_setall (bitflag *flags, const size_t size);
81 void flag_negate (bitflag *flags, const size_t size);
82 void flag_copy (bitflag *flags1, const bitflag *flags2, const size_t size);
83 bool flag_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
bool flag_diff(bitflag *flags1, const bitflag *flags2, const size_t size)
Computes the difference of two bitfields.
Definition: z-bitflag.c:358
int flag_count(const bitflag *flags, const size_t size)
Counts the flags which are "on" in a bitflag set.
Definition: z-bitflag.c:92
void flag_negate(bitflag *flags, const size_t size)
Negates all flags in a bitfield.
Definition: z-bitflag.c:283
bool flag_on(bitflag *flags, const size_t size, const int flag)
Sets one bitflag in a bitfield.
Definition: z-bitflag.c:199
png_infop png_uint_32 flag
Definition: libpng12/png.h:2191
bool flag_off(bitflag *flags, const size_t size, const int flag)
Clears one flag in a bitfield.
Definition: z-bitflag.c:241
uint8_t byte
Definition: h-basic.h:167
bool flag_on_dbg(bitflag *flags, const size_t size, const int flag, const char *fi, const char *fl)
Definition: z-bitflag.c:213
void flag_setall(bitflag *flags, const size_t size)
Sets all flags in a bitfield.
Definition: z-bitflag.c:272
void flag_wipe(bitflag *flags, const size_t size)
Clears all flags in a bitfield.
Definition: z-bitflag.c:261
bool flag_has(const bitflag *flags, const size_t size, const int flag)
Tests if a flag is "on" in a bitflag set.
Definition: z-bitflag.c:28
bool flag_is_full(const bitflag *flags, const size_t size)
Tests a bitfield for fullness.
Definition: z-bitflag.c:132
Low-level text formatting (snprintf() replacement)
bool flag_inter(bitflag *flags1, const bitflag *flags2, const size_t size)
Computes the intersection of two bitfields.
Definition: z-bitflag.c:334
The lowest level header.
int flag_next(const bitflag *flags, const size_t size, const int flag)
Iterates over the flags which are "on" in a bitflag set.
Definition: z-bitflag.c:71
png_uint_32 int flags
Definition: libpng12/png.h:1681
byte bitflag
Definition: z-bitflag.h:27
void flag_copy(bitflag *flags1, const bitflag *flags2, const size_t size)
Copies one bitfield into another.
Definition: z-bitflag.c:298
bool flags_set(bitflag *flags, const size_t size,...)
Sets multiple bitflags in a bitfield.
Definition: z-bitflag.c:501
bool flags_clear(bitflag *flags, const size_t size,...)
Clears multiple bitflags in a bitfield.
Definition: z-bitflag.c:462
Memory management.
bool flag_is_inter(const bitflag *flags1, const bitflag *flags2, const size_t size)
Tests two bitfields for intersection.
Definition: z-bitflag.c:149
bool flags_mask(bitflag *flags, const size_t size,...)
Computes the intersection of a bitfield and multiple bitflags.
Definition: z-bitflag.c:565
bool flag_is_subset(const bitflag *flags1, const bitflag *flags2, const size_t size)
Test if one bitfield is a subset of another.
Definition: z-bitflag.c:167
bool flag_union(bitflag *flags1, const bitflag *flags2, const size_t size)
Computes the union of two bitfields.
Definition: z-bitflag.c:311
bool flag_has_dbg(const bitflag *flags, const size_t size, const int flag, const char *fi, const char *fl)
Definition: z-bitflag.c:42
bool flags_test(const bitflag *flags, const size_t size,...)
Tests if any of multiple bitflags are set in a bitfield.
Definition: z-bitflag.c:385
bool flag_is_equal(const bitflag *flags1, const bitflag *flags2, const size_t size)
Tests two bitfields for equality.
Definition: z-bitflag.c:185
bool flags_test_all(const bitflag *flags, const size_t size,...)
Tests if all of the multiple bitflags are set in a bitfield.
Definition: z-bitflag.c:423
png_uint_32 size
Definition: libpng12/png.h:1546
void flags_init(bitflag *flags, const size_t size,...)
Wipes a bitfield, and then sets multiple bitflags.
Definition: z-bitflag.c:539
bool flag_is_empty(const bitflag *flags, const size_t size)
Tests a bitfield for emptiness.
Definition: z-bitflag.c:115