/*     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 FILTER_H
#define FILTER_H


class ScreenPart;
class Filter {
	public:
	ScreenPart *part;
	char *label,*name;
	int bytesscreen; //bytes screen side
	int bytesfile; //bytes file side
	int err; /*set on error */
	Filter(int fb,int sb) ;

	Filter(Filter &fil) ;
	virtual int setpart(ScreenPart *p);
	virtual char *convstr(void);
	virtual int error(void) ;
	virtual int chbytes(int bytes)=0; //set sized with bytes on fileside given, returns bytes on screen side
	virtual int chbytesback(int bytes)=0; //set sized with bytes on screen side given, returns bytes on file side
	virtual Filter *newone(void)=0;
	virtual ~Filter();
	virtual int fromfile(unsigned char *input,int &len,unsigned char *output) {
		return fromfile(input,output);
		};
	virtual int tofile(unsigned char *input,int &len,unsigned char *output) {
		return tofile(input,output) ;
		};
	virtual int fromfile(unsigned char *input,unsigned char *output){
		return 0;
		};
	virtual int tofile(unsigned char *input,unsigned char *output) {
		return 0;
		}
	virtual int  equal(Filter *fil);
	virtual int  wantaway(void) {return 1;}
	virtual int screen2filepos(int pos) ;
	virtual int file2screenpos(int pos) ;
	};
extern int filtersmaxlen,filtersnr;
extern char **filtersnames;
extern Filter *(**filtersfuncs)(int,int,char*,ScreenPart *) ;
extern char *initfilter(char *str, Filter *(*func)(int,int,char *,ScreenPart*)) ;
extern Filter *(*getfilterfunc(char *name,int len)) (int,int,char *,ScreenPart *) ;

#define filtername(filtername) filtername##name
#define registerfilterclass(filtername) \
	Filter *get##filtername(int fb,int sb,char *opts,ScreenPart *part=NULL) {\
		return new filtername(fb,sb,opts);\
		}\
	char *filtername##name= initfilter(#filtername,&get##filtername);

#define registerfilterclasspart(filtername) \
	Filter *get##filtername(int fb,int sb,char *opts,ScreenPart *part=NULL) {\
		return new filtername(fb,sb,opts,part);\
		}\
	char *filtername##name= initfilter(#filtername,&get##filtername);
#endif
