Angband
Functions
z-bitflag.c File Reference

Low-level bit vector manipulation. More...

#include "z-bitflag.h"

Functions

bool flag_has (const bitflag *flags, const size_t size, const int flag)
 Tests if a flag is "on" in a bitflag set. More...
 
bool flag_has_dbg (const bitflag *flags, const size_t size, const int flag, const char *fi, const char *fl)
 
int flag_next (const bitflag *flags, const size_t size, const int flag)
 Iterates over the flags which are "on" in a bitflag set. More...
 
int flag_count (const bitflag *flags, const size_t size)
 Counts the flags which are "on" in a bitflag set. More...
 
bool flag_is_empty (const bitflag *flags, const size_t size)
 Tests a bitfield for emptiness. More...
 
bool flag_is_full (const bitflag *flags, const size_t size)
 Tests a bitfield for fullness. More...
 
bool flag_is_inter (const bitflag *flags1, const bitflag *flags2, const size_t size)
 Tests two bitfields for intersection. More...
 
bool flag_is_subset (const bitflag *flags1, const bitflag *flags2, const size_t size)
 Test if one bitfield is a subset of another. More...
 
bool flag_is_equal (const bitflag *flags1, const bitflag *flags2, const size_t size)
 Tests two bitfields for equality. More...
 
bool flag_on (bitflag *flags, const size_t size, const int flag)
 Sets one bitflag in a bitfield. More...
 
bool flag_on_dbg (bitflag *flags, const size_t size, const int flag, const char *fi, const char *fl)
 
bool flag_off (bitflag *flags, const size_t size, const int flag)
 Clears one flag in a bitfield. More...
 
void flag_wipe (bitflag *flags, const size_t size)
 Clears all flags in a bitfield. More...
 
void flag_setall (bitflag *flags, const size_t size)
 Sets all flags in a bitfield. More...
 
void flag_negate (bitflag *flags, const size_t size)
 Negates all flags in a bitfield. More...
 
void flag_copy (bitflag *flags1, const bitflag *flags2, const size_t size)
 Copies one bitfield into another. More...
 
bool flag_union (bitflag *flags1, const bitflag *flags2, const size_t size)
 Computes the union of two bitfields. More...
 
bool flag_inter (bitflag *flags1, const bitflag *flags2, const size_t size)
 Computes the intersection of two bitfields. More...
 
bool flag_diff (bitflag *flags1, const bitflag *flags2, const size_t size)
 Computes the difference of two bitfields. More...
 
bool flags_test (const bitflag *flags, const size_t size,...)
 Tests if any of multiple bitflags are set in a bitfield. More...
 
bool flags_test_all (const bitflag *flags, const size_t size,...)
 Tests if all of the multiple bitflags are set in a bitfield. More...
 
bool flags_clear (bitflag *flags, const size_t size,...)
 Clears multiple bitflags in a bitfield. More...
 
bool flags_set (bitflag *flags, const size_t size,...)
 Sets multiple bitflags in a bitfield. More...
 
void flags_init (bitflag *flags, const size_t size,...)
 Wipes a bitfield, and then sets multiple bitflags. More...
 
bool flags_mask (bitflag *flags, const size_t size,...)
 Computes the intersection of a bitfield and multiple bitflags. More...
 

Detailed Description

Low-level bit vector manipulation.

Copyright (c) 2010 William L Moore

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Function Documentation

◆ flag_copy()

void flag_copy ( bitflag flags1,
const bitflag flags2,
const size_t  size 
)

Copies one bitfield into another.

All flags in flags2 are copied into flags1. The size of the bitfields is supplied in size.

◆ flag_count()

int flag_count ( const bitflag flags,
const size_t  size 
)

Counts the flags which are "on" in a bitflag set.

The bitfield size is supplied in size.

References FLAG_BINARY, FLAG_WIDTH, i, and size.

◆ flag_diff()

bool flag_diff ( bitflag flags1,
const bitflag flags2,
const size_t  size 
)

Computes the difference of two bitfields.

For every set flag in flags2, the corresponding flag is cleared in flags1. The size of the bitfields is supplied in size. true is returned when changes were made, and false otherwise.

References i, and size.

◆ flag_has()

bool flag_has ( const bitflag flags,
const size_t  size,
const int  flag 
)

Tests if a flag is "on" in a bitflag set.

true is returned when flag is on in flags, and false otherwise. The flagset size is supplied in size.

References FLAG_BINARY, FLAG_END, and FLAG_OFFSET.

◆ flag_has_dbg()

bool flag_has_dbg ( const bitflag flags,
const size_t  size,
const int  flag,
const char *  fi,
const char *  fl 
)

◆ flag_inter()

bool flag_inter ( bitflag flags1,
const bitflag flags2,
const size_t  size 
)

Computes the intersection of two bitfields.

For every unset flag in flags2, the corresponding flag is cleared in flags1. The size of the bitfields is supplied in size. true is returned when changes were made, and false otherwise.

References i, and size.

Referenced by flags_mask().

◆ flag_is_empty()

bool flag_is_empty ( const bitflag flags,
const size_t  size 
)

Tests a bitfield for emptiness.

true is returned when no flags are set in flags, and false otherwise. The bitfield size is supplied in size.

References i, and size.

◆ flag_is_equal()

bool flag_is_equal ( const bitflag flags1,
const bitflag flags2,
const size_t  size 
)

Tests two bitfields for equality.

true is returned when the flags set in flags1 and flags2 are identical, and false otherwise. the size of the bitfields is supplied in size.

◆ flag_is_full()

bool flag_is_full ( const bitflag flags,
const size_t  size 
)

Tests a bitfield for fullness.

true is returned when all flags are set in flags, and false otherwise. The bitfield size is supplied in size.

