source: trunk/src/bitfield.h @ 748

Last change on this file since 748 was 748, checked in by sam, 9 years ago

core: fix include guard naming scheme.

  • Property svn:keywords set to Id
File size: 1.0 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11//
12// The BitField class
13// ------------------
14//
15
16#if !defined __LOL_BITFIELD_H__
17#define __LOL_BITFIELD_H__
18
19#include <stdint.h>
20
21namespace lol
22{
23
24template class BitField<unsigned int COUNT>
25{
26public:
27    BitField()
28    {
29        memset(bits, 0, sizeof(bits));
30    }
31
32    inline unsigned int IsSet(unsigned int index)
33    {
34        return bits[index / 32] & (1 << (index & 31));
35    }
36
37    inline void Set(unsigned int index)
38    {
39        bits[index / 32] |= (1 << (index & 31));
40    }
41
42    inline void Unset(unsigned int index)
43    {
44        bits[index / 32] &= ~(1 << (index & 31));
45    }
46
47
48private:
49    uint32_t bits[(COUNT + 31) / 32];
50};
51
52} /* namespace lol */
53
54#endif // __LOL_BITFIELD_H__
55
Note: See TracBrowser for help on using the repository browser.