Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
BitArray.h
Go to the documentation of this file.
1
//! @file BitArray.h
2
//! CBitArray class for handling array of bits
3
//
4
//////////////////////////////////////////////////////////////////////
5
6
#ifndef CBITARRAY_CLASS_H
7
#define CBITARRAY_CLASS_H
8
9
#ifdef _MSC_VER
10
#pragma once
11
#endif
// _MSC_VER
12
13
BEGIN_MOOTOOLS_NAMESPACE
14
15
//! @class CBitArray
16
//! @brief CBitArray class for handling array of bits
17
class
DLL_TOOLSFUNCTION
CBitArray
18
{
19
protected
:
20
unsigned
int
size;
21
unsigned
int
*buffer;
22
23
unsigned
int
GetBufferSize()
const
;
24
unsigned
int
GetIndex(
unsigned
int
index,
unsigned
int
&
shift
)
const
;
25
26
public
:
27
CBitArray
();
28
virtual
~CBitArray
();
29
30
void
RemoveAll();
31
void
SetSize(
unsigned
int
size,
bool
value);
// Set bitarray size. This currently remove all entries, if buffer size is modified
32
unsigned
int
GetSize()
const
;
33
34
bool
operator[](
unsigned
int
index)
const
;
35
bool
GetAt(
unsigned
int
index)
const
;
36
void
SetAt(
unsigned
int
index,
bool
value);
37
38
unsigned
int
GetCount(
bool
value)
const
;
// Return number of element set to value
39
bool
IsOneSet(
bool
value)
const
;
40
41
unsigned
int
*DetachBuffer(
unsigned
int
&
buffersize
);
42
unsigned
int
*GetBuffer(
unsigned
int
&
buffersize
);
43
bool
SetBuffer(
unsigned
int
*buffer,
unsigned
int
size,
unsigned
int
buffersize
);
44
45
void
EraseByte(
unsigned
int
index,
bool
value);
// Fast clear of the byte containing the index for fast processing
46
};
47
48
inline
unsigned
int
CBitArray::GetIndex(
unsigned
int
index,
unsigned
int
&
shift
)
const
49
{
50
shift
= (index % 32);
51
shift
= 1U <<
shift
;
52
53
return
(index / 32);
54
}
55
56
inline
bool
CBitArray::operator[](
unsigned
int
index)
const
57
{
58
XASSERT(index < size);
59
if
(index >= size)
60
return
false
;
61
62
unsigned
int
shift
;
63
index = GetIndex(index,
shift
);
64
65
return
!!(buffer[index] &
shift
);
66
}
67
68
inline
bool
CBitArray::GetAt(
unsigned
int
index)
const
69
{
70
return
(*
this
)[index];
71
}
72
73
inline
void
CBitArray::SetAt(
unsigned
int
index,
bool
value)
74
{
75
XASSERT(index < size);
76
if
(index >= size)
77
return
;
78
79
unsigned
int
shift
;
80
index = GetIndex(index,
shift
);
81
82
if
(value)
83
buffer[index] |=
shift
;
84
else
85
buffer[index] &=
~shift
;
86
}
87
88
inline
void
CBitArray::EraseByte(
unsigned
int
index,
bool
value)
89
{
90
XASSERT(index < size);
91
if
(index >= size)
92
return
;
93
94
if
(value)
95
buffer[index / 32] = 0xFFFFFFFF;
96
else
97
buffer[index / 32] = 0;
98
}
99
100
END_MOOTOOLS_NAMESPACE
101
102
#endif
// !CBITARRAY_CLASS_H
C3DTPoint
The class defines an x, y, z 3D point which can use int, float or double.
Definition
3DPoint.h:27
CBitArray
CBitArray class for handling array of bits.
Definition
BitArray.h:18
VS2022-PolygonCruncherSDK-Full-IO
SDK
Includes
BitArray.h
Generated by
1.9.8