00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _OSMACROS_H_
00026 #define _OSMACROS_H_
00027
00028 #if defined(_MSC_VER)
00029
00030
00031 #pragma warning(disable: 4127)
00032 #endif
00033
00034
00035 #define OS_CHECKED_GET(objptr,getmethod) \
00036 (0 == objptr) ? 0 : (objptr)->getmethod()
00037
00038
00039 #define OS_MAX(a,b) (((a)>(b))?(a):(b))
00040 #define OS_MIN(a,b) (((a)<(b))?(a):(b))
00041
00042
00043 #define OS_ISHEXCHAR(c) \
00044 ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
00045
00046
00047 #define OS_ISPRINTABLE(c) \
00048 (c >= 0x20 && c <= 0x7e)
00049
00050
00051 #define OS_ISEMPTY(s) (s == 0 || *s == '\0')
00052
00053
00054 #define OS_HEXCHARTONIBBLE(ch,b) do { \
00055 if (ch >= '0' && ch <= '9') b = (unsigned char)(ch - '0'); \
00056 else if (ch >= 'a' && ch <= 'f') b = (unsigned char)((ch - 'a') + 10); \
00057 else if (ch >= 'A' && ch <= 'F') b = (unsigned char)((ch - 'A') + 10); \
00058 else b = 0xFF; } while(0)
00059
00060 #define OS_NIBBLETOHEXCHAR(b,ch) do { \
00061 if (b >= 0 && b <= 9) ch = (char)(b + '0'); \
00062 else if (b >= 0x0a && b <= 0x0f) ch = (char)((b - 10)+ 'a'); \
00063 else ch = '?'; } while(0)
00064
00070 #define OSRTARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
00071
00075 #define OSUTF8(str) ((const OSUTF8CHAR*)str)
00076
00080 #define OSUTF8LEN(str) strlen((const char*)str)
00081
00087 #define OS_UNUSED_ARG(arg) (void)arg
00088
00089
00090
00091 #define ForAllIter(p,listIter,type) \
00092 for(listIter.setFirst(),p=(type)listIter.getCurrentItem();!listIter.isDone();\
00093 listIter.setNext(),p=(type)listIter.getCurrentItem())
00094
00095 #define ForAllIterRev(p,listIter,type) \
00096 for(listIter.setLast(),p=(type)listIter.getCurrentItem();!listIter.isDone();\
00097 listIter.setPrev(),p=(type)listIter.getCurrentItem())
00098
00099
00100
00101
00102
00103
00104 #define DeleteListContents(pList,objectType) \
00105 if (pList) { while((pList)->getHead()) delete (objectType*) (pList)->deleteHead(); }
00106
00107
00108
00109
00110 #define OSUTF8CHAR_SIZE 1
00111
00112
00113
00114 #include <stdio.h>
00115 #include <stdarg.h>
00116
00117 #if defined(_MSC_VER) && !defined(_NO_SNPRINTF_)
00118 # if _MSC_VER >= 1400
00119 # define os_snprintf(str, size, ...) \
00120 _snprintf_s(str, size, _TRUNCATE, __VA_ARGS__)
00121 # define os_vsnprintf(str, size, fmt, ...) \
00122 _vsnprintf_s(str, size, _TRUNCATE, fmt, __VA_ARGS__)
00123 # elif defined(_SHX_) && !defined(CPP)
00124 # define os_snprintf StringCbPrintfA
00125 # define os_vsnprintf StringCbVPrintf
00126 # define strcat(s,d) StringCbCatA(s,strlen(s),d)
00127 # define strcpy(s,d) StringCbCopyA(s,strlen(s),d)
00128 # else
00129 # define os_snprintf _snprintf
00130 # define os_vsnprintf _vsnprintf
00131 # endif
00132 #elif defined(__HP_aCC)
00133
00134 # define os_snprintf(str, size, ...) snprintf(str, size, __VA_ARGS__)
00135 # define os_vsnprintf(str, size, fmt, ...) \
00136 vsnprintf(str, size, (char *)fmt, __VA_ARGS__)
00137 #elif defined(_NO_SNPRINTF_) && !defined(__vxworks) && !defined (__SYMBIAN32__)
00138 #define os_snprintf(str, size, ...) sprintf(str, __VA_ARGS__)
00139 #define os_vsnprintf(str, size, fmt, ...) vsprintf(str, fmt, __VA_ARGS__)
00140
00141 #elif defined(__vxworks) || defined(__SYMBIAN32__)
00142 #define os_snprintf(str,size,ARGS...) sprintf(str,##ARGS)
00143 #define os_vsnprintf(str,size,fmt,ARGS...) vsprintf(str,fmt,##ARGS)
00144 #else
00145 #define os_snprintf snprintf
00146 #define os_vsnprintf vsnprintf
00147 #endif
00148
00149 #endif