Freeciv21
Develop your civilization from humble roots to a global empire
bitvector.h File Reference
#include <cstring>
#include "log.h"
+ Include dependency graph for bitvector.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TEST_BIT(val, bit_no)    (((val) & (1u << (bit_no))) == (1u << (bit_no)))
 
#define _BV_BYTES(bits)   ((((bits) -1) / 8) + 1)
 
#define _BV_BYTE_INDEX(bits)   ((bits) / 8)
 
#define _BV_BITMASK(bit)   (1u << ((bit) &0x7))
 
#define _BV_ASSERT(bv, bit)   (void) 0
 
#define BV_SET(bv, bit)
 
#define BV_CLR(bv, bit)
 
#define BV_SET_VAL(bv, bit, val)
 
#define BV_CLR_ALL(bv)
 
#define BV_SET_ALL(bv)
 
#define BV_CHECK_MASK(vec1, vec2)
 
#define BV_ISSET_ANY(vec)   BV_CHECK_MASK(vec, vec)
 
#define BV_ARE_EQUAL(vec1, vec2)
 
#define BV_SET_ALL_FROM(vec_to, vec_from)
 
#define BV_CLR_ALL_FROM(vec_to, vec_from)
 
#define BV_DEFINE(name, bits)
 

Functions

template<class BV >
bool BV_ISSET (const BV &bv, int bit)
 
bool bv_check_mask (const unsigned char *vec1, const unsigned char *vec2, size_t size1, size_t size2)
 Return whether two vectors: vec1 and vec2 have common bits. More...
 
bool bv_are_equal (const unsigned char *vec1, const unsigned char *vec2, size_t size1, size_t size2)
 Compares elements of two bitvectors. More...
 
void bv_set_all_from (unsigned char *vec_to, const unsigned char *vec_from, size_t size_to, size_t size_from)
 Set everything that is true in vec_from in vec_to. More...
 
void bv_clr_all_from (unsigned char *vec_to, const unsigned char *vec_from, size_t size_to, size_t size_from)
 Clear everything that is true in vec_from in vec_to. More...
 
bool is_any_set (QBitArray &ba)
 

Macro Definition Documentation

◆ _BV_ASSERT

#define _BV_ASSERT (   bv,
  bit 
)    (void) 0

Definition at line 34 of file bitvector.h.

◆ _BV_BITMASK

#define _BV_BITMASK (   bit)    (1u << ((bit) &0x7))

Definition at line 29 of file bitvector.h.

◆ _BV_BYTE_INDEX

#define _BV_BYTE_INDEX (   bits)    ((bits) / 8)

Definition at line 28 of file bitvector.h.

◆ _BV_BYTES

#define _BV_BYTES (   bits)    ((((bits) -1) / 8) + 1)

Definition at line 27 of file bitvector.h.

◆ BV_ARE_EQUAL

#define BV_ARE_EQUAL (   vec1,
  vec2 
)
Value:
bv_are_equal((vec1).vec, (vec2).vec, sizeof((vec1).vec), \
sizeof((vec2).vec))
bool bv_are_equal(const unsigned char *vec1, const unsigned char *vec2, size_t size1, size_t size2)
Compares elements of two bitvectors.
Definition: bitvector.cpp:51

Definition at line 80 of file bitvector.h.

◆ BV_CHECK_MASK

#define BV_CHECK_MASK (   vec1,
  vec2 
)
Value:
bv_check_mask((vec1).vec, (vec2).vec, sizeof((vec1).vec), \
sizeof((vec2).vec))
bool bv_check_mask(const unsigned char *vec1, const unsigned char *vec2, size_t size1, size_t size2)
Return whether two vectors: vec1 and vec2 have common bits.
Definition: bitvector.cpp:31

Definition at line 73 of file bitvector.h.

◆ BV_CLR

#define BV_CLR (   bv,
  bit 
)
Value:
do { \
_BV_ASSERT(bv, bit); \
(bv).vec[_BV_BYTE_INDEX(bit)] &= ~_BV_BITMASK(bit); \
} while (false)
#define _BV_BYTE_INDEX(bits)
Definition: bitvector.h:28
#define _BV_BITMASK(bit)
Definition: bitvector.h:29

