Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Opcode / Ice / IceBitArray.cpp
1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 /**
3  *      Contains code for bit arrays.
4  *      \file           IceBitArray.cpp
5  *      \author         Pierre Terdiman
6  *      \date           February, 5, 2000
7  */
8 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9
10 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11 /**
12  *      A simple array of bits stored as bytes.
13  *
14  *      \class          Container
15  *      \author         Pierre Terdiman
16  *      \version        1.0
17  *      \date           February, 5, 2000
18 */
19 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20
21 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
22 // Precompiled Header
23 #include "StdAfx.h"
24
25 using namespace Opcode;
26
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
28 /**
29  *      Constructor.
30  */
31 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32 BitArray::BitArray() : mSize(0), mBits(null)
33 {
34 }
35
36 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
37 /**
38  *      Constructor.
39  */
40 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41 BitArray::BitArray(udword nb_bits) : mSize(0), mBits(null)
42 {
43         Init(nb_bits);
44 }
45
46 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47 /**
48  *      Destructor.
49  */
50 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51 BitArray::~BitArray()
52 {
53         ICE_FREE(mBits);
54         mSize = 0;
55 }
56
57 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58 /**
59  *      Initializes the bit array for a given number of entries
60  *      \param          nb_bits         [in] max number of entries in the array
61  *      \return         true if success
62  */
63 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
64 bool BitArray::Init(udword nb_bits)
65 {
66         mSize = BitsToDwords(nb_bits);
67         // Get ram for n bits
68         ICE_FREE(mBits);
69         mBits = (udword*)ICE_ALLOC(sizeof(udword)*mSize);
70         // Set all bits to 0
71         ClearAll();
72         return true;
73 }