/* ************* BSTREAM.H Bitstream file i/o class *********** * * ****************** By Alexis 'Milamber' Ashley *************** * * * Copyright (C) 1995 Alexis Ashley milamber@dcs.warwick.ac.uk This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef __BSTREAM__ #define __BSTREAM__ #include #include #include "typedefs.H" class ibstream : public virtual ifstream { public: ibstream(void) { _is_open = false; } ~ibstream(void) { } void open(const char *name, int mode=(ios::in | ios::nocreate), int prot=0664); void close(void) { _is_open=false; ifstream::close(); } int is_open(void) const { return _is_open; } ibstream& BitRead(long &val, int bits); ibstream& read(char *buff, int count) { assert(buff!=NULL); assert(_is_open); ifstream::read(buff,count); reset_count(); return *this; } ibstream& read(unsigned char *buff, int count) { assert(buff!=NULL); assert(_is_open); ifstream::read(buff,count); reset_count(); return *this; } ibstream& read(void *buff, int count) { assert(buff!=NULL); assert(_is_open); ifstream::read(buff,count); reset_count(); return *this; } ibstream& FlushRead(void); ibstream& seekg(streampos); ibstream& seekg(streamoff,seek_dir); ibstream& BitSeekg(long pos, int bitpos); protected: void reset_count(void) { power=0; val=0; } private: bool _is_open; int power; unsigned char val; }; class obstream : public virtual ofstream { public: obstream(void) { _is_open = false; } ~obstream(void) { } void open(const char *name, int mode=ios::out, int prot=0664); void close(void) { _is_open=false; ofstream::close(); } obstream& BitWrite(long val, int bits); obstream& write(char *buff, int count) { assert(buff!=NULL); assert(_is_open); if(power!=128) FlushWrite(); ofstream::write(buff,count); reset_count(); return *this; } obstream& write(unsigned char *buff, int count) { assert(buff!=NULL); assert(_is_open); if(power!=128) FlushWrite(); ofstream::write(buff,count); reset_count(); return *this; } obstream& write(void *buff, int count) { assert(buff!=NULL); assert(_is_open); if(power!=128) FlushWrite(); ofstream::write(buff,count); reset_count(); return *this; } obstream& FlushWrite(void); obstream& seekp(streampos); obstream& seekp(streamoff, seek_dir); protected: void reset_count(void) { power=128; val=0; } private: bool _is_open; int power; unsigned char val; }; class bstream : public ibstream, obstream { public: bstream(void) { } ~bstream(void) { } void open(const char *name, int mode, int prot=0664); private: }; #endif