[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / BulletCollision / Gimpact / gim_bitset.h
1 #ifndef GIM_BITSET_H_INCLUDED
2 #define GIM_BITSET_H_INCLUDED
3 /*! \file gim_bitset.h
4 \author Francisco Leon Najera
5 */
6 /*
7 -----------------------------------------------------------------------------
8 This source file is part of GIMPACT Library.
9
10 For the latest info, see http://gimpact.sourceforge.net/
11
12 Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
13 email: projectileman@yahoo.com
14
15  This library is free software; you can redistribute it and/or
16  modify it under the terms of EITHER:
17    (1) The GNU Lesser General Public License as published by the Free
18        Software Foundation; either version 2.1 of the License, or (at
19        your option) any later version. The text of the GNU Lesser
20        General Public License is included with this library in the
21        file GIMPACT-LICENSE-LGPL.TXT.
22    (2) The BSD-style license that is included with this library in
23        the file GIMPACT-LICENSE-BSD.TXT.
24    (3) The zlib/libpng license that is included with this library in
25        the file GIMPACT-LICENSE-ZLIB.TXT.
26
27  This library is distributed in the hope that it will be useful,
28  but WITHOUT ANY WARRANTY; without even the implied warranty of
29  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
30  GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
31
32 -----------------------------------------------------------------------------
33 */
34
35 #include "gim_array.h"
36
37 #define GUINT_BIT_COUNT 32
38 #define GUINT_EXPONENT 5
39
40 class gim_bitset
41 {
42 public:
43         gim_array<GUINT> m_container;
44
45         gim_bitset()
46         {
47         }
48
49         gim_bitset(GUINT bits_count)
50         {
51                 resize(bits_count);
52         }
53
54         ~gim_bitset()
55         {
56         }
57
58         inline bool resize(GUINT newsize)
59         {
60                 GUINT oldsize = m_container.size();
61                 m_container.resize(newsize / GUINT_BIT_COUNT + 1, false);
62                 while (oldsize < m_container.size())
63                 {
64                         m_container[oldsize] = 0;
65                 }
66                 return true;
67         }
68
69         inline GUINT size()
70         {
71                 return m_container.size() * GUINT_BIT_COUNT;
72         }
73
74         inline void set_all()
75         {
76                 for (GUINT i = 0; i < m_container.size(); ++i)
77                 {
78                         m_container[i] = 0xffffffff;
79                 }
80         }
81
82         inline void clear_all()
83         {
84                 for (GUINT i = 0; i < m_container.size(); ++i)
85                 {
86                         m_container[i] = 0;
87                 }
88         }
89
90         inline void set(GUINT bit_index)
91         {
92                 if (bit_index >= size())
93                 {
94                         resize(bit_index);
95                 }
96                 m_container[bit_index >> GUINT_EXPONENT] |= (1 << (bit_index & (GUINT_BIT_COUNT - 1)));
97         }
98
99         ///Return 0 or 1
100         inline char get(GUINT bit_index)
101         {
102                 if (bit_index >= size())
103                 {
104                         return 0;
105                 }
106                 char value = m_container[bit_index >> GUINT_EXPONENT] &
107                                          (1 << (bit_index & (GUINT_BIT_COUNT - 1)));
108                 return value;
109         }
110
111         inline void clear(GUINT bit_index)
112         {
113                 m_container[bit_index >> GUINT_EXPONENT] &= ~(1 << (bit_index & (GUINT_BIT_COUNT - 1)));
114         }
115 };
116
117 #endif  // GIM_CONTAINERS_H_INCLUDED