// This is a part of the Object Oriented Mathematical Library
// Copyright (C) 1999-2008 Renishaw plc
//
// This source file is the confidential property of Renishaw plc.
// Reproduction or transmission in whole or in part, in any form or
// by any means, electronic, mechanical or otherwise, is prohibited
// without the prior written consent of the copyright owner.
//
// objexcep.h -- exceptions


// ========================================================================================================================
#ifndef __OBJEXCEP_H__
#define __OBJEXCEP_H__


#include "OOMathsExport.h"

////////////////////////////////////////////////////////////////////////////////
// CMaException - math library exception (abstract base class)

class OOMATHS_API CMaException
{
public:
// destructor
	virtual ~CMaException(){}

// operations
   static inline void SetAssert(){m_nAssert = 1;}
   static inline int  IsAssertEnabled(){return m_nAssert;}
      // note: on assert setting
      //    assert is disabled by default,
      //    these functions have no effect on release version of oomaths.lib

   virtual int GetCause() const = 0;
      // note: return the internal error code

   void GetErrorMessage(int BufferSize, char* Buffer) const;
      // note: If Buffer is small the error message will be truncated.
      //    The message always terminates with a null character.

protected:
// constructor
   CMaException(int ErrorCode = 0);

// implementation
   static int m_nAssert;
   int m_nCode;
   int m_nD1;
   int m_nD2;
   double m_Value;
   double m_Value2;
   char m_pName[100];
   char m_pWhere[50];
};

// ========================================================================================================================
////////////////////////////////////////////////////////////////////////////////
// CMaConstructionException - math library construction exception

class OOMATHS_API CMaConstructionException : public CMaException
{
public:
   enum {
      none,
      badSizeDegree,
      negativeSizeDegree,
      zeroVector,
      badVectorSize,
      badLength,
      badAngle,
      badMajorMinor,
      notOrthogonal,
      pointCloseToLine,
      badStartEnd,
      badInterval,
      badData,
      badKnotsType,
      expectedSize,
	  incorrectArrayExpandSize
   };

// constructor
   CMaConstructionException(int cause = CMaConstructionException::none,
      char* objName = NULL, char* attrName = NULL, int size1 = 0, int size2 = 0);

// destructor
   ~CMaConstructionException(){}

// attributes
   inline int GetCause() const{return m_nCode;}   // error code
};

// ========================================================================================================================
////////////////////////////////////////////////////////////////////////////////
// CMaOperationException - math library operation exception

class OOMATHS_API CMaOperationException : public CMaException
{
public:
   enum {
      none,
      badArgument,
      badIntArgument,
      badIndex,
      badIndexSum,
      unmatchedSizes,
      divideByZero,
      multiplyLarge,
      zeroSize,
      zeroVector,
      notVectorSize3,
      notVectorSize3or4,
      badPolylineSize,
      smallPolylineSize,
      badValue,
      valuesNotInOrder,
      nonSquareMatrix,
      equationsNotDefined,
      badAppend,
      zeroDistancePP,
      zeroDistanceLL,
      zeroDistancePL,
      notPointOnPlane,
      notParallelLL,
      notParallelPP,
      notParallelLP,
      badRefVector,
      badDistance,
      notJoin,
      zeroSegment,
      selfIntersecting,
      ZeroBspline,
      badKnotsSize,
      badKnotsSize2,
      badKnots,
      badKnots2,
      badEqualKnots,
      badKnotsMult,
      badWeightsSize,
      badWeights,
      BadPara,
      badParas,
      BadKnotsParas,
      badLimits,
      badLowerUpperLimits,
      notImplemented,
      algorithmFailure,
	  pathNotFound,
	  unableToWriteFile
   };

// constructor
   CMaOperationException(int cause = CMaOperationException::none,
      char* opName = NULL, char* FunctionName = NULL,
      int bound1 = 0, int bound2 = 0, double value1 = 0, double value2 = 0);

// destructor
   ~CMaOperationException(){}

// attributes
   int GetCause() const{return (!m_nCode) ? 0 : m_nCode - 100;}   // error code
   inline double GetValue() const{return m_Value;}
};

// ========================================================================================================================
////////////////////////////////////////////////////////////////////////////////
// CMaBestfitException - math library bestfit exception

// 27/11/07 New ENUM "didNotConvergeWithinLimit" added as part of fix for CCAR52918.
// This is thrown when the iteration limit for a fitting method is reached before 
// the fitting method converges.

// 04/12/07 New ENUM "invalidIterationLimit" added as part of fix for CCAR52918.
// This is thrown when the iteration limit passed to a fitting method is =< 0.

class OOMATHS_API CMaBestfitException : public CMaException
{
public:
   enum {
      none,
      tooFewPoints,
      coincidentPoints,
      collinearPoints,
      coplanarPoints,
      data2D,
      badData,
      insufficientPoints,
      badDegree,
      badSize,
      notImplemented,
      algorithmFailure,
	   didNotConvergeWithinLimit, //New ENUM added as part of CCAR52918
      invalidIterationLimit //New ENUM added as part of CCAR52918
   };

// constructor
   CMaBestfitException(int cause = CMaBestfitException::none,
                       char* objName = NULL, int size = 0);

// destructor
   ~CMaBestfitException(){}

// attributes
   int GetCause() const{return(!m_nCode)? 0 : m_nCode - 200;}   // error code
   inline int GetSize() const{ return m_nD1; }
};

// ========================================================================================================================
////////////////////////////////////////////////////////////////////////////////
// CMaMemoryException - math library out-of-memory exception

class OOMATHS_API CMaMemoryException : public CMaException
{
public:
// constructor
   CMaMemoryException(char* FunctionName = NULL);

// destructor
   ~CMaMemoryException(){}

// attributes
   int GetCause() const{return m_nCode;}   // error code
};

// ========================================================================================================================

#endif // __OBJEXCEP_H__
// ========================================================================================================================
