/*///////////////////*/
/* macro for Error //*/
/*///////////////////*/
#ifndef __AIMACROS_H__ 
#define __AIMACROS_H__
 
#if defined(__DEBUG_AI__)
#define D_MmgAITestBeforeFree
#endif
 
#ifdef __FATAL_ERR_AI__
 
/* This allow us to save about 600 Ko in the release lib
#define M_AIFatalError(FatalErrorNum) \
    Erm_M_UpdateLastError(AI, C_ucErmDefaultChannel, FatalErrorNum, C_lErmNoDebugData, C_ucErmOpenInfoWindow, C_ucAllowStopForDebug, NULL);
 
#define M_AIFatalErrorMsg(FatalErrorNum,szMsg) \
    Erm_M_UpdateLastError(AI, C_ucErmDefaultChannel, FatalErrorNum, C_lErmNoDebugData, C_ucErmOpenInfoWindow, C_ucAllowStopForDebug, szMsg);
*/
 
void fn_vOnAIErm_M_UpdateLastError(unsigned short FatalErrorNum,char *szMsg);
#define M_AIFatalErrorMsg(FatalErrorNum,szMsg) fn_vOnAIErm_M_UpdateLastError(FatalErrorNum,szMsg)
#define M_AIFatalError(FatalErrorNum) M_AIFatalErrorMsg(FatalErrorNum,NULL)
 
#else /*__FATAL_ERR_AI__*/
#define M_AIFatalError(FatalErrorNum) /*nothing to do*/
#define M_AIFatalErrorMsg(FatalErrorNum,szMsg) /*nothing to do*/
#endif /*__FATAL_ERR_AI__*/
 
#ifdef __WARNING_ERR_AI__
#define M_AIWarningError(ErrorNum, ucOpenInfoWindow)\
/*      ----------------*/\
{ \
 if (ErrorNum > E_uwAIStartOfWarning) \
 { \
    Erm_M_UpdateLastError(AI, C_ucErmDefaultChannel, ErrorNum, C_lErmNoDebugData, ucOpenInfoWindow, C_ucAllowStopForDebug, NULL);\
 } \
 else \
 { \
    M_AIFatalError(E_uwAIFatalNotAFatalError);\
 } \
}
#else /*__WARNING_ERR_AI__ */
 
 
//XB 10/08/99
#define M_AIWarningError(ErrorNum, uwOpenInfoWindow)/*\
{ \
 if (ErrorNum < E_uwAIStartOfWarning) \
     M_AIFatalError(E_uwAIFatalNotAFatalError);\
}*/
 
#endif /*__WARNING_ERR_AI__ */
 
 
 
#ifdef __WARNING_ERR_AI__
 
#define M_AIWarningErrorAndAllowStopForDebug(ErrorNum, ucOpenInfoWindow, szMytxt)\
/*      ----------------*/\
{ \
 if (ErrorNum > E_uwAIStartOfWarning) \
 { \
    Erm_M_UpdateLastError(AI, C_ucErmDefaultChannel, ErrorNum, C_lErmNoDebugData, ucOpenInfoWindow, C_ucAllowStopForDebug, szMytxt);\
	Erm_M_ClearLastError(C_ucErmDefaultChannel);\
 } \
 else \
 { \
    M_AIFatalError(E_uwAIFatalNotAFatalError);\
 } \
}
 
 
#define M_AIWarningErrorAndNeverStopForDebug(ErrorNum, ucOpenInfoWindow, szMytxt)\
/*      ----------------*/\
{ \
 if (ErrorNum > E_uwAIStartOfWarning) \
 { \
    Erm_M_UpdateLastError(AI, C_ucErmDefaultChannel, ErrorNum, C_lErmNoDebugData, ucOpenInfoWindow, C_ucNeverStopForDebug, szMytxt);\
	Erm_M_ClearLastError(C_ucErmDefaultChannel);\
 } \
 else \
 { \
    M_AIFatalError(E_uwAIFatalNotAFatalError);\
 } \
}
#else /*__WARNING_ERR_AI__ */
 
//XB 10/08/99
#define M_AIWarningErrorAndAllowStopForDebug(ErrorNum, uwOpenInfoWindow, szMytxt)/*\
{ \
 if (ErrorNum < E_uwAIStartOfWarning) \
     M_AIFatalError(E_uwAIFatalNotAFatalError);\
}*/
 
//XB 10/08/99
#define M_AIWarningErrorAndNeverStopForDebug(ErrorNum, uwOpenInfoWindow, szMytxt)/*\
{ \
 if (ErrorNum < E_uwAIStartOfWarning) \
     M_AIFatalError(E_uwAIFatalNotAFatalError);\
}*/
 
#endif /*__WARNING_ERR_AI__ */
 
#ifdef __FATAL_ERR_AI__   
#define M_AIIfErrorUpdateFatalError(UsedModule, ErrorNum)\
/*      ---------------------------*/\
	if (Erm_M_uwCheckError(UsedModule, C_ucErmDefaultChannel)){\
		Erm_M_ClearLastError(C_ucErmDefaultChannel);\
		M_AIFatalError(ErrorNum);\
	}
