//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project
//
//File: exception.cpp
//
//State: $State: Exp $
//
//Version: $Revision: 1.14 $
//
//Date: $Date: 1998/10/05 07:09:48 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
// 
//Authors:
//      Jari Pusa
//
//Description:
//      See file header (exception.h) description.
//
//Copyright:    
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//      
//Licence:
//     
//
//History:
//
//

#include "exception.h"
#include "debug.h"

//
// Method: Class pfException constructors
//
// Description:
//

pfException :: pfException(const pfException &other_)
    : _cause(other_._cause),
      _line(other_._line),
      _file(other_._file)
{
    return;
}

pfException :: pfException(pfUlong cause_)
    : _cause(cause_),
      _line(0),
      _file()
{
    return;
}

pfException :: pfException(string file_, int line_)
    : _cause (41),
      _line(line_),
      _file(file_)
{
    return;
}

//
// Method: Class pfException destructor
//
// Description:
//

pfException :: ~pfException(void)
{
    return;
}

//
// Method: getName
//
// Description:
//      Returns the cause value of the exception.
//

pfUlong pfException :: getCause(void) const
{
    return _cause;
}

//
// Method: getName
//
// Description:
//      Returns the name of exception.
//

string pfException :: getName(void) const
{
    string name("pfException");
    return name;
}

//
// Method: printInfo
//
// Description:
//      Prints some information concerning the occurence of
//      exception.
// 

void pfException :: printInfo(void) const
{
    static string unknownfile("unknown file");
    debugString("occured exception", getName());
    debugString("file", (_file.length() > 0 ? _file : unknownfile)); 
    debugPfUlong("line", _line);
    debugPfUlong("cause", _cause);
    return;
}

//
// Class: pfInvalidTypeException
//

pfInvalidTypeException :: pfInvalidTypeException(
    const pfInvalidTypeException &other_)
    : pfException(other_),
      _name(other_._name),
      _triedType(other_._triedType),
      _validType(other_._validType)
{
    return;
}

pfInvalidTypeException :: pfInvalidTypeException(string file_, int line_)
    : pfException(file_, line_),
      _name(),
      _triedType(0),
      _validType(0)
{
    return;
}

pfInvalidTypeException :: pfInvalidTypeException(
    string name_,
    int      triedType_,
    int      validType_,
    string file_,
    int      line_)
    : pfException(file_, line_),
      _name(name_),
      _triedType(triedType_),
      _validType(validType_)
{
    return;
}

pfInvalidTypeException :: ~pfInvalidTypeException(void)
{
    return;
}

string pfInvalidTypeException :: getName(void) const
{
    string name("pfInvalidTypeException");
    return name;
}

void pfInvalidTypeException :: printInfo(void) const
{
    pfException::printInfo();

    // If we know the name of variable, we know its valid type.
    debugString("Name of variable", _name);
    debugPfUlong("Valid type of variable", _validType);
    debugPfUlong("Invalid type of variable", _triedType);

    return;
}

//
// Class: pfNameAlreadyDefinedException
//

pfNameAlreadyDefinedException :: pfNameAlreadyDefinedException(
    const pfNameAlreadyDefinedException &other_)
    : pfException(other_),
      _name(other_._name)
{   
    return;
}

pfNameAlreadyDefinedException ::
pfNameAlreadyDefinedException(string file_, int line_)
    : pfException(file_, line_),
      _name()
{
    return;
}

pfNameAlreadyDefinedException ::
pfNameAlreadyDefinedException(string name_, string file_, int line_)
    : pfException(file_, line_),
      _name(name_)
{
    return;
}

pfNameAlreadyDefinedException :: ~pfNameAlreadyDefinedException(void)
{
    return;
}

string pfNameAlreadyDefinedException::getName(void) const
{
    string name("pfNameAlreadyDefinedException");
    return name;
}

void pfNameAlreadyDefinedException::printInfo(void) const
{
    pfException::printInfo();
    debugString("Name of variable", _name);
    return;
}

//
// Class: pfNameUndefinedException
//

pfNameUndefinedException :: pfNameUndefinedException(
    const pfNameUndefinedException &other_)
    : pfException(other_),
      _name(other_._name)
{
    return;
}

pfNameUndefinedException :: pfNameUndefinedException(string file_, int line_)
    : pfException(file_, line_),
      _name()
{
    return;
}

pfNameUndefinedException :: pfNameUndefinedException(string name_,
                                                     string file_, int line_)
    : pfException(file_, line_),
      _name(name_)
{
    return;
}

pfNameUndefinedException :: ~pfNameUndefinedException(void)
{
    return;
}

string pfNameUndefinedException :: getName(void) const
{
    string name("pfNameUndefinedException");
    return name;
}

void pfNameUndefinedException :: printInfo(void) const
{
    pfException::printInfo();
    debugString("Name of variable", _name);
    return;
}
    
//
// Class: pfOutOfRangeException
//

pfOutOfRangeException ::
pfOutOfRangeException(const pfOutOfRangeException &other_)
    : pfException(other_),
      _index(other_._index),
      _rangeMin(other_._rangeMin),
      _rangeMax(other_._rangeMax)
{
    return;
}

