man rflag (Fonctions bibliothèques) - bit flag routines
NAME
rflag - bit flag routines
SYNOPSIS
#include <roy.h>
RFLAG_FLAGS (struct);
RFLAG_SET (struct, flag);
RFLAG_UNSET (struct, flag);
RFLAG_ISSET (struct, flag);
RFLAG_ONLYSET (struct, flag);
DESCRIPTION
These are a set of macros for setting, clearing and checking bit flags as found in a number of structures. In order for this to work, the structure must have a 'flags' member, for which you create an enumerated list of bit flags.
RFLAG_FLAGS(3) returns the struct->flags member.
RFLAG_SET(3) sets the value of flag in the flags member in struct. This is done using the bitwise & operator.
RFLAG_UNSET(3) clears the value of flag in the flags member in struct.
RFLAG_ISSET(3) returns the TRUE if the flag flag is set, or FALSE if unset.
RFLAG_ONLYSET(3) returns TRUE if flag is the only bit turned on in the flags member of struct.
MACROS
These calls are all implemented with macros.
EXAMPLE
/* Create an enumerated list of flags. */
typedef enum { FOO_NEEDS_BAR = 1 << 0, FOO_NEEDS_BAZ = 1 << 1, FOO_NEEDS_BAX = 1 << 2 } MyFlags;
/* Create a structure with a flags member. */
typedef struct { /* ... */ unsigned int flags; /* ... */ } MyStruct;
/* Example setting/checking. */
void foo (void) { MyStruct *mys;
/* ... */
RFLAG_SET (mys, FOO_NEEDS_BAR);
if (RFLAG_ISSET (mys, FOO_NEEDS_BAZ)) { /* do something.. */ }
RFLAG_UNSET (mys, FOO_NEEDS_BAR); }