00001
00002
00003
00004
00005
00006
00007
00008
00009
00014
00015 #ifndef BITREADERS_HPP_INCLUDED
00016 #define BITREADERS_HPP_INCLUDED
00017
00018 #include <iostream>
00019 #include <vector>
00020 #include <string>
00021
00022 #include "bitreader.hpp"
00023
00026
00029 class null_bitreader : public bitreader {
00030
00031 public:
00034 null_bitreader(size_t size_in_bits=0) : bitreader(size_in_bits) { ; }
00035
00036 ~null_bitreader() { finalize(); }
00037
00038 bool supports_seek() const { return false; }
00039
00040 protected:
00041 char read_next_byte() { return 0; }
00042 };
00043
00045 class stream_bitreader : public bitreader {
00046
00047 public:
00051 stream_bitreader(std::istream &_s, size_t size_in_bits=0)
00052 : bitreader(size_in_bits), s(_s) { ; }
00053
00054 ~stream_bitreader() { finalize(); }
00055
00056 bool supports_seek() const { return false; }
00057
00058 protected:
00059 char read_next_byte() { char c; s.get(c); return c; }
00060
00061 std::istream &s;
00062 };
00063
00065 class vector_bitreader : public bitreader {
00066
00067 public:
00071 vector_bitreader(const std::vector<char> &_s)
00072 : bitreader(8 * _s.size()), s(_s), index(0) { ; }
00076 vector_bitreader(const std::vector<char> &_s, size_t size_in_bits)
00077 : bitreader(size_in_bits), s(_s), index(0) { ; }
00078
00079 ~vector_bitreader() { finalize(); }
00080
00081 bool supports_seek() const { return true; }
00082
00083 protected:
00084
00085 char read_next_byte() { return s[index++]; }
00086 void set_position(size_t pos) { index = pos; }
00087
00088 const std::vector<char> &s;
00089 size_t index;
00090 };
00091
00093 class string_bitreader : public bitreader {
00094
00095 public:
00099 string_bitreader(const std::string &_s)
00100 : bitreader(8 * _s.size()), s(_s), index(0)
00101 { ; }
00105 string_bitreader(const std::string &_s, size_t size_in_bits)
00106 : bitreader(size_in_bits), s(_s), index(0) { ; }
00107
00108 ~string_bitreader() { finalize(); }
00109
00110 bool supports_seek() const { return true; }
00111
00112 protected:
00113
00114 char read_next_byte() { return s[index++]; }
00115 void set_position(size_t pos) { index = pos; }
00116
00117 const std::string &s;
00118 size_t index;
00119 };
00120
00122 class array_bitreader : public bitreader {
00123
00124 public:
00128 array_bitreader(const char *_s, size_t size_in_bits)
00129 : bitreader(size_in_bits), s(_s), index(0) { ; }
00130
00131 ~array_bitreader() { finalize(); }
00132
00133 bool supports_seek() const { return true; }
00134
00135 protected:
00136 char read_next_byte() { return s[index++]; }
00137 void set_position(size_t pos) { index = pos; }
00138
00139 const char *s;
00140 size_t index;
00141 };
00142
00144
00145 #endif // BITREADERS_HPP_INCLUDED