pfOutOfRangeException :: pfOutOfRangeException(string file_, int line_)
    : pfException(file_, line_),
      _index(0),
      _rangeMin(0),
      _rangeMax(0)
{
    return;
}

pfOutOfRangeException :: pfOutOfRangeException(pfLong   index_, 
                                               pfLong   rangeMin_,
                                               pfLong   rangeMax_,
                                               string file_,
                                               int      line_)
    : pfException(file_, line_),
      _index(index_),
      _rangeMin(rangeMin_),
      _rangeMax(rangeMax_)
{
    return;
}

pfOutOfRangeException :: ~pfOutOfRangeException(void)
{
    return;
}

string pfOutOfRangeException :: getName(void) const
{
    string name("pfOutOfRangeException");
    return name;
}

void pfOutOfRangeException :: printInfo(void) const
{
    pfException::printInfo();
    
    // Easy but maybe dirty way to resolve availability:
    // The only situation _index == _rangeMin _should_be_
    // _index == 0 && _rangeMin == 0, otherways this exception
    // is called without a reason (index is in the range) 
    if (_index != _rangeMin)
    {
        debugPfUlong("Index", _index);
        debugPfUlong("Min of index", _rangeMin);
        debugPfUlong("Max of index", _rangeMax);
    }
    return;
}

//---------------------------------------------------------------------------
//
// Class: pfBadValue
//

pfBadValue ::
pfBadValue(const pfBadValue &other_)
    : pfException(other_),
      _value(other_._value),
      _valueMin(other_._valueMin),
      _valueMax(other_._valueMax)
{
    return;
}

pfBadValue :: pfBadValue(string file_, int line_)
    : pfException(file_, line_),
      _value(0),
      _valueMin(0),
      _valueMax(0)
{
    return;
}

pfBadValue :: pfBadValue(pfLong value_, 
                         pfLong valueMin_,
                         pfLong valueMax_,
                         string file_,
                         int line_)
    : pfException(file_, line_),
      _value(value_),
      _valueMin(valueMin_),
      _valueMax(valueMax_)
{
    return;
}

pfBadValue :: ~pfBadValue(void)
{
    return;
}

string pfBadValue :: getName(void) const
{
    string name("pfBadValue");
    return name;
}

void pfBadValue :: printInfo(void) const
{
    pfException::printInfo();
    
    // Easy but maybe dirty way to resolve availability:
    // The only situation _index == _rangeMin _should_be_
    // _index == 0 && _rangeMin == 0, otherways this exception
    // is called without a reason (index is in the range) 
    if (_value != _valueMin)
    {
        debugPfUlong("Value", _value);
        debugPfUlong("Min of value", _valueMin);
        debugPfUlong("Max of value", _valueMax);
    }
    return;
}

//---------------------------------------------------------------------------

pfMemoryAllocationException :: pfMemoryAllocationException(
    const pfMemoryAllocationException &other_)
    : pfException(other_),
      _size(other_._size)
{
    return;
}
pfMemoryAllocationException :: pfMemoryAllocationException(
    string file_, int line_, int size_)
    : pfException(file_, line_),    
      _size(size_)
{    
    return;
}

pfMemoryAllocationException :: ~pfMemoryAllocationException(void)
{
    return;
}

string pfMemoryAllocationException :: getName(void) const
{
    string name("pfMemoryAllocationException");
    return name;
}

void pfMemoryAllocationException :: printInfo(void) const
{
    pfException::printInfo();
    debugPfUlong("Size", _size);
    return;
}

//---------------------------------------------------------------------------


pfNullPointerException :: pfNullPointerException(
    const pfNullPointerException &other_)
    : pfException(other_)
{
    return;
}
    
pfNullPointerException :: pfNullPointerException(string file_, int line_)
    : pfException(file_, line_)    
{
    return;
}

pfNullPointerException :: ~pfNullPointerException(void)
{
    return;
}

string pfNullPointerException :: getName(void) const
{
    string name("pfNullPointerException");
    return name;
}

void pfNullPointerException :: printInfo(void) const
{
    pfException::printInfo();
    return;
}

//---------------------------------------------------------------------------

pfNotConnectedException :: pfNotConnectedException(
    const pfNotConnectedException &other_)
    : pfException(other_)
{
    return;
}

pfNotConnectedException :: pfNotConnectedException(string file_, int line_)
    : pfException(file_, line_)
{
    return;
}

pfNotConnectedException :: ~pfNotConnectedException(void)
{
    return;
}

string pfNotConnectedException :: getName(void) const
{
    string name("pfNotConnectedException");
    return name;
}

void pfNotConnectedException :: printInfo(void) const
{
    pfException::printInfo();
    return;
}

//---------------------------------------------------------------------------

pfMethodFailed :: pfMethodFailed(const pfMethodFailed &other_)
    : pfException(other_)
{
    _cause = other_._cause;
    return;
}

pfMethodFailed :: pfMethodFailed(string cause_, string file_, int line_)
    : pfException(file_, line_)
{
    _cause = cause_;
    return;
}

pfMethodFailed :: ~pfMethodFailed(void)
{
    return;
}

string pfMethodFailed :: getName(void) const
{
    string name("pfMethodFailed");
    return name;
}

void pfMethodFailed :: printInfo(void) const
{
    pfException::printInfo();
    debugString("Cause", _cause);
    return;
}

