rcolyer.net
RC Lib  Version 202403231100
Public Member Functions | Friends | List of all members
RC::Bitfield2D Class Reference

A bounds-safe two-dimensional structure of efficiently packed bits. More...

#include <Bitfield2D.h>

Public Member Functions

 Bitfield2D ()
 Default constructor which initializes to size 0, 0.
 
 Bitfield2D (size_t b_size1, size_t b_size2)
 Constructor which sets the initial sizes. More...
 
void Delete ()
 Deletes the stored data, resets the sizes to 0, and releases the memory.
 
bool IsEmpty () const
 True if the total size of the bits is 0.
 
Bitfield::BitfieldBool operator() (size_t x, size_t y)
 Bounds-checked access of the indexed element. More...
 
Bitfield::BitfieldBoolConst operator() (size_t x, size_t y) const
 Const version of operator()
 
Bitfield::BitfieldBool At (size_t x, size_t y)
 Identical to operator()
 
Bitfield::BitfieldBoolConst At (size_t x, size_t y) const
 Const version of At()
 
size_t size1 () const
 Return the extent in bits of dimension 1.
 
size_t size2 () const
 Return the extent in bits of dimension 2.
 
void Zero ()
 Set all bits to 0 / false.
 
void Zero1D (const size_t y)
 Set all bits of dimension 1 to zero at y indexed dimension 2.
 
bool Check (const size_t x, const size_t y) const
 True if indices x and y are both in bounds.
 
void Assert (const size_t x, const size_t y) const
 Throws ErrorMsgBounds if index x or y is out of bounds.
 

Friends

void swap (Bitfield2D &a, Bitfield2D &b)
 Swap the data in Bitfield2D a and b.
 

Detailed Description

A bounds-safe two-dimensional structure of efficiently packed bits.

Note AxB and BxA dimensions will both take AB bits of storage with the total rounded up to the nearest 32 bit word.

See also
Bitfield
Bitfield3D

Constructor & Destructor Documentation

◆ Bitfield2D()

RC::Bitfield2D::Bitfield2D ( size_t  b_size1,
size_t  b_size2 
)
inlineexplicit

Constructor which sets the initial sizes.

Efficiency note: The first dimension, set by b_size1, should be the one which is iterated over most frequently in innermost loops for caching gains.

Parameters
b_size1The size of the first dimension.
b_size2The size of the second dimension.

Member Function Documentation

◆ operator()()

Bitfield::BitfieldBool RC::Bitfield2D::operator() ( size_t  x,
size_t  y 
)
inline

Bounds-checked access of the indexed element.

Throws an ErrorMsgBounds exception if x or y is out of the bounds.

Parameters
xThe dimension 1 index of the bit to access.
yThe dimension 2 index of the bit to access.
Returns
A Bitfield::BitfieldBool structure that casts to a bool or can be assigned a bool value.

The documentation for this class was generated from the following file:
email address
— (c) 2015