#ifndef DECODER_H #define DECODER_H #include #include #include #include class Source { public: virtual std::streamsize read(char* buf, std::streamsize buf_size) = 0; }; template class StreamSource : public Source { private: T& s; public: StreamSource(T& s_) : s(s_) {} std::streamsize read(char* buf, std::streamsize buf_size) { return boost::iostreams::read(s, buf, buf_size); } }; class DecoderBase { public: typedef boost::shared_ptr p; virtual ~DecoderBase() {} virtual size_t decode(Source& input, uint8_t *output, size_t output_size) = 0; }; //! Input filter to hold a decoder in a filter chain. class DecoderFilter : public boost::iostreams::multichar_input_filter { private: DecoderBase::p decoder; public: typedef boost::shared_ptr p; DecoderFilter(DecoderBase::p decoder_); template std::streamsize read(Source& src, char *s, std::streamsize n) { StreamSource src_f(src); return decoder->decode(src_f, (uint8_t*)s, n); } }; namespace decoder { void init(); DecoderFilter::p get_decoder(const std::string& name); }; #endif