References i, and size.

◆ flag_is_inter()

bool flag_is_inter ( const bitflag flags1,
const bitflag flags2,
const size_t  size 
)

Tests two bitfields for intersection.

true is returned when any flag is set in both flags1 and flags2, and false otherwise. The size of the bitfields is supplied in size.

References i, and size.

◆ flag_is_subset()

bool flag_is_subset ( const bitflag flags1,
const bitflag flags2,
const size_t  size 
)

Test if one bitfield is a subset of another.

true is returned when every set flag in flags2 is also set in flags1, and false otherwise. The size of the bitfields is supplied in size.

References i, and size.

◆ flag_negate()

void flag_negate ( bitflag flags,
const size_t  size 
)

Negates all flags in a bitfield.

All flags in flags are toggled. The bitfield size is supplied in size.

References i, and size.

◆ flag_next()

int flag_next ( const bitflag flags,
const size_t  size,
const int  flag 
)

Iterates over the flags which are "on" in a bitflag set.

Returns the next on flag in flags, starting from (and including) flag. FLAG_END will be returned when the end of the flag set is reached. Iteration will start at the beginning of the flag set when flag is FLAG_END. The bitfield size is supplied in size.

References FLAG_BINARY, FLAG_END, FLAG_MAX, and FLAG_OFFSET.

Referenced by write_flags().

◆ flag_off()

bool flag_off ( bitflag flags,
const size_t  size,
const int  flag 
)

Clears one flag in a bitfield.

The bitflag identified by flag is cleared in flags. The bitfield size is supplied in size. true is returned when changes were made, false otherwise.

References FLAG_BINARY, and FLAG_OFFSET.

Referenced by remove_flag().

◆ flag_on()

bool flag_on ( bitflag flags,
const size_t  size,
const int  flag 
)

Sets one bitflag in a bitfield.

The bitflag identified by flag is set in flags. The bitfield size is supplied in size. true is returned when changes were made, false otherwise.

References FLAG_BINARY, and FLAG_OFFSET.

Referenced by flags_init(), flags_mask(), and grab_flag().

◆ flag_on_dbg()

bool flag_on_dbg ( bitflag flags,
const size_t  size,
const int  flag,
const char *  fi,
const char *  fl 
)

References FLAG_BINARY, FLAG_OFFSET, and quit_fmt().

◆ flag_setall()

void flag_setall ( bitflag flags,
const size_t  size 
)

Sets all flags in a bitfield.

All flags in flags are set. The bitfield size is supplied in size.

◆ flag_union()

bool flag_union ( bitflag flags1,
const bitflag flags2,
const size_t  size 
)

Computes the union of two bitfields.

For every set flag in flags2, the corresponding flag is set in flags1. The size of the bitfields is supplied in size. true is returned when changes were made, and false otherwise.

References i, and size.

◆ flag_wipe()

void flag_wipe ( bitflag flags,
const size_t  size 
)

Clears all flags in a bitfield.

All flags in flags are cleared. The bitfield size is supplied in size.

Referenced by flags_init().

◆ flags_clear()

bool flags_clear ( bitflag flags,
const size_t  size,
  ... 
)

Clears multiple bitflags in a bitfield.

The flags specified in ... are cleared in flags. The bitfield size is supplied in size. true is returned when changes were made, false otherwise.

WARNING: FLAG_END must be the final argument in the ... list.

References args, FLAG_BINARY, FLAG_END, and FLAG_OFFSET.

◆ flags_init()

void flags_init ( bitflag flags,
const size_t  size,
  ... 
)

Wipes a bitfield, and then sets multiple bitflags.

The flags specified in ... are set in flags, while all other flags are cleared. The bitfield size is supplied in size.

WARNING: FLAG_END must be the final argument in the ... list.

References args, FLAG_END, flag_on(), and flag_wipe().

◆ flags_mask()

bool flags_mask ( bitflag flags,
const size_t  size,
  ... 
)

Computes the intersection of a bitfield and multiple bitflags.

The flags not specified in ... are cleared in flags. The bitfeild size is supplied in size. true is returned when changes were made, false otherwise.

WARNING: FLAG_END must be the final argument in the ... list.

References args, FLAG_END, flag_inter(), flag_on(), mask, mem_free(), and mem_zalloc().

◆ flags_set()

bool flags_set ( bitflag flags,
const size_t  size,
  ... 
)

Sets multiple bitflags in a bitfield.

The flags specified in ... are set in flags. The bitfield size is supplied in size. true is returned when changes were made, false otherwise.

WARNING: FLAG_END must be the final argument in the ... list.

References args, FLAG_BINARY, FLAG_END, and FLAG_OFFSET.

Referenced by update_mon().

◆ flags_test()

bool flags_test ( const bitflag flags,
const size_t  size,
  ... 
)

Tests if any of multiple bitflags are set in a bitfield.

true is returned if any of the flags specified in ... are set in flags, false otherwise. The bitfield size is supplied in size.

WARNING: FLAG_END must be the final argument in the ... list.

References args, FLAG_BINARY, FLAG_END, and FLAG_OFFSET.

Referenced by count_abilities(), effect_handler_EARTHQUAKE(), get_move(), get_move_find_range(), grid_data_as_text(), lore_append_movement(), monster_is_nonliving(), and monster_passes_walls().

◆ flags_test_all()

bool flags_test_all ( const bitflag flags,
const size_t  size,
  ... 
)

Tests if all of the multiple bitflags are set in a bitfield.

true is returned if all of the flags specified in ... are set in flags, false otherwise. The bitfield size is supplied in size.

WARNING: FLAG_END must be the final argument in the ... list.

References args, FLAG_BINARY, FLAG_END, and FLAG_OFFSET.

Referenced by add_sustain().