Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef BITSET_H
00025 #define BITSET_H
00026
00033 #include "Alvar.h"
00034 #include <iostream>
00035 #include <deque>
00036 #include <string>
00037 #include <sstream>
00038 #include <iomanip>
00039
00040 namespace alvar {
00041
00062 class ALVAR_EXPORT Bitset {
00063 protected:
00064 std::deque<bool> bits;
00065
00066 public:
00068 int Length();
00072 std::ostream &Output(std::ostream &os) const;
00074 void clear();
00078 void push_back(const bool bit);
00083 void push_back(const unsigned char b, const int bit_count=8);
00088 void push_back(const unsigned short s, const int bit_count=16);
00093 void push_back(const unsigned long l, const int bit_count=32);
00097 void push_back_meaningful(const unsigned long l);
00101 void fill_zeros_left(const size_t bit_count);
00105 void push_back(std::string s);
00107 bool pop_front();
00109 bool pop_back();
00113 void flip(size_t pos);
00115 std::string hex();
00117 unsigned long ulong();
00119 unsigned char uchar();
00121 inline std::deque<bool>& GetBits()
00122 {
00123 return bits;
00124 }
00125 };
00126
00135 class ALVAR_EXPORT BitsetExt : public Bitset {
00136 protected:
00137 bool verbose;
00138 void hamming_enc_block(unsigned long block_len, std::deque<bool>::iterator &iter);
00139 int hamming_dec_block(unsigned long block_len, std::deque<bool>::iterator &iter);
00140 public:
00142 BitsetExt();
00144 BitsetExt(bool _verbose);
00146 void SetVerbose(bool _verbose);
00148 static int count_hamming_enc_len(int block_len, int dec_len);
00150 static int count_hamming_dec_len(int block_len, int enc_len);
00152 void hamming_enc(int block_len);
00154 int hamming_dec(int block_len);
00155 };
00156
00157 }
00158
00159 #endif