/*------------------------------------------------------------------------------
        FILE    :       StdInc.h
        CREATED :       98/05/11
        AUTHOR  :       Catalin Cocos
        CONTENTS:       standard includes - header to precompile
------------------------------------------------------------------------------*/

#ifndef __LDT_STDINC__
#define __LDT_STDINC__

/*••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
/*                       PROJECT-CONFIGURING DEFINES                          */
/*••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
/*=============================COMPATIBILITY==================================*/
#define LDT_SCR		/* define this to enable LDT/SCR interfacing facilities	  */

/*=================================DISK=======================================*/
#define LDT_MULTITHREADED
		/* define this if you want to use LDT in a multithreading environment */
#define LDT_USE_SINGLE_FILE_BUFFER	 /* WORKS ONLY IN THE SINGLETHREADED MODE */
        /* define this if you want to use a persistent and unique file buffer */


/*=============================PERFORMANCE====================================*/
#define LDT_LOG_STATISTICS
        /* define this if you want LDT to print an information log file at the
		 end of the execution */
#define LDT_LOG_MEMORY				 /* WORKS ONLY IN THE SINGLETHREADED MODE */
        /* define this if you want LDT to generate memory usage information   */

/*================================ERRoR=======================================*/
#define LDT_LOG_ERRORS		/* log warnings/errors */
#define LDT_DISPLAY_ERRORS		/* display error messages */
//#define LDT_DISPLAY_WARNINGS	/* display warning messages */
#define LDT_WARNING_LEVEL	3	/* the warning level:
									0 - no warnings						(DEFAULT)
									1 - level 1 warnings
									2 - level 2 & 1 warnings
									3 - levels 1, 2 & 3 
									4 - all warnings */
#define LDT_ERROR_LEVEL		0	/* the error level:
									0 - errors only for level 0			(DEFAULT)
									1 - level 1 warnings are treated as errors
									2 - level 2 & 1 warnings are treated as errors
									3 - level 1, 2 & 3 are treated as errors
									4 - all warnings are treated as errors */


/*••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
/*                 DO NOT EDIT THE FILE BEYOND THIS POINT !                   */
/*••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/


#ifdef U64
#undef LDT_MULTITHREADED
#undef LDT_LOG_STATISTICS
#undef LDT_LOG_MEMORY
#endif


#ifdef LDT_DISPLAY_WARNINGS
#define LDT_DISPLAY_ERRORS
#endif

#ifdef LDT_LOG_ERRORS
#define LDT_ERROR_TREATMENT
#endif

#ifdef LDT_DISPLAY_ERRORS
#define LDT_ERROR_TREATMENT
#endif

#ifdef LDT_MULTITHREADED
#undef LDT_USE_SINGLE_FILE_BUFFER
#undef LDT_LOG_MEMORY
#define LDT_USE_WIN
#endif

#ifdef LDT_LOG_MEMORY
#define LDT_LOG_STATISTICS
#endif

#ifdef LDT_LOG_STATISTICS
#define LDT_USE_WIN
#endif

#ifdef LDT_USE_WIN

#pragma warning(disable: 4115) 
#pragma warning(disable: 4201) 
#pragma warning(disable: 4214) 

#include <windows.h>
#include <process.h>
#include <limits.h>
#include <time.h>

#else

//typedef unsigned long       DWORD;
typedef int                 BOOL;
typedef unsigned char       BYTE;
typedef unsigned short      WORD;

#endif 

#ifdef LDT_LOG_STATISTICS

/* Log/stat stuff
-------------------*/
extern unsigned TimerStartCount;
extern unsigned TimerStopCount;

extern LONGLONG Frequency;
extern LONGLONG TimingOverhead;
extern LONGLONG StartOverhead;
extern LONGLONG StopOverhead;

typedef struct TimerStruct_ TimerStruct;

struct TimerStruct_
{
	LONGLONG	TimeCounter;
	LONGLONG	LastValue;
	unsigned	LastStartCount;
	unsigned	LastStopCount;
};

void InitializeTimingEnvironment();

void InitTimer(TimerStruct*);
void StartTimer(TimerStruct*);
void StopTimer(TimerStruct*);
double ReadTimer(TimerStruct*);

#endif

/*------------------------------------------------------------------------------
        COMPILER-DEPENDENT DEFINES
------------------------------------------------------------------------------*/

#ifdef __WATCOMC__

#define __inline

#endif /* __WATCOMC__ */

#ifdef _MSC_VER	/* Visulal C/C++ compiler */

#pragma warning(disable: 4514) /* Warning: unreferenced inline/local function has been removed */


#endif /* _MSC_VER */



/*------------------------------------------------------------------------------
        STANDARD INCLUDES
------------------------------------------------------------------------------*/

#ifdef U64

#define  LDT_USE_MMG    /* on ultra 64, use the memory manager*/
#include <ultra.h>

#else

#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <search.h>
#include <assert.h>
#include <string.h>
#include <io.h>

#endif /* U64 */



/*------------------------------------------------------------------------------
        MEMORY ALLOCATION TYPE
------------------------------------------------------------------------------*/

#ifdef LDT_USE_MMG

#define malloc LDT_malloc_Mmg
#define realloc LDT_realloc_Mmg
#define free LDT_free_Mmg

#include "Mem.h"

#endif /* LDT_USE_MMG */


/*------------------------------------------------------------------------------
        DEFINES
------------------------------------------------------------------------------*/

/*      Code exportation */
#undef CPA_EXPORT
#if defined(CPA_WANTS_IMPORT)
#define CPA_EXPORT __declspec(dllimport)
#elif defined(CPA_WANTS_EXPORT)
#define CPA_EXPORT __declspec(dllexport)
#else /* CPA_WANTS_IMPORT */
#define CPA_EXPORT
#endif /* CPA_WANTS_IMPORT */


#ifdef LDT_LOG_MEMORY

#include <malloc.h>

extern unsigned long g_allocsize;
extern unsigned long g_Maxallocsize;
extern unsigned long g_size;
extern void* g_palloc;

extern unsigned long g_allocCount;
extern unsigned long g_reallocCount;
extern unsigned long g_freeCount;

#define malloc(x) ( g_size = x, g_allocsize += g_size, g_allocCount++, g_Maxallocsize = max(g_Maxallocsize, g_allocsize), malloc(g_size))
#define realloc( y, x) (g_palloc = y, g_size = x, g_reallocCount++, g_allocsize += g_size - (g_palloc?_msize(g_palloc):0), g_Maxallocsize = max(g_Maxallocsize, g_allocsize), realloc( g_palloc, g_size ))
#define free( y ) (g_palloc = y, g_freeCount++, g_size =(g_palloc?_msize(g_palloc):0), g_allocsize -= g_size, free(g_palloc))

#endif

#endif /* __LDT_STDINC__ */