Definition at line 49 of file bitvector.h.

◆ BV_CLR_ALL

#define BV_CLR_ALL (   bv)
Value:
do { \
memset((bv).vec, 0, sizeof((bv).vec)); \
} while (false)

Definition at line 62 of file bitvector.h.

◆ BV_CLR_ALL_FROM

#define BV_CLR_ALL_FROM (   vec_to,
  vec_from 
)
Value:
bv_clr_all_from((vec_to).vec, (vec_from).vec, sizeof((vec_to).vec), \
sizeof((vec_from).vec))
void bv_clr_all_from(unsigned char *vec_to, const unsigned char *vec_from, size_t size_to, size_t size_from)
Clear everything that is true in vec_from in vec_to.
Definition: bitvector.cpp:99

Definition at line 92 of file bitvector.h.

◆ BV_DEFINE

#define BV_DEFINE (   name,
  bits 
)
Value:
typedef struct { \
unsigned char vec[_BV_BYTES(bits)]; \
} name
#define _BV_BYTES(bits)
Definition: bitvector.h:27
const char * name
Definition: inputfile.cpp:118

Definition at line 97 of file bitvector.h.

◆ BV_ISSET_ANY

#define BV_ISSET_ANY (   vec)    BV_CHECK_MASK(vec, vec)

Definition at line 76 of file bitvector.h.

◆ BV_SET

#define BV_SET (   bv,
  bit 
)
Value:
do { \
_BV_ASSERT(bv, bit); \
(bv).vec[_BV_BYTE_INDEX(bit)] |= _BV_BITMASK(bit); \
} while (false)

Definition at line 44 of file bitvector.h.

◆ BV_SET_ALL

#define BV_SET_ALL (   bv)
Value:
do { \
memset((bv).vec, 0xff, sizeof((bv).vec)); \
} while (false)

Definition at line 66 of file bitvector.h.

◆ BV_SET_ALL_FROM

#define BV_SET_ALL_FROM (   vec_to,
  vec_from 
)
Value:
bv_set_all_from((vec_to).vec, (vec_from).vec, sizeof((vec_to).vec), \
sizeof((vec_from).vec))
void bv_set_all_from(unsigned char *vec_to, const unsigned char *vec_from, size_t size_to, size_t size_from)
Set everything that is true in vec_from in vec_to.
Definition: bitvector.cpp:77

Definition at line 86 of file bitvector.h.

◆ BV_SET_VAL

#define BV_SET_VAL (   bv,
  bit,
  val 
)
Value:
do { \
if (val) { \
BV_SET(bv, bit); \
} else { \
BV_CLR(bv, bit); \
} \
} while (false);

Definition at line 54 of file bitvector.h.

◆ TEST_BIT

#define TEST_BIT (   val,
  bit_no 
)     (((val) & (1u << (bit_no))) == (1u << (bit_no)))

Definition at line 23 of file bitvector.h.

Function Documentation

◆ bv_are_equal()

bool bv_are_equal ( const unsigned char *  vec1,
const unsigned char *  vec2,
size_t  size1,
size_t  size2 
)

Compares elements of two bitvectors.

Both vectors are expected to have same number of elements, i.e. , size1 must be equal to size2.

Definition at line 51 of file bitvector.cpp.

◆ bv_check_mask()

bool bv_check_mask ( const unsigned char *  vec1,
const unsigned char *  vec2,
size_t  size1,
size_t  size2 
)

Return whether two vectors: vec1 and vec2 have common bits.

I.e. (vec1 & vec2) != 0.

Don't call this function directly, use BV_CHECK_MASK macro instead. Don't call this function with two different bitvectors.

Definition at line 31 of file bitvector.cpp.

◆ bv_clr_all_from()

void bv_clr_all_from ( unsigned char *  vec_to,
const unsigned char *  vec_from,
size_t  size_to,
size_t  size_from 
)

Clear everything that is true in vec_from in vec_to.

Stuff that already is false in vec_to aren't touched.

Both vectors are expected to have same number of elements, i.e. , size1 must be equal to size2.

Don't call this function directly, use BV_CLR_ALL_FROM macro instead.

