//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project
//
//File: exception.h
//
//State: $State: Exp $
//
//Version: $Revision: 1.15 $
//
//Date: $Date: 1998/10/05 07:24:27 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
// 
//Authors:
//      Jari Pusa
//
//Description:
//       This file includes several exception classes and the base
//       class for exceptions.
//
//Copyright:    
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//
//      
//Licence:
//     
//
//History:
//
//

#ifndef __PF_EXCEPTION_H__
#define __PF_EXCEPTION_H__

#include <typeinfo>
#include <string>
#include "types.h"

// PF_EX_INFO macro tells exception constructors their call position.

#define PF_EX_INFO __FILE__, __LINE__

//
// Class: pfException
//
// Description:
//      Ancestor of all exception classes. It provides two
//      methods: getName and printInfo. The further returns the
//      name of the class and latter prints (using debug)
//      some information about the occurence.
//

class pfException
{
    public:
        pfException(const pfException &other_);
        explicit pfException(pfUlong cause_);
        pfException(string file_, int line_);
        virtual ~pfException(void);

        virtual pfUlong getCause(void) const;
        virtual string getName(void) const;
        virtual void printInfo(void) const;
        
    private:
	pfException &operator=(const pfException &other_);
        pfUlong _cause;
        int _line;
        string _file;
};

//
// Class: pfInvalidTypeException
//
// Description:
//      This exception should be thrown whenever a wrong
//      type parameter is encountered.
//

class pfInvalidTypeException : public pfException
{
    public:
        pfInvalidTypeException(const pfInvalidTypeException &other_);
        pfInvalidTypeException(string file_, int line_);
        pfInvalidTypeException(string name_, int triedType_, int validType,
			       string file_, int line_);
        virtual ~pfInvalidTypeException(void);

        virtual string getName(void) const;
        virtual void printInfo(void) const;

    private:
        string _name;
        int _triedType;
        int _validType;
};

//
// Class: pfNameAlreadyDefinedException
//
// Description:
//      This exception should be thrown whenever a unique
//      named variable is tried to allocate twice.
//

class pfNameAlreadyDefinedException : public pfException
{
    public:
        pfNameAlreadyDefinedException(
            const pfNameAlreadyDefinedException &other_);
        pfNameAlreadyDefinedException(string file_, int line_);
        pfNameAlreadyDefinedException(string name_,
                                      string file_, int line_);
        virtual ~pfNameAlreadyDefinedException(void);

        virtual string getName(void) const;
        virtual void printInfo(void) const;
        
    private:
        string _name;
};

//
// Class: pfNameUndefinedException
//
// Description:
//      This exception should be thrown whenever a name
//      for a variable is not defined when requested.
//

class pfNameUndefinedException : public pfException
{
    public:
        pfNameUndefinedException(const pfNameUndefinedException &other_);
        pfNameUndefinedException(string file_, int line_);
        pfNameUndefinedException(string name_,
                                 string file_, int line_);
        virtual ~pfNameUndefinedException(void);

        virtual string getName(void) const;
        virtual void printInfo(void) const;

    private:
        string _name;
};

//
// Class: pfOutOfRangeException
//
// Description:
//      This exception should be thrown whenever e.g. an index
//      operator (operator[]) is called with an illegal value.
//

class pfOutOfRangeException : public pfException
{
    public:
        pfOutOfRangeException(const pfOutOfRangeException &other_);
        pfOutOfRangeException(string file_, int line_);
        pfOutOfRangeException(pfLong index_,
                              pfLong rangeMin_,
                              pfLong rangeMax_,
			      string file_,
                              int line_);
        virtual ~pfOutOfRangeException(void);
        
        virtual string getName(void) const;
        virtual void printInfo(void) const;

    private:
        pfLong _index;
        pfLong _rangeMin;
        pfLong _rangeMax;
};

//
// Class: pfOutOfRangeException
//
// Description:
//      This exception should be thrown whenever e.g. an index
//      operator (operator[]) is called with an illegal value.
//

class pfBadValue : public pfException
{
    public:
        pfBadValue(const pfBadValue &other_);
        pfBadValue(string file_, int line_);
        pfBadValue(pfLong value,
                   pfLong valueMin_,
                   pfLong valueMax_,
		   string file_,
                   int line_);
        virtual ~pfBadValue(void);
        
        virtual string getName(void) const;
        virtual void printInfo(void) const;

    private:
        pfLong _value;
        pfLong _valueMin;
        pfLong _valueMax;
};

//
// Class: pfMemoryAllocationException
//
// Description:
//      This exception should be thrown whenever
//      memory allocation fails,
//      for example in methods such as instance, clone, constructors
//

class pfMemoryAllocationException : public pfException
{
    public:
        pfMemoryAllocationException(const pfMemoryAllocationException &other_);
        pfMemoryAllocationException(string file_, int line_, int size_);

        virtual ~pfMemoryAllocationException(void);

        virtual string getName(void) const;
        virtual void printInfo(void) const;

    private:
        int _size;
};

//
// Class: pfNullPointerException
//
// Description:
//      This exception should be thrown whenever
//      null is about to be referenced,
//      i.e. instead of the following code, if (pointer != 0) {...}.
//

class pfNullPointerException : public pfException
{
    public:
        pfNullPointerException(const pfNullPointerException &other_);
        pfNullPointerException(string file_, int line_);

        virtual ~pfNullPointerException(void);

        virtual string getName(void) const;
        virtual void printInfo(void) const;
};

//
// Class: pfNotConnectedException
//
// Description:
//      This exception should be thrown whenever
//      messages send to destination that does not exist,
//      i.e. in toA method when A-side is not connected.
//

class pfNotConnectedException : public pfException
{
    public:
        pfNotConnectedException(const pfNotConnectedException &other_);
        pfNotConnectedException(string file_, int line_);

        virtual ~pfNotConnectedException(void);

        virtual string getName(void) const;
        virtual void printInfo(void) const;
};

//
// Class: pfMethodFailed
//
// Description:
//      This exception should be thrown whenever
//      method call fails. Critical execption e.g.
//      can be used instead of exit(error code).
//

class pfMethodFailed : public pfException
{
    public:
        pfMethodFailed(const pfMethodFailed &other_);
        pfMethodFailed(string cause_, string file_, int line_);

        virtual ~pfMethodFailed(void);

        virtual string getName(void) const;
        virtual void printInfo(void) const;

    private:
        string _cause;
};

#endif // __PF_EXCEPTION_H__

