Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletCollision/GIMPACT/gim_bitset.h @ 2041

Last change on this file since 2041 was 1963, checked in by rgrieder, 16 years ago

Added Bullet physics engine.

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1#ifndef GIM_BITSET_H_INCLUDED
2#define GIM_BITSET_H_INCLUDED
3/*! \file gim_bitset.h
4\author Francisco Len Nßjera
5*/
6/*
7-----------------------------------------------------------------------------
8This source file is part of GIMPACT Library.
9
10For the latest info, see http://gimpact.sourceforge.net/
11
12Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
13email: 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/*! \addtogroup CONTAINERS
38\brief
39Abstract class for template containers
40*/
41//! @{
42
43#define GUINT_BIT_COUNT 32
44#define GUINT_EXPONENT 5
45
46class gim_bitset
47{
48public:
49    gim_array<GUINT> m_container;
50
51    gim_bitset()
52    {
53
54    }
55
56    gim_bitset(GUINT bits_count)
57    {
58        resize(bits_count);
59    }
60
61    ~gim_bitset()
62    {
63    }
64
65        inline bool resize(GUINT newsize)
66        {
67                GUINT oldsize = m_container.size();
68                m_container.resize(newsize/GUINT_BIT_COUNT + 1,false);
69                while(oldsize<m_container.size())
70                {
71                        m_container[oldsize] = 0;
72                }
73                return true;
74        }
75
76        inline GUINT size()
77        {
78                return m_container.size()*GUINT_BIT_COUNT;
79        }
80
81        inline void set_all()
82        {
83                for(GUINT i = 0;i<m_container.size();++i)
84                {
85                        m_container[i] = 0xffffffff;
86                }
87        }
88
89        inline void clear_all()
90        {
91            for(GUINT i = 0;i<m_container.size();++i)
92                {
93                        m_container[i] = 0;
94                }
95        }
96
97        inline void set(GUINT bit_index)
98        {
99                if(bit_index>=size())
100                {
101                        resize(bit_index);
102                }
103                m_container[bit_index >> GUINT_EXPONENT] |= (1 << (bit_index & (GUINT_BIT_COUNT-1)));
104        }
105
106        ///Return 0 or 1
107        inline char get(GUINT bit_index)
108        {
109                if(bit_index>=size())
110                {
111                        return 0;
112                }
113                char value = m_container[bit_index >> GUINT_EXPONENT] &
114                                         (1 << (bit_index & (GUINT_BIT_COUNT-1)));
115                return value;
116        }
117
118        inline void clear(GUINT bit_index)
119        {
120            m_container[bit_index >> GUINT_EXPONENT] &= ~(1 << (bit_index & (GUINT_BIT_COUNT-1)));
121        }
122};
123
124
125//! @}
126
127
128
129#endif // GIM_CONTAINERS_H_INCLUDED
Note: See TracBrowser for help on using the repository browser.