#ifndef __CP_Tran_h
#define __CP_Tran_h

#include "common.h"
#ifndef WORD
 #include "typedfs.h"
#endif

/// Parent codepage translator that maintains list of translators.
class CpTranslator
	{
private:static CpTranslator *First;
	CpTranslator *Previous;
	CpTranslator *Next;

public: explicit CpTranslator(const char *name);
	~CpTranslator();

	const char *Name;

	virtual WORD operator[](const WORD n) const {return(n);}
	virtual WORD number(void) const {return(0);}
        static CpTranslator *getFirst(void) {return(First);};
        CpTranslator *getNext(void) {return(Next);};

	friend CpTranslator *GetTranslator(const char *Name);
	};
CpTranslator *GetTranslator(const char *Name);	


/// Codepage translator that converts to wchar.
class WCpTranslator: public CpTranslator
	{
public: WCpTranslator(const char *name, WORD number, const WORD *trn);

	WORD Number;
	const WORD *Trn;

	WORD operator[](const WORD n) const {if(n>=Number) return(n); return(Trn[n]);}
	WORD number(void) const {return(Number);}
	};


/// Codepage translator that converts to 8bit char.
class BCpTranslator: public CpTranslator
	{
public: BCpTranslator(const char *name, WORD number, const BYTE *trn);

	WORD Number;
	const BYTE *Trn;

	WORD operator[](const WORD n) const {if(n>=Number) return(n); return(Trn[n]);}
	WORD number(void) const {return(Number);}

	};        

/// Codepage translator that converts to wchar where the space is not contiguous.
class SparseCpTranslator: public CpTranslator
	{
public: SparseCpTranslator(const char *name, BYTE banks, const WORD *const *trn_bank);

	BYTE Banks;
	const WORD * const* Trn_bank;

	WORD operator[](const WORD n) const;
	WORD number(void) const {return(256*Banks);}
	};


#endif