/*
------------------------------------------------------------------------------------------
HEADER FILE FOR :
Macros definition for mathematical module
------------------------------------------------------------------------------------------
File Name :
Mth_Macr.h
------------------------------------------------------------------------------------------
Creation :
  * Date : 
    February 18,1997
  * Author : 
    Albert PAIS
------------------------------------------------------------------------------------------
Contents :
This file defines somes macros used in MTH library
------------------------------------------------------------------------------------------
Modification :
  * Date : 
  * Author : 
  * Modify :
------------------------------------------------------------------------------------------
*/
#if !defined(__MTHMACROS_TYPES__)
#define __MTHMACROS_TYPES__
 
#if !defined(ONLY_TYPES)
#define MTHMACROS_UNDEF
#define ONLY_TYPES
#endif /* !ONLY_TYPES */
 
/*
------------------------------------------------------------------------------------------
INCLUDE FILES :
------------------------------------------------------------------------------------------
*/
/*
----------------------------------------
File Name :
Mth_Opt.h
----------------------------------------
Required for :
Mathematical options.
----------------------------------------
*/
#include "Mth_Opt.h"
 
#if defined(MTHMACROS_UNDEF)
#undef ONLY_TYPES
#undef MTHMACROS_UNDEF
#endif /* !MTHMACROS_UNDEF */
 
/*
------------------------------------------------------------------------------------------
TYPE DEFINITION :
If enumerate :
 M_BeginDeclareEnumerate(<type>)
 M_EndDeclareEnumerate(<type>, <basic type>)
------------------------------------------------------------------------------------------
*/
 
#endif /* !__MTHMACROS_TYPES__ */
 
#if !defined(ONLY_TYPES)
 
#if !defined(__MTHMACROS_VARS__)
#define __MTHMACROS_VARS__
 
#undef EXTERN
#undef extern
#if !defined(GLOBALS)
#define EXTERN extern
#else /* !GLOBALS */
#define EXTERN
#endif /* !GLOBALS */
 
/*
------------------------------------------------------------------------------------------
MACROS-CONSTANT DECLARATION:
------------------------------------------------------------------------------------------
*/
 
#undef extern
#endif /* !__MTHMACROS_VARS__ */
 
#if !defined (__MTHMACROS_PROTOS__)
#define __MTHMACROS_PROTOS__
 
/*
------------------------------------------------------------------------------------------
MACROS-FUNCTIONS DECLARATION:
------------------------------------------------------------------------------------------
*/
 
/*////////////////////*/
/* macro for Error  //*/
/*////////////////////*/
 
#ifdef __FATAL_ERR_MTH__
#define M_MTH_FatalError(FatalErrorNum) \
    Erm_M_UpdateLastError(MTH, C_ucErmDefaultChannel, FatalErrorNum, C_lErmNoDebugData, C_ucErmOpenInfoWindow, C_ucAllowStopForDebug, NULL);
#else /*__FATAL_ERR_MTH__*/
#define M_MTH_FatalError(FatalErrorNum)
#endif /*__FATAL_ERR_MTH__*/
 
#ifdef __WARNING_ERR_MTH__
#define M_MTH_WarningError(ErrorNum, ucOpenInfoWindow)\
/*      ----------------*/\
{ \
 if (ErrorNum > E_uwMTHStartOfWarning) \
 { \
    Erm_M_UpdateLastError(MTH, C_ucErmDefaultChannel, ErrorNum, C_lErmNoDebugData, ucOpenInfoWindow, C_ucAllowStopForDebug, NULL);\
 } \
 else \
 { \
    M_MTH_FatalError(E_uwMTHFatalNotAFatalError);\
 } \
}
#else /*__WARNING_ERR_MTH__*/
#define M_MTH_WarningError(ErrorNum, uwOpenInfoWindow)\
{ \
 if (ErrorNum < E_uwMTHStartOfWarning) \
     M_MTH_FatalError(E_uwMTHFatalNotAFatalError);\
}
#endif /*__WARNING_ERR_MTH__*/
 
#ifdef __FATAL_ERR_MTH__
#define M_MTH_IfErrorUpdateFatalError(UsedModule, ErrorNum)\
/*      ---------------------------*/\
	if (Erm_M_uwCheckError(UsedModule, C_ucErmDefaultChannel)){\
		Erm_M_ClearLastError(C_ucErmDefaultChannel);\
		M_MTH_FatalError(ErrorNum);\
	}
