global items used:
member variables:
INT8
*bitmask_: An array of INT8. A bit with bitnumber n can be
found in array element n div 8, bit position n mod 8.
INT32
size_: The size of the array. At most size*8 bits can be
stored.
member functions:
CBitMask
(INT32 aSize = ArrayAllocationSize): Allocates a bitmask that can
store aSize bits. If aSize is not positive, an assert
fails.
CBitMask
(void *mask, INT32 size): Allocates a bitmask that can store size
bytes of mask, and copies the first size bytes of mask
into it. If size is not positive or if mask is NULL,
an assert fails.
CBitMask
(const CBitMask& bitmask): Copies the information stored in bitmask.
The internal bitmask will have the same size as that in bitmask.
~CBitMask
(): Frees the memory occupied by the bitmask.
void
Allocate (INT32 size): The function assumes that the array has been
deleted, allocates a new one with size size and fills the array
with 0.
Note: size is not checked, so take care not to call the
function with a size of zero.
int
GetBit (INT32 place) const: Returns 0 if the bit with bitnumber place
is not set, otherwise a value != 0.
INT32
GetIndex (INT32 place) const: The bitmask is internally realized as
an array of INT8. So this function returns the array index of the INT8,
where the bit with bitnumber place is located.
INT32
GetOffset (INT32 place) const: Returns the bitnumber in the particular
INT8 in which the bit with bitnumber place is located.
int
operator& (const INT32 place) const: Returns 0 if the bit with
the number place is False, a value != 0 if the bit is True.
CBitMask&
operator|= (const INT32 place): Sets the bit with the bitnumber place
to True, returns the bitmask.
CBitMask&
operator^= (const INT32 place): Toggles the value of the bit with
the bitnumber place, returns the bitmask.
void
ReAllocate (INT32 size): Deletes the old bitmask array, allocates
a new with size size. Stores the new size in member size_
and fills the array with 0.
Note: again, size is not checked,
so take care not to call the function with a size of zero.
void
Reset (INT32 aSize = ArrayAllocationSize): Sets all bits to zero and
sets the size of the bitmask so that aSize bits can be stored.
If aSize is not positive, an assert fails.
void
Set (const void *mask, INT32 size): Discards the old bitmask, allocates
enough memory to store size bytes of mask, and copies
these bytes from mask into the own bitmask. If size is
not positive or if mask is NULL, an assert fails.
void
SetBit (INT32 place): Sets the bit with bitnumber place to
True. That is done by setting the appropriate bit in the array to 1.