/****************************************************************************
	Kalkulon - A programmable calculator for programmers

	This file is part of the Kalkulon core.
	
	If you find this source code useful, your are encouraged to use it in your own projects.
	Please give me credit!

	COPYRIGHT by Juergen Holetzeck 2003 - 2008
	e-mail:		contact@kalkulon.de
	homepage:	www.kalkulon.de
****************************************************************************/


// ErrBase.h: interface for the ErrBase class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_ERRBASE_H__6ED41F56_4009_11D7_B2CA_00300511F21B__INCLUDED_)
#define AFX_ERRBASE_H__6ED41F56_4009_11D7_B2CA_00300511F21B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

namespace Kalkulon{
/////////////////////////////////////////////////////////////////////
// base types of exceptions: use one of these as simple interface (-> GetErrorMessage)
// use specific types (see below) for own error messages

static const size_t strbuf_size = 255;

struct ErrBase
{
	Token tok;
	char strbuf[strbuf_size+1];	//string buffer for GetErrorMessage text

	ErrBase(Token &t) {tok = t; strbuf[0]=0; strbuf[strbuf_size]=0; /* be sure that strbuf is always null terminated */}
	ErrBase() {strbuf[0]=0; strbuf[strbuf_size]=0; /* be sure that strbuf is always null terminated */}
	virtual ~ErrBase() {}

	virtual const char* GetErrorMessage() {return strbuf;}
};


/////////////////////////////////////////////////////////////////////
// types of ArithParser exceptions
struct ErrWrongToken:public ErrBase
{
	ErrWrongToken(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};


struct ErrPrimExpr:public ErrBase
{
	ErrPrimExpr(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};


struct ErrLPExpr:public ErrBase
{
	ErrLPExpr(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};


struct ErrRPExpr:public ErrBase
{
	ErrRPExpr(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};


struct ErrRCBExpr:public ErrBase
{
	ErrRCBExpr(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};


struct ErrRBExpr:public ErrBase
{
	ErrRBExpr(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};


struct ErrRQExpr:public ErrBase
{
	ErrRQExpr(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};


struct ErrStatement:public ErrBase
{
	ErrStatement(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};


struct ErrENDExpr:public ErrBase
{
	ErrENDExpr(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};


struct ErrIdExpected:public ErrBase
{
	ErrIdExpected(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};

/////////////////////////////////////////////////////////////////////
// types of RPNEval exceptions
struct ErrNumOfArg:public ErrBase
{
	ErrNumOfArg(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};

struct ErrUndefSym:public ErrBase
{
	ErrUndefSym(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};

struct ErrUnknFunc:public ErrBase
{
	ErrUnknFunc(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};

struct ErrWrongDef:public ErrBase
{
	ErrWrongDef(Token &t):ErrBase(t) {}
	virtual const char* GetErrorMessage();
};

struct ErrMath:public ErrBase
{
	std::string reason;

  ErrMath(Token &t, std::string r):ErrBase(t) {reason=r;}
	virtual const char* GetErrorMessage();
};

struct ErrUserDef:public ErrBase
{
	std::string reason;

  ErrUserDef(std::string r):ErrBase() {reason=r;}
	virtual const char* GetErrorMessage();
};

struct ErrInDefFunc:public ErrBase
{
	std::string err_str;
	std::string fn;

  ErrInDefFunc(std::string fn_, const char *err_str_):ErrBase() {fn=fn_; err_str=err_str_;}
	virtual const char* GetErrorMessage();
};


/////////////////////////////////////////////////////////////////////
// internal error, should never occur
struct ErrInternal:public ErrBase
{
	std::string module;
	int line;

	ErrInternal(int l, std::string m):ErrBase() {line=l; module=m;}
	virtual const char* GetErrorMessage();
};

/////////////////////////////////////////////////////////////////////
// break by user
struct ErrBreakSig:public ErrBase
{
	virtual const char* GetErrorMessage();
};

}

#endif // !defined(AFX_ERRBASE_H__6ED41F56_4009_11D7_B2CA_00300511F21B__INCLUDED_)