#else /*__FATAL_ERR_MTH__*/
#define M_MTH_IfErrorUpdateFatalError(UsedModule, ErrorNum)
#endif /*__FATAL_ERR_MTH__*/
 
#ifdef __WARNING_ERR_MTH__
#define M_MTH_IfErrorUpdateWarningError(UsedModule, ErrorNum, uwOpenInfoWindow)\
/*      -----------------------------*/\
	if (Erm_M_uwCheckError(UsedModule, C_ucErmDefaultChannel)){\
		Erm_M_ClearLastError(C_ucErmDefaultChannel);\
		M_MTH_WarningError(ErrorNum, uwOpenInfoWindow);\
	}
#else /*__WARNING_ERR_MTH__*/
#define M_MTH_IfErrorUpdateWarningError(UsedModule, ErrorNum, uwOpenInfoWindow)
#endif /*__WARNING_ERR_MTH__*/
 
/*////////////////////*/
/* macro for Memory //*/
/*////////////////////*/
#ifdef MODE_STATIC_MEM_FOR_MTH
  #define M_MTH_InitMem() Mmg_M_SetModeAlloc4Ch(MTH, E_ucMTHBlock1,C_ucMmgDefaultChannel)
#else
  #define M_MTH_InitMem() Mmg_M_SetModeAlloc4Ch(MTH, E_ucDynamic,C_ucMmgDefaultChannel)
#endif /* MODE_STATIC_MEM_FOR_MTH*/
 
#define M_MTH_Alloc(Var, cast, ucSize)\
{\
	M_MTH_InitMem();\
	Var = (cast) Mmg_fn_p_vAlloc4Ch(ucSize,C_ucMmgDefaultChannel);\
	M_MTH_IfErrorUpdateFatalError(Mmg, E_uwMTHFatalFailedAllocationMem);\
}
 
#define M_MTH_AllocWithoutInitMem(Var, cast, ucSize)\
{\
	Var = (cast) Mmg_fn_p_vAlloc4Ch(ucSize,C_ucMmgDefaultChannel);\
	M_MTH_IfErrorUpdateFatalError(Mmg, E_uwMTHFatalFailedAllocationMem);\
}
 
#define M_MTHRealloc(Var, AdrSrc, cast, ucSize)\
{\
	M_MTH_InitMem();\
	Var = (cast) Mmg_fn_p_vRealloc4Ch(AdrSrc, ucSize,C_ucMmgDefaultChannel);\
	M_MTH_IfErrorUpdateFatalError(Mmg, E_uwMTHFatalFailedAllocationMem);\
}
#define M_MTHReallocWithoutInitMem(Var, AdrSrc, cast, ucSize)\
{\
	Var = (cast) Mmg_fn_p_vRealloc4Ch(AdrSrc, ucSize,C_ucMmgDefaultChannel);\
	M_MTH_IfErrorUpdateFatalError(Mmg, E_uwMTHFatalFailedAllocationMem);\
}
 
 
#define M_MTHFree(p_cAdr) \
{\
	M_MTH_InitMem();\
	Mmg_fn_vFree4Ch(p_cAdr,C_ucMmgDefaultChannel);\
	M_MTH_IfErrorUpdateWarningError(Mmg, E_uwMTHWarningCanNotFree, C_ucErmOpenInfoWindow);\
 p_cAdr=NULL; \
}
 
#define M_MTHFreeWithoutInitMem(p_cAdr) \
{\
	Mmg_fn_vFree4Ch(p_cAdr,C_ucMmgDefaultChannel);\
	M_MTHIfErrorUpdateWarningError (Mmg, E_uwMTHWarningCanNotFree, C_ucErmOpenInfoWindow);\
 p_cAdr=NULL; \
}
 
#ifdef MTH_M_DEBUG
#define MTH_M_ASSERT(_Expression,_eErrorCode)\
 if(!(_Expression))\
 {\
  M_MTH_FatalError(_eErrorCode);\
 }
#else /* MTH_M_DEBUG */
#define MTH_M_ASSERT(_Expression,_eErrorCode)
#endif /* MTH_M_DEBUG */
 
/*
------------------------------------------------------------------------------------------
FUNCTIONS DECLARATION:
------------------------------------------------------------------------------------------
*/
#endif /* !__MTHMACROS_PROTOS__ */
 
#endif /* !ONLY_TYPES */
