3ds Max C++ API Reference
BitArray Class Reference

#include <bitarray.h>

+ Inheritance diagram for BitArray:

Classes

class  NumberSetProxy
 

Public Member Functions

 BitArray ()
 
 BitArray (int n)
 
 BitArray (const BitArray &b)
 
 ~BitArray ()
 
void SetSize (int n, int save=0)
 
int GetSize () const
 
void ClearAll ()
 
void SetAll ()
 
void Set (int i)
 
void Clear (int i)
 
void Set (int i, int b)
 
__forceinline int operator[] (int i) const
 
bool IsEmpty () const
 
bool AnyBitSet () const
 
NumberSetProxy NumberSet () const
 
void Compress ()
 
void Expand ()
 
void Reverse (BOOL keepZero=FALSE)
 
void Rotate (int direction, int count)
 
void Shift (int direction, int count, int where=0)
 
void EnumSet (BitArrayCallback &cb)
 
void DeleteSet (BitArray &dset, int mult=1)
 
IOResult Save (ISave *isave)
 
IOResult Load (ILoad *iload)
 
bool operator== (const BitArray &b) const
 
BitArrayoperator= (const BitArray &b)
 
BitArrayoperator&= (const BitArray &b)
 
BitArrayoperator|= (const BitArray &b)
 
BitArrayoperator^= (const BitArray &b)
 
BitArray operator& (const BitArray &) const
 
BitArray operator| (const BitArray &) const
 
BitArray operator^ (const BitArray &) const
 
BitArray operator~ () const
 
void Swap (BitArray &other)
 Swap the contents of two bitarrays. More...
 

Friends

class NumberSetProxy
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Detailed Description

See also
Template Class Tab, Class BitArrayCallback.

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.

Constructor & Destructor Documentation

◆ BitArray() [1/3]

BitArray ( )
inline
Remarks
Default constructor. Sets the number of bits to 0.
206  {
207  bits = NULL;
208  numBits = 0;
209  BitArrayAllocated();
210  }
#define NULL
Definition: autoptr.h:18
DWORD_PTR * bits
Definition: bitarray.h:69

◆ BitArray() [2/3]

BitArray ( int  n)
inline
Remarks
Constructor.
Parameters:
int i

The size of the BitArray in bits.
216  {
217  DbgAssert(n >= 0);
218  if (n < 0)
219  {
220  n = 0;
221  }
222  if (UseLocalBits(n))
223  {
224  numBits = n;
225  localBits = 0;
226 
227  BitArrayAllocated();
228  }
229  else
230  {
231  CreateBitArrayImpl(n);
232  }
233  }
DWORD_PTR localBits
Definition: bitarray.h:72
#define DbgAssert(expr)
Definition: assert1.h:82

◆ BitArray() [3/3]

BitArray ( const BitArray b)
inline
Remarks
Constructor. Duplicates the BitArray passed.
Parameters:
const BitArray& b

The BitArray to duplicate.
239  {
240  if (b.UseLocalBits())
241  {
242  localBits = b.localBits;
243  numBits = b.numBits;
244 
245  BitArrayAllocated();
246  }
247  else
248  {
249  SetBitsFromImpl(b);
250  }
251  }

◆ ~BitArray()

~BitArray ( )
inline
254  {
255  if (!UseLocalBits())
256  FreeBitsImpl();
257  else
258  BitArrayDeallocated();
259  }

Member Function Documentation

◆ SetSize()

void SetSize ( int  n,
int  save = 0 
)
Remarks
Sets the number of bits used.
Parameters
n- The number of bits in to be in the array. If this value is a negative number, or equal to the current size of the BitArray then nothing will happen.
save- If passed as 1, the old bit values will be preserved when the array is resized.

◆ GetSize()

int GetSize ( ) const
inline
Remarks
Returns the size of the bit array in bits.
269  {
270  return numBits;
271  }

◆ ClearAll()

void ClearAll ( )
inline
Remarks
Clears all the bits in the array (sets them to 0).
275  {
276  if (UseLocalBits())
277  {
278  localBits = 0;
279  }
280  else
281  {
282  ClearAllImpl();
283  }
284  }

◆ SetAll()

void SetAll ( )
inline
Remarks
Sets all the bits in the array to 1.
288  {
289  if (UseLocalBits())
290  {
291  localBits = BitMask(numBits) - 1;
292  }
293  else
294  {
295  SetAllImpl();
296  }
297  }

◆ Set() [1/2]

void Set ( int  i)
inline
Remarks
Set the i-th bit to 1.
Parameters
i- The array index of the bit to set.
302  {
303  DbgAssert(i > -1 && i < numBits);
304  if ((i > -1) && (i < numBits))
305  {
306  if (UseLocalBits())
307  {
308  localBits |= BitMask(i);
309  }
310  else
311  {
312  bits[i >> NSHIFT] |= BitMask(i & BITS_PER_DWORD_PTR_MASK);
313  }
314  }
315  }

◆ Clear()

void Clear ( int  i)
inline
Remarks
Sets the i-th bit to 0.
Parameters:
int i

