123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #ifndef _SP_COMM_H__
- #define _SP_COMM_H__
- #define _CRTDBG_MAP_ALLOC
- #include <stdlib.h>
- #ifdef RVC_OS_WIN
- #include <crtdbg.h>
- #endif //RVC_OS_WIN
- #include <cstring>
- #include <iostream>
- #include <sstream>
- #include "SpBase.h"
- namespace SP
- {
- //depecrated, to use defined at Module/include/CommEntityUtil.hpp
- struct MachineFormat
- {
- enum Site
- {
- CMB_UNKNOWN,
- CMB_LIB, /** 行内大堂*/
- CMB_FLB, /** 离行机器*/
- };
- #define SITE_ENUM_TYPE(MACRO) \
- MACRO(LIB)\
- MACRO(FLB)
- #define ENUM_MAP_CONVERT(elem) \
- if (stricmp(lpcszSiteName, "CMB."#elem) == 0) return CMB_##elem;
- /*!
- * convert cmb site name to enum type.
- */
- static Site Str2Site(LPCSTR lpcszSiteName)
- {
- if (lpcszSiteName == NULL || strlen(lpcszSiteName) == 0)
- return CMB_UNKNOWN;
- SITE_ENUM_TYPE(ENUM_MAP_CONVERT)
- return CMB_UNKNOWN;
- }
- #undef ENUM_MAP_CONVERT
- #define ENUM_MAP_CONVERT(elem) case CMB_##elem: return "CMB."#elem;
- static LPCSTR Site2Str(Site site) {
- switch (site) {
- SITE_ENUM_TYPE(ENUM_MAP_CONVERT)
- default:
- break;
- }
- return "Unkown";
- }
- enum What
- {
- RVC_UNKNOWN,
- RVC_Stand2S, /** 落地式大机*/
- RVC_Stand1SPlus /** 单屏大机*/
- };
- #define MACHINE_ENUM_TYPE(MACRO) \
- MACRO(Stand2S)\
- MACRO(Stand1SPlus)
- #undef ENUM_MAP_CONVERT
- #define ENUM_MAP_CONVERT(elem) \
- if (stricmp(lpcszTypeName, "RVC."#elem) == 0) return RVC_##elem;
- /*!
- * convert cmb site name to enum type.
- */
- static What Str2Type(LPCSTR lpcszTypeName)
- {
- if (lpcszTypeName == NULL || strlen(lpcszTypeName) == 0)
- return RVC_UNKNOWN;
- MACHINE_ENUM_TYPE(ENUM_MAP_CONVERT)
- return RVC_UNKNOWN;
- }
- #undef ENUM_MAP_CONVERT
- #define ENUM_MAP_CONVERT(elem) case RVC_##elem: return "RVC."#elem;
- static LPCSTR Type2Str(What what) {
- switch (what) {
- MACHINE_ENUM_TYPE(ENUM_MAP_CONVERT)
- default:
- break;
- }
- return "Unkown";
- }
- };
- /** Leak Detector*/
- namespace Perf
- {
- struct LeakDetector
- {
- LeakDetector()
- {
- #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
- int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
- flag |= _CRTDBG_LEAK_CHECK_DF;
- flag |= _CRTDBG_ALLOC_MEM_DF;
- _CrtSetDbgFlag(flag);
- #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
- }
- ~LeakDetector()
- {
- }
- };
- struct LineLeakDetector
- {
- LineLeakDetector() {
- #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
- _CrtMemCheckpoint(&s1);
- #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
- }
- ~LineLeakDetector()
- {
- #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
- _CrtMemCheckpoint(&s2);
- if (_CrtMemDifference(&s3, &s1, &s2))
- _CrtMemDumpStatistics(&s3);
- //_CrtDumpMemoryLeaks();
- #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
- }
- #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
- _CrtMemState s1, s2, s3;
- #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
- };
- }
- }
- #ifdef RVC_OS_WIN
- #define SP_SLEEP(ms) Sleep(ms)
- #else
- #include <unistd.h>
- #define SP_SLEEP(ms) usleep((ms) * 1000)
- #endif
- #ifndef ASSERT
- #include <assert.h>
- #define ASSERT assert
- #endif
- #endif // _SP_COMM_H__
|