#ifndef _BITSTREAM_H_ #define _BITSTREAM_H_ #pragma warning (disable: 4786) #include #include using namespace std; // ibstream class interface: Bit-input stream wrapper class // // CONSTRUCTION: with an open istream // // ******************PUBLIC OPERATIONS*********************** // int readBit( ) --> Read one bit as a 0 or 1 // istream & getInputStream( ) --> Return underlying stream // ******************ERRORS********************************** // Error checking can be done on result of getInputStream( ) class ibstream { public: ibstream( istream & is ); int readBit( ); istream & getInputStream( ) const; private: istream & in; // The underlying input stream char buffer; // Buffer to store eight bits at a time int bufferPos; // Position in buffer for next read }; // obstream class interface: Bit-output stream wrapper class // // CONSTRUCTION: with an open ostream // // ******************PUBLIC OPERATIONS*********************** // void writeBit( val ) --> Write one bit (0 or 1) // void writeBits( val ) --> Write a vector of bits // void flush( ) --> Flush buffered bits // ostream & getOutputStream( ) --> Return underlying stream // ******************ERRORS********************************** // Error checking can be done on result of getOutputStream( ) class obstream { public: obstream( ostream & os ); ~obstream( ); void writeBit( int val ); void writeBits( const vector & val ); ostream & getOutputStream( ) const; void flush( ); private: ostream & out; // The underlying output stream char buffer; // Buffer to store eight bits at a time int bufferPos; // Position in buffer for next write }; #endif