

//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/
//_/_/  This file is part of CMSDK version 2.1.1.260726 (26 July 2026)
//_/_/  
//_/_/  developed by
//_/_/  
//_/_/  Communicative Machines Ltd. 
//_/_/    http://cmlabs.com/
//_/_/  Copyright (c) 2026
//_/_/  
//_/_/  in collaboration with 
//_/_/  
//_/_/  Icelandic Institute for Intelligent Machines ses
//_/_/    Menntavegur 1
//_/_/    101 Reykjavik
//_/_/    ICELAND
//_/_/    http://www.iiim.is/
//_/_/
//_/_/  and is released under the following
//_/_/  
//_/_/  EXTENDED BSD License
//_/_/
//_/_/  Redistribution and use in source and binary forms, with or without
//_/_/  modification, is permitted provided that the following conditions 
//_/_/  are met:
//_/_/
//_/_/  - Redistributions of source code must retain the above copyright 
//_/_/    and collaboration notice, this list of conditions and the following 
//_/_/    disclaimer.
//_/_/
//_/_/  - Redistributions in binary form must reproduce the above copyright 
//_/_/    notice, this list of conditions and the following disclaimer in the 
//_/_/    documentation and/or other materials provided with the distribution.
//_/_/
//_/_/  - Neither the name of its copyright holders nor the names of its 
//_/_/    contributors may be used to endorse or promote products derived from 
//_/_/    this software without specific prior written permission.
//_/_/
//_/_/  - CADIA Clause: The license granted in and to the software under this 
//_/_/    agreement is a limited-use license. The software may not be used in 
//_/_/    furtherance of: (i) intentionally causing bodily injury or severe 
//_/_/    emotional harm to any person; (ii) invading the personal privacy or 
//_/_/    violating the human rights of any person; or (iii) committing or 
//_/_/    preparing for any act of war. 
//_/_/
//_/_/  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
//_/_/  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
//_/_/  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
//_/_/  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 
//_/_/  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
//_/_/  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
//_/_/  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
//_/_/  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
//_/_/  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
//_/_/  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
//_/_/  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
/*! @file Standard.h
    @brief Platform/compiler detection and base portability macros for all of CMSDK.

    Included (directly or indirectly) by every translation unit. It:
    - detects the platform and defines WINDOWS / LINUX / OSX+DARWIN / POCKETPC,
      ARCH_32 / ARCH_64, NATIVESYSTEMNAME and COMPILERVERSION;
    - defines small math convenience macros (clPI, clmax, clmin, clround,
      clsqr, clsign, clabs);
    - papers over libc differences (snprintf/sscanf_s, stricmp/strnicmp,
      longlong / __int64 typedefs, _open/_close);
    - pulls in the ubiquitous STL headers and bimap.h.

    Keep this header free of heavyweight includes: it is the innermost
    dependency of the whole SDK. */
/*

  This is the file where we define all we need for different OSes,
  like the Darwin system, that does not have various normal OS functions.

*/

#if !defined(__standard_h)              // Sentry, use file only if it's not already included.
#define __standard_h

#pragma warning (disable : 4100)

#define __LIBRARY_VERSION_STRING__		"2.1.1"

// Will speed up STL in general and massively in debug
#ifndef _SECURE_SCL
	#define _SECURE_SCL 0
	#define _SCL_SECURE_NO_DEPRECATE
	#define _HAS_ITERATOR_DEBUGGING 0
#endif

#include <list>
#include <map>
#include <queue>
#include "bimap.h"
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>

// #pragma warning( disable : 4995 )

#if defined(WIN32_PLATFORM_PSPC)
	// Code for either Windows Mobile 6 Classic
	// or Windows Mobile 6 Professional.
	#define POCKETPC
	#define WINDOWS
	#define NATIVESYSTEMNAME "Win32PPC"
	#define COMPILERVERSION _MSC_VER
//	#if (WIN32_PLATFORM_PSPC = 400)
		// Code for Windows Mobile 2003.
//	#elif (WIN32_PLATFORM_PSPC = 310)
		// Code for Pocket PC 2002.
