OpenClovis Logo

API Usage Examples
Bitmap Management

Code Examples. More...

Code Examples.

Create a bitmap of specified length

ClBitmapHandleT bitHdl = CL_BM_INVALID_BITMAP_HANDLE;
ClRcT rc = CL_OK;
ClUint32T bitNum = 10;
/*Creates a bitmap of length 10 (bit 0-9)*/
rc = clBitmapCreate(&bitHdl, bitNum);
if(CL_OK != rc)
{
clLogError("EXP","BIT", "Failed to create bitmap.");
return rc;
}

Set a bit of the bitmap

ClUint32T bitNum = 5;
/*Get bitHdl by calling clBitmapCreate()*/
rc = clBitmapBitSet(bitHdl, bitNum);
if(CL_OK != rc)
{
clLogError("EXP","BIT", "Failed to set the bit 5.");
return rc;
}

Check the status of a bit of the bitmap

ClUint32T bitNum = 5;
ClRcT retVal = CL_OK;
ClInt32T bitStatus = CL_BM_BIT_UNDEF;
/*Get bitHdl by calling clBitmapCreate()*/
bitStatus = clBitmapIsBitSet(bitHdl, bitNum, &retVal);
if(CL_OK != retVal)
{
clLogError("EXP","BIT", "Failed to check the bit status.");
return rc;
}
if(CL_BM_BIT_SET == bitStatus)
{
clLogInfo("EXP","BIT", "Bit 5 is set.");
}
else if(CL_BM_BIT_CLEAR == bitStatus)
{
clLogInfo("EXP","BIT", "Bit 5 is not set.");
}
else
{
clLogInfo("EXP","BIT", "Bit 5 is undefined.");
}

Clear a bit of the bitmap

ClUint32T bitNum = 3;
Clear a bit of the bitmap
/*Get bitHdl by calling clBitmapCreate()*/
rc = clBitmapBitClear(bitHdl, bitNum);
if(CL_OK != rc)
{
clLogError("EXP","BIT", "Failed to clear bit number 3.");
return rc;
}

Get the length of the bitmap

ClUint32T bitmapLength = 0;
/*Get bitHdl by calling clBitmapCreate()*/
bitmapLength = clBitmapLen(bitHdl);
if(0 == bitmapLength)
{
clLogError("EXP","BIT", "Failed to get the bitmap length.");
}
else
{
clLogInfo("EXP","BIT", "Bitmap length = %d.", bitmapLength);
}

Get the number of bits set in the bitmap

ClUint32T numBitSet = 0;
/*Get bitHdl by calling clBitmapCreate()*/
rc = clBitmapNumBitsSet(bitHdl, &numBitSet);
if(CL_OK != rc)
{
clLogError("EXP","BIT", "Failed to get the bitmap length.");
return rc;
}
else
{
clLogInfo("EXP","BIT", "Number of bits set in the bitmap = %d.",
numBitSet);
}

Destroy the Bitmap

/*Get bitHdl by calling clBitmapCreate()*/
rc = clBitmapDestroy(bitHdl);
if(CL_OK != rc)
{
clLogError("EXP","BIT", "Failed to destroy the bitmap.");
return rc;
}

Generated on Tue Jan 10 10:29:15 PST 2012 for OpenClovis SDK using Doxygen