#pragma once
/*************************************************

Copyright:

Author:李宇哲

Date:2021-07-12

Description:平台宏配置，及其用户语言配置表相关定义

**************************************************/
#include <iostream>
#if SM_DEBUG_TIME_LOG
#include <time.h>
#endif

#ifdef _MSC_VER //用于判断是否是 vs 平台
#ifdef SH_LANGUAGE_UNIT_TEST
    #define SH_CROSS_PLATFORM_API
  #else
    #define SH_CROSS_PLATFORM_HIDDEN_API
	#ifdef SH_CROSS_PLATFORM_LIBRARY_EXPORTS
		#define SH_CROSS_PLATFORM_API __declspec(dllexport)
	#else
		#define SH_CROSS_PLATFORM_API __declspec(dllimport)
    #endif
  #endif
#else // 说明是 OSX 或者 Linux
    #define SH_CROSS_PLATFORM_API __attribute((visibility("default"))) // 明确指示，这个函数在动态库中可见
	#define SH_CROSS_PLATFORM_HIDDEN_API __attribute((visibility("hidden"))) // 明确指示，这个函数在动态库中不可见
#endif

// 定义命名空间
#define U_NS_BEGIN_SH_LANGUAGE namespace SmartHomeLanugage{
#define U_NS_END_SH_LANGUAGE }

#define U_SH_DISABLE_COPY(Class) \
    Class(const Class &); \
    Class &operator=(const Class &);

#define U_SH_DISABLE_CONSTRUCT_AND_COPY(Class) \
    Class(); \
    Class(const Class &); \
    Class &operator=(const Class &);

/** 用于宏函数的保护  */
#if !(defined (U_SH_STMT_START) && defined (U_SH_STMT_END))
#define U_SH_STMT_START  do
#define U_SH_STMT_END    while (0)

/** 当expr为假时，返回 */
#define U_SH_RETURN_IF_FAIL(expr)  U_SH_STMT_START{   \
if (!(expr)) \
{\
	return; \
}   \
	}U_SH_STMT_END

/** 当expr为假时，返回val */
#define U_SH_RETURN_VAL_IF_FAIL(expr, val) U_SH_STMT_START{    \
if (!(expr)) \
{\
	return val; \
}   \
	}U_SH_STMT_END
/** 当expr为假时，goto */
#define U_SH_GOTO_IF_FAIL(expr, flag)  U_SH_STMT_START{   \
if (!(expr)) \
{\
	goto flag; \
}   \
	}U_SH_STMT_END

/** 仅供测试使用 **/
#ifdef SH_LANGUAGE_UNIT_TEST
#define SH_UPrivate public
#else
#define SH_UPrivate private
#endif


/** delete宏 */
#define SH_DELETE_PTR(p) {if(p) delete (p);(p)=NULL;}
#define SH_DELETE_ARRAY(p) {if(p) delete[] (p);(p)=NULL;}


#define SH_DEBUG_TIME_BEGIN() long prev_time_clock = clock();\
	long curr_time_clock = prev_time_clock; \
	double use_time_clock = 0;

#define SH_DEBUG_TIME_PRINT(flagStr) 	curr_time_clock = clock();\
	use_time_clock = (double)(curr_time_clock - prev_time_clock) * 1000 / CLOCKS_PER_SEC; \
	std::cout << flagStr << ":" << use_time_clock << "ms" << std::endl; \
	prev_time_clock = curr_time_clock;


#define U_OPTIMIZE 1

#endif