//	#endif
#elif defined(__CYGWIN__)
	#define NATIVESYSTEMNAME "Win32Cygwin"
	#define COMPILERVERSION GCC_VERSION
	#define   WINDOWS
	#if defined(__x86_64)
		#define   ARCH_64
	#elif defined(__i386)
		#define   ARCH_32
	#endif
#elif defined(_WIN64)
	#define   WINDOWS
	#define   ARCH_64
	#define WIN_VS
	#if _MSC_VER < 1300
		#define WIN_VS6
		#define NATIVESYSTEMNAME "Win32VS6"
	#else
		#define WIN_VSNET
		#define NATIVESYSTEMNAME "Win32VSNET"
	#endif // _MSC_VER < 1300
	#define COMPILERVERSION _MSC_VER
#elif defined(_WIN32)
	#define   WINDOWS
	#define   ARCH_32
	#define WIN_VS
	#if _MSC_VER < 1300
		#define WIN_VS6
		#define NATIVESYSTEMNAME "Win32VS6"
	#else
		#define WIN_VSNET
		#define NATIVESYSTEMNAME "Win32VSNET"
	#endif // _MSC_VER < 1300
	#define COMPILERVERSION _MSC_VER
#elif defined(__GNUC__)

	#if defined(__x86_64)
		#define   ARCH_64
	#elif defined(__i386)
		#define   ARCH_32
	#elif defined(__aarch64__)
		#define   ARCH_64
	#endif
	#if defined(__linux)
		#define   LINUX
		#define NATIVESYSTEMNAME "Unix"
	#elif defined(__APPLE__)
		#define   OSX
		#define   DARWIN
		#define NATIVESYSTEMNAME "Darwin"
	#endif
	#define COMPILERVERSION GCC_VERSION
#endif

//3.1415926535
#define clPI 3.14159265358979323846264 
#define clmax(a,b) (((a) > (b)) ? (a) : (b))
#define clmin(a,b) (((a) < (b)) ? (a) : (b))
#define clround(x) (int) (((x) - floor(x)) >= 0.5 ? (floor(x) + 1) : (floor(x)))
#define clsqr(x) ((x) * (x))
#define clsign(x) (((x) < 0) ? (-1) : (1))
#define clabs(a) ((a)<0?-(a):(a))

#if defined(WIN_VS)
	#if !defined(POCKETPC)
		#if defined(_DEBUG)
			//#define _CRTDBG_MAP_ALLOC
			//#include <stdlib.h>
			//#include <crtdbg.h>
			//#define MY_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__) 
			//#define new MY_NEW 
			//#define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
		#endif
	#endif
#endif

#if defined(CYGWIN)
	#include <winsock2.h>
#endif

#if defined(__GNUC__)

	#ifdef __GNUC_PATCHLEVEL__
		#define GCC_VERSION (__GNUC__ * 10000 \
	                    + __GNUC_MINOR__ * 100 \
	                    + __GNUC_PATCHLEVEL__)
	#else
		#define GCC_VERSION (__GNUC__ * 10000 \
	                    + __GNUC_MINOR__ * 100)
	#endif
	//#if __GNUC__ == 4
	//	#if __GNUC_MINOR__ < 3
	//		#error "GNU C++ 4.3 or later is required to compile this program"
	//	#endif /* __GNUC_MINOR__ */
	//#endif /* __GNUC__ */
	#define _open open
	#define _close close
#endif

#ifdef WINDOWS
	#define longlong signed __int64
	// typedef signed __int64 longlong;
//	#include <windows.h>
//	#include <RpcDce.h>
	#ifndef snprintf
		#define snprintf sprintf_s
	#endif // snprintf
	#define stricmp _stricmp
	//#define snprintf sprintf_s
	#define ssscanf sscanf_s
	#define strnicmp _strnicmp
#else

	typedef long long longlong;
	#ifdef Darwin
	#else
	#endif // Darwin

	#include <unistd.h>
	#include <pthread.h>
	#ifndef __APPLE__
	#include <semaphore.h>
	#endif

	#ifndef __int64
		typedef long long __int64;
	#endif 

	#define HAVE_TIMEZONE_VAR 1
	#define ssscanf sscanf
	#define strnicmp strncasecmp
#endif

#if !defined(POCKETPC)
	#include <signal.h>
#endif

#include <stdlib.h>
#include <ctype.h>

#endif // __standard_h
