#ifndef AVIFILE_EXCEPT_H
#define AVIFILE_EXCEPT_H

/********************************************************

	Exception object
	Copyright 2000 Eugene Kuznetsov  (divx@euro.ru)

*********************************************************/

/**
 *
 *   The idea is to use error codes for non-fatal problems
 * ( for example, problem in decompressing one frame is not fatal
 * for video decoder ) and exceptions for problems which leave
 * object in unusable state. GenError is an intermediate case.
 *
 */
#include <stdarg.h>
class BaseError
{
    char* module;
    char* description;
    const char* file;
    char* severity;
    int line;
public:
    ~BaseError();
    BaseError();
    BaseError(const BaseError& f);
    void Init(const char* sev, const char* mod, const char* f, int l, const char* desc, va_list va);
    void Print();
    void PrintAll();
    const char* GetModule() const;
    const char* GetDesc() const;
};

class FatalError: public BaseError
{
public:
    FatalError(const char* mod, const char* f, int l, const char* desc,...)
    {
	va_list va;
	va_start(va, desc);
	Init("FATAL", mod, f, l, desc, va);
	va_end(va);
    }
    FatalError(const FatalError& f):BaseError(f){}
};

class GenError: public BaseError
{
public:
    GenError(const char* mod, const char* f, int l, const char* desc,...)
    {
    	va_list va;
	va_start(va, desc);
	Init("WARNING", mod, f, l, desc, va);
	va_end(va);
    }
    GenError(const GenError& f):BaseError(f){}
};

#define FATAL(X...) FatalError(__MODULE__,__FILE__,__LINE__,X)
#define WARNING(X...) GenError(__ERR_MODULE__,__FILE__,__LINE__,X)
#define MEMORY_FATAL FATAL("Out of memory")
/*
class Unsigned
{
    int i;
public:
    Unsigned(){}
    Unsigned(const Unsigned& ref):i(ref.i)
    {
	if(i<0)
	    throw FatalError("Unsigned value", "Range error", __FILE__, __LINE__);
    }
    Unsigned(int ref):i(ref)
    {
	if(i<0)
	    throw FatalError("Unsigned value", "Range error", __FILE__, __LINE__);
    }
    operator unsigned() const {return (unsigned)i;}
    bool operator<(const Unsigned& e) const {return i<e.i;}
    bool operator<(int e) const {return i<e;}
    bool operator<(unsigned e) const {return i<e;}
    Unsigned& operator++(int){i++;return *this;}
    Unsigned& operator++(){i++;return *this;}
    Unsigned operator-(const Unsigned& e) const 
    {
	return Unsigned(i-e.i);
    }	
    Unsigned operator-(int e) const 
    {
	return Unsigned(i-e);
    }	
    Unsigned operator+(const Unsigned& e) const 
    {
	return Unsigned(i+e.i);
    }	
    Unsigned& operator+=(const Unsigned& e)
    {
	i+=e.i;
	return *this;
    }
    Unsigned& operator-=(const Unsigned& e)
    {
	i-=e.i;
	if(i<0)
	    throw FatalError("Unsigned value", "Range error", __FILE__, __LINE__);
	return *this;
    }
//    operator int(){return i;}
//    unsigned& operator=(const unsigned& ref){i=ref; return *this;}
};
*/

#endif // AVIFILE_EXCEPT_H
