00001 /*00002 * The Software License00003 * =================================================================================00004 * Copyright (c) 2003-.The Terimber Corporation. All rights reserved.00005 * =================================================================================00006 * Redistributions of source code must retain the above copyright notice, 00007 * this list of conditions and the following disclaimer.00008 * Redistributions in binary form must reproduce the above copyright notice, 00009 * this list of conditions and the following disclaimer in the documentation 00010 * and/or other materials provided with the distribution.00011 * The end-user documentation included with the redistribution, if any, 00012 * must include the following acknowledgment:00013 * "This product includes software developed by the Terimber Corporation."00014 * =================================================================================00015 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, 00016 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00017 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00018 * IN NO EVENT SHALL THE TERIMBER CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR 00019 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00020 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00021 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00022 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT00023 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE00024 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.00025 * ================================================================================00026 */00027
00028 #ifndef _terimber_bitset_h_00029 #define _terimber_bitset_h_00030
00031 #include "base/vector.h"00032
00033 BEGIN_TERIMBER_NAMESPACE00034 #pragma pack(4)00035
00038class base_bitset00039 {
00041enumen_bitset00042 {
00043bs_bits_in_byte = 8,
00044bs_offset = 3,
00045bs_mask = bs_bits_in_byte - 1
00046 };
00047
00048 public:
00049
00051 inline00052 bool00053 set( size_t index,
00054 bool value
00055 );
00057 inline00058 bool00059 get( size_t index
00060 ) const;
00062 inline00063 bool00064 find_first_free(size_t& index
00065 ) const;
00066
00068 inline00069 bool00070 empty() const;
00072 inline00073 bool00074 operator==(constbase_bitset& x) const;
00076 inline00077 bool00078 operator!=(constbase_bitset& x) const;
00080 inline00081 base_bitset&
00082 operator|=(constbase_bitset& x);
00084 inline00085 base_bitset&
00086 operator&=(constbase_bitset& x);
00088 inline00089 void00090 reset();
00092 inline00093 booloperator<(constbase_bitset& x) const;
00094
00095 protected:
00097 inline00098 base_bitset( size_t capacity
00099 );
00101 static00102 inline00103 size_t00104 get_byte_len( size_t bitlen
00105 );
00107 static00108 inline00109 size_t00110 offset( size_t index
00111 );
00113 static00114 inline00115 unsignedchar00116 mask( size_t index
00117 );
00118
00119 protected:
00120size_t_capacity;
00121unsignedchar* _bits;
00122 };
00123
00126class _bitset : publicbase_bitset00127 {
00128 public:
00130 inline00131 _bitset();
00133 inline00134 _bitset( TERIMBER::byte_allocator& all,
00135 size_t capacity
00136 );
00138 inline00139 _bitset&
00140 operator=(const_bitset& x);
00142 inline00143 _bitset&
00144 assign( byte_allocator& all,
00145 const_bitset& x
00146 );
00148 inline00149 _bitset&
00150 resize( byte_allocator& all,
00151 size_t capacity
00152 );
00154 inline00155 void00156 clear();
00157 };
00158
00160class bitset : publicbase_bitset00161 {
00162 public:
00164 inline00165 bitset();
00166
00168 inline00169 bitset( size_t capacity
00170 );
00172 inline00173 ~bitset();
00175 inline00176 bitset& operator=(constbitset& x);
00177 inline00179 bitset&
00180 resize( size_t capacity
00181 );
00183 inline00184 void00185 clear();
00186 };
00187
00188
00189 #pragma pack()00190 END_TERIMBER_NAMESPACE00191
00192 #endif // _terimber_stack_h_00193