osMacros.h
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
00082
00083
00084 #define ForAllIter(p,listIter,type) \
00085 for(listIter.setFirst(),p=(type)listIter.getCurrentItem();!listIter.isDone();\
00086 listIter.setNext(),p=(type)listIter.getCurrentItem())
00087
00088 #define ForAllIterRev(p,listIter,type) \
00089 for(listIter.setLast(),p=(type)listIter.getCurrentItem();!listIter.isDone();\
00090 listIter.setPrev(),p=(type)listIter.getCurrentItem())
00091
00092
00093
00094 #define OSUTF8CHAR_SIZE 1
00095
00096
00097
00098 #include <stdio.h>
00099 #include <stdarg.h>
00100
00101 #if defined(_MSC_VER)
00102 # if _MSC_VER >= 1400
00103 # define os_snprintf(str, size, ...) \
00104 _snprintf_s(str, size, _TRUNCATE, __VA_ARGS__)
00105 # define os_vsnprintf(str, size, fmt, ...) \
00106 _vsnprintf_s(str, size, _TRUNCATE, fmt, __VA_ARGS__)
00107 # else
00108 # define os_snprintf _snprintf
00109 # define os_vsnprintf _vsnprintf
00110 # endif
00111 #elif defined(__HP_aCC)
00112
00113 # define os_snprintf(str, size, ...) sprintf(str, __VA_ARGS__)
00114 # define os_vsnprintf(str, size, fmt, ...) \
00115 vsnprintf(str, size, (char *)fmt, __VA_ARGS__)
00116 #elif defined(_NO_SNPRINTF_) && !defined(__vxworks) && !defined (__SYMBIAN32__)
00117 #define os_snprintf(str, size, ...) sprintf(str, __VA_ARGS__)
00118 #define os_vsnprintf(str, size, fmt, ...) vsprintf(str, fmt, __VA_ARGS__)
00119
00120 #elif defined(__vxworks) || defined(__SYMBIAN32__)
00121 #define os_snprintf(str,size,ARGS...) sprintf(str,##ARGS)
00122 #define os_vsnprintf(str,size,fmt,ARGS...) vsprintf(str,fmt,##ARGS)
00123 #else
00124 #define os_snprintf snprintf
00125 #define os_vsnprintf vsnprintf
00126 #endif
00127
00128 #endif
00129