Class BitArray

3DS Max Plug-In SDK

Class BitArray

See Also: Template Class Tab, Class BitArrayCallback.

Class BitArray

Description:

This class allows the developer to define a set of bit flags that may be treated as a virtual array and are stored in an efficient manner. The class has methods to set, clear and return the i-th bit, resize the BitArray, etc. All methods are implemented by the system.

Methods:

Prototype:

BitArray()

Remarks:

Default constructor. Sets the number of bits to 0.

Prototype:

BitArray(int n);

Remarks:

Constructor.

Parameters:

int i

The size of the BitArray in bits.

Prototype:

BitArray(const BitArray& b);

Remarks:

Constructor. Duplicates the BitArray passed.

Parameters:

const BitArray& b

The BitArray to duplicate.

Prototype:

void SetSize(int n, int save=0)

Remarks:

Sets the number of bits used.

Parameters:

int n

The number of bits in the array.

int save=0

If passed as 1, the old bit values will be preserved when the array is resized.

Prototype:

int GetSize()

Remarks:

Returns the size of the bit array in bits.

Prototype:

void ClearAll()

Remarks:

Clears all the bits in the array (sets them to 0).

Prototype:

void SetAll()

Remarks:

Sets all the bits in the array to 1.

Prototype:

void Set(int i)

Remarks:

Set the i-th bit to 1.

Parameters:

int i

The array index of the bit to set.

Prototype:

void Clear(int i)

Remarks:

Sets the i-th bit to 0.

Parameters:

int i

The array index of the bit to clear.

Prototype:

void Set(int i, int b);

Remarks:

Set the i-th bit to b.

Parameters:

int i

The index of the bit to set.

int b

The value to set, either 1 or 0.

Prototype:

int NumberSet()

Remarks:

Returns the number of bits set to 1.

Return Value:

The number of bits set to 1.

Prototype:

BOOL IsEmpty();

Remarks:

This method is available in release 3.0 and later only.

Returns TRUE if no bits are set; otherwise FALSE. This method is much faster than checking if NumberSet() returns 0.

Prototype:

void Compress()

Remarks:

This is not currently implemented and is reserved for future use.

Prototype:

void Expand()

Remarks:

This is not currently implemented and is reserved for future use.

Prototype:

void Reverse(BOOL keepZero = FALSE);

Remarks:

This method is available in release 2.0 and later only.

Reverses the bits in the BitArray.

Parameters:

BOOL keepZero = FALSE

If TRUE the zero bit is kept where it is.

Prototype:

void Rotate(int direction, int count);

Remarks:

This method is available in release 2.0 and later only.

Rotates the bits in the BitArray (with wraparound).

Parameters:

int direction

The direction to rotate.

int count

The number of bits to rotate.

Prototype:

void Shift(int direction, int count, int where=0);

Remarks:

This method is available in release 2.0 and later only.

Shifts the bits in the BitArray (without wraparound).

Parameters:

int direction

One of the following values:

LEFT_BITSHIFT

RIGHT_BITSHIFT

int count

The number of bits to shift.

int where=0

This indicates where the shift will begin. For example, if you have a BitArray containing: 10101010

and you Shift(LEFT_BITSHIFT, 1, 4) you'll get: 10100100

All the bits from 4 to 8 are shifted one bit left, with zeroes shifted in from the right. The first bit affected is the where bit. If you leave off the where parameter you'd get the usual: 01010100

The RIGHT_BITSHIFT starts at that bit; it is unaffected because the operation proceeds to the right: 10101010.

Shift(RIGHT_BITSHIFT, 1, 4) results in: 10101101.

Prototype:

void EnumSet(BitArrayCallback &cb);

Remarks:

This method is available in release 3.0 and later only.

This method is used to enumerate all the elements that have a "1" value, and call the callback proc() with the index of the element.

Parameters:

BitArrayCallback &cb

The callback object whose proc() method is called.

Prototype:

void DeleteSet(BitArray & dset, int mult=1);

Remarks:

This method is available in release 3.0 and later only.

This method allows you to delete a selection of elements from this BitArray. This is useful, for instance, if you're deleting a set of vertices from a mesh and wish to keep the vertSel and vertHide arrays up to date.

Parameters:

BitArray & dset

This is a bit array which represents which elements should be deleted. Typically (if mult==1) dset will have the same size as (this).

int mult=1

This is a multiplier which indicates how many elements in (*this) are deleted for each entry in dset. For instance, when deleting faces in a mesh, you also need to delete the corresponding edge selection data. Since edgeSel[f*3], edgeSel[f*3+1], and edgeSel[f*3+2] correspond to face f, you'd use mult=3:

faceSel.DeleteSet (fdel);

edgeSel.DeleteSet (fdel, 3);

Prototype:

IOResult Save(ISave* isave);

Remarks:

Saves the BitArray to the 3ds max file.

Prototype:

IOResult Load(ILoad* iload);

Remarks:

Loads the BitArray from the 3ds max file.

Operators:

Prototype:

int operator[](int i) const;

Remarks:

Gets the i-th bit.

Parameters:

int i

The index of the bit.

Prototype:

BOOL operator==(const BitArray& b);

Remarks:

This operator is available in release 3.0 and later only.

Comparison operator.

Parameters:

const BitArray& b

The BitArray to compare with this one.

Return Value:

TRUE if the BitArrays are 'equal' (same size and same bits set); otherwise FALSE.

Assignment operators: These require arrays of the same size!

Prototype:

BitArray& operator=(const BitArray& b)

Remarks:

Assignment operator.

Prototype:

BitArray& operator&=(const BitArray& b)

Remarks:

AND= this BitArray with the specified BitArray.

Prototype:

BitArray& operator|=(const BitArray& b)

Remarks:

OR= this BitArray with the specified BitArray.

Prototype:

BitArray& operator^=(const BitArray& b)

Remarks:

XOR= this BitArray with the specified BitArray.

Binary operators: These require arrays of the same size!

Prototype:

BitArray operator&(const BitArray&) const

Remarks:

AND two BitArrays

Prototype:

BitArray operator|(const BitArray&) const

Remarks:

OR two BitArrays

Prototype:

BitArray operator^(const BitArray&) const

Remarks:

XOR two BitArrays

Unary operators

Prototype:

BitArray operator~()

Remarks:

Unary NOT function