#else /*__FATAL_ERR_AI__   */
#define M_AIIfErrorUpdateFatalError(UsedModule, ErrorNum) /*nothing to do*/
#endif /*__FATAL_ERR_AI__*/
 
 
#ifdef __WARNING_ERR_AI__
#define M_AIIfErrorUpdateWarningError(UsedModule, ErrorNum, uwOpenInfoWindow)\
/*      -----------------------------*/\
	if (Erm_M_uwCheckError(UsedModule, C_ucErmDefaultChannel)){\
		Erm_M_ClearLastError(C_ucErmDefaultChannel);\
		M_AIWarningError(ErrorNum, uwOpenInfoWindow);\
	}
#else /*__WARNING_ERR_AI__*/
#define M_AIIfErrorUpdateWarningError(UsedModule, ErrorNum, uwOpenInfoWindow) /*nothing to do*/
#endif /*__WARNING_ERR_AI__*/
 
/* ALB January 1997 */
#ifdef __DEBUG_AI__
#define M_AI_DEBUG_ASSERT(bCond,ErrorRaised)\
 if(!(bCond))\
 {\
  M_AIFatalError(ErrorRaised);\
 }
 
#define M_AI_DEBUG_ASSERT_WARNING(bCond,ErrorRaised)\
 if(!(bCond))\
 {\
  M_AIWarningError(ErrorRaised, C_ucErmNoOpenInfoWindow); \
 }
 
#define M_AI_MemSet(pBuffer,cCharToSet,ucSizeOfMem)\
 if(pBuffer)\
 {\
  memset(pBuffer,cCharToSet,ucSizeOfMem);\
 }
#else /*__DEBUG_AI__*/
#define M_AI_DEBUG_ASSERT(bCond,ErrorRaised)
#define M_AI_DEBUG_ASSERT_WARNING(bCond,ErrorRaised)
#define M_AI_MemSet(pBuffer,cCharToSet,ucSizeOfMem)
#endif /*__DEBUG_AI__*/
/* ALB END */
 
/*////////////////////*/
/* macro for Memory //*/
/*////////////////////*/
#define MODE_STATIC_MEM_FOR_AI
#ifdef MODE_STATIC_MEM_FOR_AI
  #define M_AIChooseMemoryBlock() Mmg_M_SetModeAlloc4Ch(AI,(unsigned char)AI_g_ucMemoryBlockUsed,C_ucMmgDefaultChannel)
#else
  #define M_AIChooseMemoryBlock() Mmg_M_SetModeAlloc4Ch(AI,E_ucDynamic,C_ucMmgDefaultChannel)
#endif /* MODE_STATIC_MEM_FOR_AI*/
 
void fn_vErrorOnAIAlloc(void);
/*M_AIIfErrorUpdateFatalError(Mmg, E_uwAIFatalFailedAllocationMem);*/
 
void fn_vErrorOnAIFree(void);
/*M_AIIfErrorUpdateWarningError (Mmg, E_uwAIWarningCanNotFree, C_ucErmOpenInfoWindow);*/
 
 
/*	M_AIChooseMemoryBlock();*/
/*	Var = (cast) Mmg_fn_p_vAlloc4Ch(ucSize,C_ucMmgDefaultChannel);*/
 
#ifndef U64 
#define M_AIAlloc(Var, cast, ucSize)\
{\
 Var = (cast)AI_fn_p_vTrueAlloc(ucSize);\
 AI_fn_vMemoryLogFile(Var,AI_C_ActionMalloc,__FILE__,__LINE__); \
	fn_vErrorOnAIAlloc(); \
}
#else  /* !U64 */
	#define M_AIAlloc(Var, cast, ucSize)\
	{\
		Var = (cast)AI_fn_p_vTrueAlloc(ucSize);\
		fn_vErrorOnAIAlloc(); \
	}
#endif /* !U64 */
 
/*	M_AIChooseMemoryBlock();*/
/*	Var = (cast) Mmg_fn_p_vRealloc4Ch(AdrScr,ucSize,C_ucMmgDefaultChannel);*/
 
#ifndef U64 
#define M_AIReAlloc(Var,AdrScr,cast, ucSize)\
{\
 Var = (cast) AI_fn_p_vTrueRealloc(AdrScr,ucSize);\
 AI_fn_vMemoryLogFile(Var,AI_C_ActionRealloc,__FILE__,__LINE__); \
		fn_vErrorOnAIAlloc(); \
	}
#else  /* !U64 */
	#define M_AIReAlloc(Var,AdrScr,cast, ucSize)\
	{\
		Var = (cast) AI_fn_p_vTrueRealloc(AdrScr,ucSize);\
	fn_vErrorOnAIAlloc(); \
}
#endif /* !U64 */
 
/*	M_AIChooseMemoryBlock();*/
/*	Mmg_fn_vFree4Ch(p_cAdr,C_ucMmgDefaultChannel);*/
 
#ifndef U64 
#define M_AIFree(p_cAdr) \
{\
 AI_fn_vMemoryLogFile(p_cAdr,AI_C_ActionFree,__FILE__,__LINE__); \
		AI_fn_vTrueFree(p_cAdr);\
		fn_vErrorOnAIFree(); \
		p_cAdr=NULL; \
	}
#else  /* !U64 */
	#define M_AIFree(p_cAdr) \
	{\
 AI_fn_vTrueFree(p_cAdr);\
 fn_vErrorOnAIFree(); \
 p_cAdr=NULL; \
}
#endif /* !U64 */
 
#endif /* __AIMACROS_H__*/