Definition at line 99 of file bitvector.cpp.

◆ BV_ISSET()

template<class BV >
bool BV_ISSET ( const BV &  bv,
int  bit 
)
inline

Definition at line 37 of file bitvector.h.

Referenced by achievement_check(), achievement_player_has(), action_would_be_blocked_by(), advance_has_flag(), advance_req_iter_next(), advance_root_req_iter_next(), amphibious_move_scope(), are_requirements_contradictions(), autoadjust_ruleset_data(), base_has_flag(), build_free_small_wonders(), build_landarea_map(), bvplayers_count(), bvplayers_str(), can_extras_coexist(), can_unit_type_transport(), can_utype_do_act_if_tgt_diplrel(), city_production_caravan_shields_init(), city_production_gets_caravan_shields(), col_gold(), col_government(), col_luxury(), col_research(), col_science(), col_tax(), dai_hunter_manage(), plr_item::data(), debug_command(), dem_line_item(), destroy_extra(), diplrel_req_contradicts(), disaster_has_effect(), do_capture_units(), do_spaceship_place(), event_cache_match(), event_cache_save(), extra_has_flag(), fair_map_island_new(), freeciv::layer_water::fill_irrigation_sprite_array(), freeciv::layer_special::fill_sprite_array(), freeciv::layer_water::fill_sprite_array(), get_culture_info(), get_infrastructure_text(), get_preferred_pillage(), give_shared_vision(), gives_shared_vision(), goods_has_flag(), handle_city_info(), handle_city_sabotage_list(), handle_city_short_info(), handle_edit_city(), handle_edit_tile(), handle_player_info(), handle_ruleset_extra(), handle_rulesets_ready(), helptext_advance(), helptext_unit(), identity_number_is_used(), img_createmap(), img_plot(), img_save(), improvement_has_flag(), is_airunit_refuel_point(), is_city_option_set(), is_extra_needed(), is_native_extra_to_uclass(), is_native_to_class(), is_unit_reachable_by_unit(), load_ruleset_terrain(), map_claim_base(), mapimg_define(), mapimg_define_arg(), mapimg_generate_name(), plr_widget::nation_selected(), next_spaceship_component(), num_spaceship_structurals_placed(), package_player_info(), pf_attack_possible(), pick_random_tech_to_lose(), player_has_flag(), player_has_real_embassy(), player_status_check(), really_gives_vision(), remove_shared_vision(), research_get_reachable_rreqs(), research_goal_tech_req(), research_invention_set(), road_has_flag(), road_integrators_cache_init(), rs_barbarian_units(), rs_common_units(), sanity_check_ruleset_data(), save_game_ruleset(), save_terrain_ruleset(), save_uclass_vec(), set_unit_class_caches(), sg_extras_get(), sg_load_player_vision(), sg_save_player_cities(), sg_save_player_main(), sg_save_player_vision(), spaceship_calc_derived(), spy_send_sabotage_list(), startpos_unpack(), startunits_callback(), tile_has_conflicting_extra(), tile_has_visible_extra(), tile_resource_is_valid(), tile_virtual_new(), transfer_city(), transform_unit(), uclass_has_flag(), unit_move(), unit_transport_load_send(), utype_can_do_act_if_tgt_citytile(), utype_can_do_act_when_ustate(), utype_can_do_action(), utype_can_freely_load(), utype_can_freely_unload(), utype_has_flag(), utype_has_role(), and utype_upkeep_cost().

◆ bv_set_all_from()

void bv_set_all_from ( unsigned char *  vec_to,
const unsigned char *  vec_from,
size_t  size_to,
size_t  size_from 
)

Set everything that is true in vec_from in vec_to.

Stuff that already is true in vec_to aren't touched. (Bitwise inclusive OR assignment)

Both vectors are expected to have same number of elements, i.e. , size1 must be equal to size2.

Don't call this function directly, use BV_SET_ALL_FROM macro instead.

Definition at line 77 of file bitvector.cpp.

◆ is_any_set()

bool is_any_set ( QBitArray &  ba)

Definition at line 112 of file bitvector.cpp.

Referenced by helptext_unit().