My Project
Bitset.h
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #ifndef BITSET_H
25 #define BITSET_H
26 
33 #include "Alvar.h"
34 
35 #include <deque>
36 #include <iomanip>
37 #include <iostream>
38 #include <sstream>
39 #include <string>
40 
41 namespace alvar {
42 
63 class ALVAR_EXPORT Bitset
64 {
65 protected:
66  std::deque<bool> bits;
67 
68 public:
70  int Length();
74  std::ostream &Output(std::ostream &os) const;
76  void clear();
80  void push_back(const bool bit);
85  void push_back(const unsigned char b, const int bit_count = 8);
90  void push_back(const unsigned short s, const int bit_count = 16);
95  void push_back(const unsigned long l, const int bit_count = 32);
99  void push_back_meaningful(const unsigned long l);
103  void fill_zeros_left(const size_t bit_count);
107  void push_back(std::string s);
109  bool pop_front();
111  bool pop_back();
115  void flip(size_t pos);
117  std::string hex();
119  unsigned long ulong();
121  unsigned char uchar();
123  inline std::deque<bool> &
125  {
126  return bits;
127  }
128 };
129 
138 class ALVAR_EXPORT BitsetExt : public Bitset
139 {
140 protected:
141  bool verbose;
142  void hamming_enc_block(unsigned long block_len, std::deque<bool>::iterator &iter);
143  int hamming_dec_block(unsigned long block_len, std::deque<bool>::iterator &iter);
144 
145 public:
149  BitsetExt(bool _verbose);
151  void SetVerbose(bool _verbose);
153  static int count_hamming_enc_len(int block_len, int dec_len);
155  static int count_hamming_dec_len(int block_len, int enc_len);
157  void hamming_enc(int block_len);
159  int hamming_dec(int block_len);
160 };
161 
162 } // namespace alvar
163 
164 #endif
This file defines library export definitions, version numbers and build information.
An extended Bitset ( BitsetExt ) for handling e.g. Hamming encoding/decoding.
Definition: Bitset.h:139
BitsetExt(bool _verbose)
Constructor.
int hamming_dec(int block_len)
Hamming decoding 'in-place' using the defined block length.
void SetVerbose(bool _verbose)
Set the verbose/silent mode.
static int count_hamming_dec_len(int block_len, int enc_len)
Count how many bits will be in the Bitset after hamming decoding.
static int count_hamming_enc_len(int block_len, int dec_len)
Count how many bits will be in the Bitset after hamming encoding.
BitsetExt()
Constructor.
void hamming_enc(int block_len)
Hamming encoding 'in-place' using the defined block length.
Bitset is a basic class for handling bit sequences
Definition: Bitset.h:64
void flip(size_t pos)
Flip the selected bit.
bool pop_front()
Pop the front bit.
unsigned char uchar()
The Bitset as 'unsigned char'.
void push_back_meaningful(const unsigned long l)
Push back meaningful bits from 'long' l.
void push_back(const unsigned long l, const int bit_count=32)
Push back bit_count bits from 'long' l.
void fill_zeros_left(const size_t bit_count)
Fill the Bitset with non-meaningful zeros.
std::deque< bool > & GetBits()
The Bitset as 'deque<bool>'.
Definition: Bitset.h:124
void clear()
Clear the bits.
bool pop_back()
Pop the back bit.
std::string hex()
The Bitset as a hex string.
int Length()
The length of the Bitset.
unsigned long ulong()
The Bitset as 'unsigned long'.
void push_back(const bool bit)
Push back one bit.
void push_back(const unsigned char b, const int bit_count=8)
Push back bit_count bits from 'byte' b.
std::ostream & Output(std::ostream &os) const
Output the bits to selected ostream.
void push_back(std::string s)
Push back a string of characters.
void push_back(const unsigned short s, const int bit_count=16)
Push back bit_count bits from 'short' s.
Main ALVAR namespace.
Definition: Alvar.h:174