/*This is the file Error.h.  It contains Exception handling classes similar to
those that were covered in lecture.  You must have this file to use Matrix.h or
Eigen.h.*/

#ifndef Error_H
#define Error_H

#include <iostream.h>
#include <string.h>

/*The Exception class is the base class of the error handling structure.  This
class is exactly the same as the Exception class that was covered in lecture.*/

class Exception
{
public:
	Exception(char* pMsg, char* pFile, int nLine)
	{
	   strcpy (msg, pMsg);
	   msg[sizeof(msg)-1]='\0';
	   strcpy (file, pFile);
	   file [sizeof(file)-1]='\0';
	   lineNum=nLine;
	}
	
	virtual void display(ostream& out)
	{
	    out << "Error: "<<msg<<endl;
	    out << "Occured on line number "<<lineNum<<", file"<<endl;
	}
	
protected:
    //error message
    char msg[80];

    //file name and line number where error occured
    char file[80];
    int lineNum;
};

/*The InvalidSizes class is a daughter class of the Exception class.  It will
handle errors due to array size mismatch with arithmetic.  For example if you
multiply two matrices a and b, a.num_rows must equal b.num_cols.*/

class InvalidSizes:public Exception
{
public:
    InvalidSizes (char* arg1, char* arg2, char* pFile, int nLine):
        Exception ("Invalid size matching", pFile, nLine)
        {
            strcpy (size1, arg1);
	        size1[sizeof(size1)-1]='\0';
	        strcpy (size2, arg2);
	        size2[sizeof(size2)-1]='\0';
       }

        virtual void display (ostream& out)
        {
            Exception::display(out);
            out << size1 << "!=" <<size2<<endl;
        }

protected:
        char size1[80];
        char size2[80];
};

/*The InvalidRange class is a daughter class of the Exception class.  It
handles errors of requesting some array element that does not actually exist.*/

class InvalidRange:public Exception
{
public:
    InvalidRange (int arg, char* pFile, int nLine):
        Exception ("Invalid element request: element ", pFile, nLine)
        {
            element = arg;
        }

       int elem()
        {return element;}

       virtual void display (ostream& out)
        {
            Exception::display(out);
            out << element << "not part of array"<<endl;
        }

protected:
        int element;
};

#endif