/*     Bed a menu-driven multi dataformat binary editor for Linux            */
/*     Copyright (C) 1998 Jaap Korthals Altes <jkaltes@hetnet.nl>       */
/*                                                                           */
/*     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     */
/*     (at your option) 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.             */
/* Fri Dec  8 22:14:27 2000                                                  */
#ifndef BITFIELDS_H
#define BITFIELDS_H
#include "../filter.h"
#include "../screenpart.h"
#include "../hassub.h"
extern char *filtername(Bitfield) ;
typedef short Bitnr;
typedef short Bytenr;
extern int bitcpy(unsigned char *output,unsigned char *input,char bitout,char bitin,int bitnr) ;
class Bitfield: public Filter {
private:
	int maxlen;
	char *convstring;
	public:
	short number;
	int filebits;
	Bitnr *bitnr;
	Bytenr *bytenr;
	char wantsaway;
	int Bitfield::wantaway(void) ;
	Bitfield::Bitfield(int bits,int bytes,ScreenPart *pa);
	Bitfield(int bytes);
	Bitfield(int fb,int sb,char *conv,ScreenPart *pa); 
	Bitfield(Bitfield &rev);
	int Bitfield::extendtolen(int newnumber) ;
	int getbit(int pos);
	int calcsizes(void) ;
	int resizeitem(int it,int size) ;
	int addrange(short beg,short len,short tobytes) ;
	char *convstr(void) ;
	~Bitfield() ;
	virtual Filter *newone(void) ;
	virtual int chbytes(int b) ;
	virtual int chbytesback(int b) ;
	virtual int addposition(int pos,int bytes,int max) ;
	int rmpos(int pos) ;
	int chbitspos(int pos,int bits) ;
	int chbytespos(int pos,int bytes) ;
	virtual int fromfile(unsigned char *input,unsigned char *output) ;
	virtual int tofile(unsigned char *input,unsigned char *output) ;
	int  equal(Filter *fil) ;
	virtual int file2screenpos(int pos) ;
	virtual int screen2filepos(int pos) ;
	};
#endif