The array index of the bit to clear.
322  {
323  DbgAssert(i > -1 && i < numBits);
324  if ((i > -1) && (i < numBits))
325  {
326  if (UseLocalBits())
327  {
328  localBits &= ~BitMask(i);
329  }
330  else
331  {
332  bits[i >> NSHIFT] &= ~BitMask(i & BITS_PER_DWORD_PTR_MASK);
333  }
334  }
335  }

◆ Set() [2/2]

void Set ( int  i,
int  b 
)
inline
Remarks
Set the i-th bit to b.
Parameters
i- The index of the bit to set.
b- The value to set, either 1 or 0.
341  {
342  b ? Set(i) : Clear(i);
343  }
void Clear(int i)
Definition: bitarray.h:321
void Set(int i)
Definition: bitarray.h:301

◆ operator[]()

__forceinline int operator[] ( int  i) const
inline
Remarks
Gets the i-th bit.
Parameters
i- The index of the bit. If the index is a negative or bigger than the array size, it returns 0
348  {
349  DbgAssert(i > -1);
350  DbgAssert(i < numBits);
351  if ((i > -1) && (i < numBits))
352  return UseLocalBits() ? (localBits & BitMask(i) ? 1 : 0) : GetBit(i);
353  else
354  return 0;
355  }

◆ IsEmpty()

bool IsEmpty ( ) const
inline
Remarks
Returns true if no bits are set; otherwise false. This method is much faster than checking if NumberSet() returns 0.
360  {
361  return UseLocalBits() ? !localBits : IsEmptyImpl();
362  }

◆ AnyBitSet()

bool AnyBitSet ( ) const
inline
364  {
365  return !IsEmpty();
366  }
bool IsEmpty() const
Definition: bitarray.h:359

◆ NumberSet()

NumberSetProxy NumberSet ( ) const
inline
Remarks
how many bits are 1's? use IsEmpty() for faster checks
Returns
Returns a proxy object which can optimize client code depending on the type of access required (ie: != 0 would call IsEmpty(), etc)
372  {
373  return NumberSetProxy(*this);
374  }
friend class NumberSetProxy
Definition: bitarray.h:201

◆ Compress()

void Compress ( )
Remarks
This is not currently implemented and is reserved for future use.

◆ Expand()

void Expand ( )
Remarks
This is not currently implemented and is reserved for future use.

◆ Reverse()

void Reverse ( BOOL  keepZero = FALSE)
Remarks
Reverses the bits in the BitArray.
Parameters:
BOOL keepZero = FALSE

If TRUE the zero bit is kept where it is.

◆ Rotate()

void Rotate ( int  direction,
int  count 
)
Remarks
Rotates the bits in the BitArray (with wraparound).
Parameters:
int direction

The direction to rotate.

int count

The number of bits to rotate.

◆ Shift()

void Shift ( int  direction,
int  count,
int  where = 0 
)
Remarks
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.

◆ EnumSet()

void EnumSet ( BitArrayCallback cb)
Remarks
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.

◆ DeleteSet()

void DeleteSet ( BitArray dset,
int  mult = 1 
)
Remarks
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);

◆ Save()

IOResult Save ( ISave isave)
Remarks
Saves the BitArray to the 3ds Max file.

◆ Load()

IOResult Load ( ILoad iload)
Remarks
Loads the BitArray from the 3ds Max file.
Operators:

◆ operator==()

bool operator== ( const BitArray b) const
inline
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.
Returns
true if the BitArrays are 'equal' (same size and same bits set); otherwise false.
453  {
454  return (numBits == b.numBits) && (UseLocalBits() ? (localBits == b.localBits) : CompareBitsImpl(b));
455  }

◆ operator=()

BitArray& operator= ( const BitArray b)
Remarks
Assignment operator.

◆ operator&=()

BitArray& operator&= ( const BitArray b)
Remarks
AND= this BitArray with the specified BitArray.

◆ operator|=()

BitArray& operator|= ( const BitArray b)
Remarks
OR= this BitArray with the specified BitArray.

◆ operator^=()

BitArray& operator^= ( const BitArray b)
Remarks
XOR= this BitArray with the specified BitArray.

◆ operator&()

BitArray operator& ( const BitArray ) const
Remarks
AND two BitArrays

◆ operator|()

BitArray operator| ( const BitArray ) const
Remarks
OR two BitArrays

◆ operator^()

BitArray operator^ ( const BitArray ) const
Remarks
XOR two BitArrays

◆ operator~()

BitArray operator~ ( ) const
inline
Remarks
Unary NOT function
480  {
481  return UseLocalBits() ? BitArray(~localBits, numBits, true) : OperatorNotImpl();
482  }
BitArray()
Definition: bitarray.h:205

◆ Swap()

void Swap ( BitArray other)

Swap the contents of two bitarrays.

This is an efficient way of transfering the contents of a temporary bitarray object into a more permanent instance, such as a data member. For instance:

{
BitArray tmp(size);
// do something with tmp...
m_MyBitArray.Swap(tmp);
}
Definition: bitarray.h:60

would be more efficient than using operator= in this case.

Parameters
[in,out]otherThe contents of 'other' will be swaped with the contents of 'this'

Friends And Related Function Documentation

◆ NumberSetProxy

friend class NumberSetProxy
friend

Member Data Documentation

◆ bits

DWORD_PTR* bits

◆ localBits

DWORD_PTR localBits