Changeset View
Changeset View
Standalone View
Standalone View
extern/bullet2/src/BulletCollision/Gimpact/gim_bitset.h
| Show All 28 Lines | |||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files | ||||
| GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details. | GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details. | ||||
| ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ||||
| */ | */ | ||||
| #include "gim_array.h" | #include "gim_array.h" | ||||
| #define GUINT_BIT_COUNT 32 | #define GUINT_BIT_COUNT 32 | ||||
| #define GUINT_EXPONENT 5 | #define GUINT_EXPONENT 5 | ||||
| class gim_bitset | class gim_bitset | ||||
| { | { | ||||
| public: | public: | ||||
| gim_array<GUINT> m_container; | gim_array<GUINT> m_container; | ||||
| gim_bitset() | gim_bitset() | ||||
| { | { | ||||
| } | } | ||||
| gim_bitset(GUINT bits_count) | gim_bitset(GUINT bits_count) | ||||
| { | { | ||||
| resize(bits_count); | resize(bits_count); | ||||
| } | } | ||||
| ~gim_bitset() | ~gim_bitset() | ||||
| { | { | ||||
| } | } | ||||
| inline bool resize(GUINT newsize) | inline bool resize(GUINT newsize) | ||||
| { | { | ||||
| GUINT oldsize = m_container.size(); | GUINT oldsize = m_container.size(); | ||||
| m_container.resize(newsize/GUINT_BIT_COUNT + 1,false); | m_container.resize(newsize / GUINT_BIT_COUNT + 1, false); | ||||
| while(oldsize<m_container.size()) | while (oldsize < m_container.size()) | ||||
| { | { | ||||
| m_container[oldsize] = 0; | m_container[oldsize] = 0; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| inline GUINT size() | inline GUINT size() | ||||
| { | { | ||||
| return m_container.size()*GUINT_BIT_COUNT; | return m_container.size() * GUINT_BIT_COUNT; | ||||
| } | } | ||||
| inline void set_all() | inline void set_all() | ||||
| { | { | ||||
| for(GUINT i = 0;i<m_container.size();++i) | for (GUINT i = 0; i < m_container.size(); ++i) | ||||
| { | { | ||||
| m_container[i] = 0xffffffff; | m_container[i] = 0xffffffff; | ||||
| } | } | ||||
| } | } | ||||
| inline void clear_all() | inline void clear_all() | ||||
| { | { | ||||
| for(GUINT i = 0;i<m_container.size();++i) | for (GUINT i = 0; i < m_container.size(); ++i) | ||||
| { | { | ||||
| m_container[i] = 0; | m_container[i] = 0; | ||||
| } | } | ||||
| } | } | ||||
| inline void set(GUINT bit_index) | inline void set(GUINT bit_index) | ||||
| { | { | ||||
| if(bit_index>=size()) | if (bit_index >= size()) | ||||
| { | { | ||||
| resize(bit_index); | resize(bit_index); | ||||
| } | } | ||||
| m_container[bit_index >> GUINT_EXPONENT] |= (1 << (bit_index & (GUINT_BIT_COUNT-1))); | m_container[bit_index >> GUINT_EXPONENT] |= (1 << (bit_index & (GUINT_BIT_COUNT - 1))); | ||||
| } | } | ||||
| ///Return 0 or 1 | ///Return 0 or 1 | ||||
| inline char get(GUINT bit_index) | inline char get(GUINT bit_index) | ||||
| { | { | ||||
| if(bit_index>=size()) | if (bit_index >= size()) | ||||
| { | { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| char value = m_container[bit_index >> GUINT_EXPONENT] & | char value = m_container[bit_index >> GUINT_EXPONENT] & | ||||
| (1 << (bit_index & (GUINT_BIT_COUNT-1))); | (1 << (bit_index & (GUINT_BIT_COUNT - 1))); | ||||
| return value; | return value; | ||||
| } | } | ||||
| inline void clear(GUINT bit_index) | inline void clear(GUINT bit_index) | ||||
| { | { | ||||
| m_container[bit_index >> GUINT_EXPONENT] &= ~(1 << (bit_index & (GUINT_BIT_COUNT-1))); | m_container[bit_index >> GUINT_EXPONENT] &= ~(1 << (bit_index & (GUINT_BIT_COUNT - 1))); | ||||
| } | } | ||||
| }; | }; | ||||
| #endif // GIM_CONTAINERS_H_INCLUDED | #endif // GIM_CONTAINERS_H_INCLUDED | ||||