Bullet Collision Detection & Physics Library
gim_bitset.h
Go to the documentation of this file.
1 #ifndef GIM_BITSET_H_INCLUDED
2 #define GIM_BITSET_H_INCLUDED
3 
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 
38 #define GUINT_BIT_COUNT 32
39 #define GUINT_EXPONENT 5
40 
42 {
43 public:
45 
47  {
48 
49  }
50 
51  gim_bitset(GUINT bits_count)
52  {
53  resize(bits_count);
54  }
55 
57  {
58  }
59 
60  inline bool resize(GUINT newsize)
61  {
62  GUINT oldsize = m_container.size();
63  m_container.resize(newsize/GUINT_BIT_COUNT + 1,false);
64  while(oldsize<m_container.size())
65  {
66  m_container[oldsize] = 0;
67  }
68  return true;
69  }
70 
71  inline GUINT size()
72  {
74  }
75 
76  inline void set_all()
77  {
78  for(GUINT i = 0;i<m_container.size();++i)
79  {
80  m_container[i] = 0xffffffff;
81  }
82  }
83 
84  inline void clear_all()
85  {
86  for(GUINT i = 0;i<m_container.size();++i)
87  {
88  m_container[i] = 0;
89  }
90  }
91 
92  inline void set(GUINT bit_index)
93  {
94  if(bit_index>=size())
95  {
96  resize(bit_index);
97  }
98  m_container[bit_index >> GUINT_EXPONENT] |= (1 << (bit_index & (GUINT_BIT_COUNT-1)));
99  }
100 
102  inline char get(GUINT bit_index)
103  {
104  if(bit_index>=size())
105  {
106  return 0;
107  }
108  char value = m_container[bit_index >> GUINT_EXPONENT] &
109  (1 << (bit_index & (GUINT_BIT_COUNT-1)));
110  return value;
111  }
112 
113  inline void clear(GUINT bit_index)
114  {
115  m_container[bit_index >> GUINT_EXPONENT] &= ~(1 << (bit_index & (GUINT_BIT_COUNT-1)));
116  }
117 };
118 
119 
120 
121 
122 
123 #endif // GIM_CONTAINERS_H_INCLUDED
void clear(GUINT bit_index)
Definition: gim_bitset.h:113
void set_all()
Definition: gim_bitset.h:76
#define GUINT_BIT_COUNT
Definition: gim_bitset.h:38
void resize(GUINT size, bool call_constructor=true, const T &fillData=T())
Definition: gim_array.h:288
gim_array< GUINT > m_container
Definition: gim_bitset.h:44
GUINT size()
Definition: gim_bitset.h:71
bool resize(GUINT newsize)
Definition: gim_bitset.h:60
void clear_all()
Definition: gim_bitset.h:84
void set(GUINT bit_index)
Definition: gim_bitset.h:92
#define GUINT
Definition: gim_math.h:42
gim_bitset(GUINT bits_count)
Definition: gim_bitset.h:51
GUINT size() const
Definition: gim_array.h:144
#define GUINT_EXPONENT
Definition: gim_bitset.h:39