Blender V2.61 - r43446
|
00001 #ifndef GIM_BITSET_H_INCLUDED 00002 #define GIM_BITSET_H_INCLUDED 00003 00006 /* 00007 ----------------------------------------------------------------------------- 00008 This source file is part of GIMPACT Library. 00009 00010 For the latest info, see http://gimpact.sourceforge.net/ 00011 00012 Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. 00013 email: projectileman@yahoo.com 00014 00015 This library is free software; you can redistribute it and/or 00016 modify it under the terms of EITHER: 00017 (1) The GNU Lesser General Public License as published by the Free 00018 Software Foundation; either version 2.1 of the License, or (at 00019 your option) any later version. The text of the GNU Lesser 00020 General Public License is included with this library in the 00021 file GIMPACT-LICENSE-LGPL.TXT. 00022 (2) The BSD-style license that is included with this library in 00023 the file GIMPACT-LICENSE-BSD.TXT. 00024 (3) The zlib/libpng license that is included with this library in 00025 the file GIMPACT-LICENSE-ZLIB.TXT. 00026 00027 This library is distributed in the hope that it will be useful, 00028 but WITHOUT ANY WARRANTY; without even the implied warranty of 00029 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 00030 GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details. 00031 00032 ----------------------------------------------------------------------------- 00033 */ 00034 00035 #include "gim_array.h" 00036 00037 00038 #define GUINT_BIT_COUNT 32 00039 #define GUINT_EXPONENT 5 00040 00041 class gim_bitset 00042 { 00043 public: 00044 gim_array<GUINT> m_container; 00045 00046 gim_bitset() 00047 { 00048 00049 } 00050 00051 gim_bitset(GUINT bits_count) 00052 { 00053 resize(bits_count); 00054 } 00055 00056 ~gim_bitset() 00057 { 00058 } 00059 00060 inline bool resize(GUINT newsize) 00061 { 00062 GUINT oldsize = m_container.size(); 00063 m_container.resize(newsize/GUINT_BIT_COUNT + 1,false); 00064 while(oldsize<m_container.size()) 00065 { 00066 m_container[oldsize] = 0; 00067 } 00068 return true; 00069 } 00070 00071 inline GUINT size() 00072 { 00073 return m_container.size()*GUINT_BIT_COUNT; 00074 } 00075 00076 inline void set_all() 00077 { 00078 for(GUINT i = 0;i<m_container.size();++i) 00079 { 00080 m_container[i] = 0xffffffff; 00081 } 00082 } 00083 00084 inline void clear_all() 00085 { 00086 for(GUINT i = 0;i<m_container.size();++i) 00087 { 00088 m_container[i] = 0; 00089 } 00090 } 00091 00092 inline void set(GUINT bit_index) 00093 { 00094 if(bit_index>=size()) 00095 { 00096 resize(bit_index); 00097 } 00098 m_container[bit_index >> GUINT_EXPONENT] |= (1 << (bit_index & (GUINT_BIT_COUNT-1))); 00099 } 00100 00102 inline char get(GUINT bit_index) 00103 { 00104 if(bit_index>=size()) 00105 { 00106 return 0; 00107 } 00108 char value = m_container[bit_index >> GUINT_EXPONENT] & 00109 (1 << (bit_index & (GUINT_BIT_COUNT-1))); 00110 return value; 00111 } 00112 00113 inline void clear(GUINT bit_index) 00114 { 00115 m_container[bit_index >> GUINT_EXPONENT] &= ~(1 << (bit_index & (GUINT_BIT_COUNT-1))); 00116 } 00117 }; 00118 00119 00120 00121 00122 00123 #endif // GIM_CONTAINERS_H_INCLUDED