00001 #ifndef BIT_VECTOR_CLASS
00002 #define BIT_VECTOR_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "data_structure_dll.h"
00019
00021
00022 class DATA_STRUCTURE_CLASS_STYLE bit_vector
00023 {
00024 public:
00025 bit_vector();
00027
00028 bit_vector(int size, const byte *initial = NIL);
00030
00034 bit_vector(const bit_vector &to_copy);
00035
00036 ~bit_vector();
00037
00038 bit_vector &operator =(const bit_vector &to_copy);
00039
00040 int bits() const;
00042
00043 bool operator [] (int position) const;
00045
00046 bool on(int position) const;
00048
00049 bool off(int position) const;
00051
00052 void set_bit(int position, bool value);
00054
00055 bool whole() const;
00057
00058 bool empty() const;
00060
00061 int find_first(bool to_find) const;
00063
00066 void light(int position);
00068
00069 void clear(int position);
00071
00072 void resize(int size);
00074
00076 void reset(int size);
00078
00079 bool compare(const bit_vector &that, int start, int stop) const;
00081
00082 bool operator == (const bit_vector &that) const;
00084
00086 bool operator != (const bit_vector &that) const;
00088
00089 istring text_form() const;
00091
00092 bit_vector subvector(int start, int end) const;
00094
00098 bool overwrite(int start, const bit_vector &to_write);
00100
00105 u_int get(int start, int size) const;
00107
00112 bool set(int start, int size, u_int source);
00114
00120 operator const byte_array &() const;
00122
00124 private:
00125 byte_array *_implementation;
00126 int _number_of_bits;
00127
00128 struct two_dim_location { int byte; int offset; };
00130
00131 two_dim_location into_two_dim(int position) const;
00134 bool get_bit(const two_dim_location &pos_in2) const;
00136 void set_bit(const two_dim_location &pos_in2, bool value);
00138 };
00139
00141
00142
00143
00145 template <class type>
00146 void SET(type &to_modify, type bits) { to_modify |= bits; }
00147
00149 template <class type>
00150 void CLEAR(type &to_modify, type bits) { to_modify &= (type)~bits; }
00151
00153 template <class type>
00154 bool TEST(type to_test, type bits) { return bool(!(!(to_test & bits))); }
00155
00157
00158 #endif
00159