00001 00007 #ifndef BOOL_VECTOR_HH 00008 #define BOOL_VECTOR_HH 00009 00018 namespace my_lib { 00019 00027 class bool_vector_t { 00028 private: 00037 struct bool_handler_t{ 00038 private: 00039 unsigned char * const _byte; 00040 unsigned char _mask; 00041 public: 00042 bool_handler_t(unsigned char position, unsigned char * byte); 00043 operator bool() const; 00044 bool_handler_t& operator=(const bool& b); 00045 }; 00046 00047 unsigned char * _content; //le tableau qui stocke les valeurs 00048 unsigned _size; //la taille apparente du vecteur 00049 unsigned _capacity; //la taille réelle du tableau en octets : _capacity*8 >= _size 00050 00051 public: 00058 bool_vector_t (unsigned size); 00064 ~bool_vector_t (); 00065 00075 bool_handler_t operator[] (unsigned i) ; 00082 const bool_handler_t operator[] (unsigned i) const; 00083 00091 inline 00092 unsigned size() const { 00093 return _size; 00094 } 00095 00107 inline 00108 unsigned capacity() const { 00109 return _capacity*8; 00110 } 00111 00119 void resize(unsigned new_size); 00128 void reserve(unsigned new_capacity); 00129 00130 00135 struct const_iterator{ 00136 protected: 00137 unsigned char* _content; 00138 unsigned _position; 00139 public: 00140 const_iterator(unsigned char* content, unsigned position) : 00141 _position(position) , _content(content) {} 00142 inline 00143 bool operator==(const const_iterator& it) const{ 00144 return _content==it._content && _position==it._position; 00145 } 00146 inline 00147 bool operator!=(const const_iterator& it) const{ 00148 return _content!=it._content || _position!=it._position; 00149 } 00154 inline 00155 const_iterator& operator++() { 00156 ++_position; 00157 return *this; 00158 } 00159 00165 const bool_handler_t operator*(); 00166 }; 00167 00174 struct iterator : public const_iterator{ 00175 public: 00176 iterator(unsigned char* content, unsigned position) : const_iterator(content, position) {} 00177 inline 00178 iterator& operator++() { 00179 ++_position; 00180 return *this; 00181 } 00182 00183 bool_handler_t operator*(); 00184 }; 00185 00190 iterator begin() ; 00191 00196 const_iterator begin() const ; 00197 00202 iterator end() ; 00203 00208 const_iterator end() const ; 00209 }; 00210 00211 00212 00213 } // fin namespace my_lib 00214 00215 00216 #endif //BOOL_VECTOR_HH