00001
00002
00003
00004
00005
00006
00007
00008
00009
00014
00015 #ifndef FILE_BITREADER_HPP_INCLUDED
00016 #define FILE_BITREADER_HPP_INCLUDED
00017
00018 #include <fstream>
00019
00020 #include "bitreader.hpp"
00021
00033 class file_bitreader : public bitreader {
00034
00035 public:
00039 file_bitreader(const char *name)
00040 : s(name, std::ios::binary)
00041 {
00042 if (s)
00043 {
00044 length = 8 * s.seekg(0, std::ios::end).tellg();
00045 s.seekg(0);
00046 }
00047 }
00051 file_bitreader(const char *name, size_t size_in_bits)
00052 : bitreader(size_in_bits), s(name, std::ios::binary) { ; }
00053
00054 ~file_bitreader() { finalize(); }
00055
00058 bool error() const { return !s; }
00059
00060 bool supports_seek() const { return true; }
00061
00062 protected:
00063 char read_next_byte() { char c; s.get(c); return c; }
00064 void set_position(size_t pos) { s.seekg((std::streamoff)pos); }
00065
00066 std::ifstream s;
00067 };
00068
00069 #endif // FILE_BITREADER_HPP_INCLUDED