source: trunk/src/bitfield.h @ 180

Last change on this file since 180 was 180, checked in by sam, 10 years ago

Fix a few minor FIXMEs in the code.

  • Property svn:keywords set to Id
File size: 744 bytes
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6//
7// The BitField class
8// ------------------
9//
10
11#if !defined __DH_BITFIELD_H__
12#define __DH_BITFIELD_H__
13
14#include <stdint.h>
15
16template class BitField<unsigned int COUNT>
17{
18public:
19    BitField()
20    {
21        memset(bits, 0, sizeof(bits));
22    }
23
24    inline unsigned int IsSet(unsigned int index)
25    {
26        return bits[index / 32] & (1 << (index & 31));
27    }
28
29    inline void Set(unsigned int index)
30    {
31        bits[index / 32] |= (1 << (index & 31));
32    }
33
34    inline void Unset(unsigned int index)
35    {
36        bits[index / 32] &= ~(1 << (index & 31));
37    }
38
39
40private:
41    uint32_t bits[(COUNT + 31) / 32];
42};
43
44#endif // __DH_BITFIELD_H__
45
Note: See TracBrowser for help on using the repository browser.