libcm is a C development framework with an emphasis on audio signal processing applications.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

cmGlobal.h 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //{
  2. //(
  3. // cmGlobal.h contains the global macros, header files, and
  4. // typedefs availale to all other cm modules.
  5. //
  6. // All operating system dependencies should be resolved in this file via
  7. // testing for OS_LINUX, OS_OSX, or OS_W32.
  8. //)
  9. #ifndef cmGlobal_h
  10. #define cmGlobal_h
  11. //(
  12. #include "config.h" // created by 'configure'
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <assert.h>
  17. #include <stdbool.h>
  18. #include <stdarg.h>
  19. #include <math.h>
  20. #include <ctype.h>
  21. #include <errno.h>
  22. #include <float.h>
  23. #include <limits.h>
  24. #include <signal.h>
  25. #include <time.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #define CM_FLOAT_SMP 1 //< make cmSample_t = float in cmFloatTypes.h
  30. #define CM_FLOAT_REAL 0 //< make cmReal_t = double in cmFloatTypes.h
  31. #ifdef NDEBUG
  32. #define cmDEBUG_FL 0 //< Define cmDEBUG_FL as 0 when building in release mode. See \ref debug_mode.
  33. #else
  34. #define cmDEBUG_FL 1 //< Define cmDEBUG_FL as 1 when building in debug mode. See \ref debug_mode.
  35. #endif
  36. // Perform byte swapping on 16 bit values.
  37. #define cmSwap16(x) \
  38. (((((unsigned short)(x)) & 0x00ff) << 8) | ((((unsigned short)(x)) & 0xff00) >> 8))
  39. #ifdef OS_LINUX
  40. #include <byteswap.h> // gcc specific
  41. #include <unistd.h>
  42. // Perform byte swapping on 32 bit values on systems were <byteswap.h> is available.
  43. #define cmSwap32(x) (bswap_32(x))
  44. // Perform byte swapping on 64 bit values on systems were <byteswap.h> is available.
  45. #define cmSwap64(x) (bswap_64(x))
  46. #endif
  47. #ifdef OS_OSX
  48. #include <unistd.h>
  49. // Perform byte swapping on 32 bit values on systems were <byteswap.h> is not available.
  50. #define cmSwap32(x) \
  51. ((((unsigned)((x) & 0x000000FF)) << 24) | \
  52. (((unsigned)((x) & 0x0000FF00)) << 8) | \
  53. (((unsigned)((x) & 0x00FF0000)) >> 8) | \
  54. (((unsigned)((x) & 0xFF000000)) >> 24))
  55. // Perform byte swapping on 64 bit values on systems were <byteswap.h> is not available.
  56. #define cmSwap64(x) \
  57. (((((unsigned long long)(x))<<56) & 0xFF00000000000000ULL) | \
  58. ((((unsigned long long)(x))<<40) & 0x00FF000000000000ULL) | \
  59. ((((unsigned long long)(x))<<24) & 0x0000FF0000000000ULL) | \
  60. ((((unsigned long long)(x))<< 8) & 0x000000FF00000000ULL) | \
  61. ((((unsigned long long)(x))>> 8) & 0x00000000FF000000ULL) | \
  62. ((((unsigned long long)(x))>>24) & 0x0000000000FF0000ULL) | \
  63. ((((unsigned long long)(x))>>40) & 0x000000000000FF00ULL) | \
  64. ((((unsigned long long)(x))>>56) & 0x00000000000000FFULL))
  65. #endif
  66. #define cmAllFlags(f,m) (((f) & (m)) == (m)) //< Test if all of a group 'm' of binary flags in 'f' are set.
  67. #define cmIsFlag(f,m) (((f) & (m)) ? true : false) //< Test if any one of a the bits in 'm' is also set in 'f'.
  68. #define cmIsNotFlag(f,m) (cmIsFlag(f,m)==false) //< Test if none of the bits in 'm' are set in 'f'.
  69. #define cmSetFlag(f,m) ((f) | (m)) //< Return 'f' with the bits in 'm' set.
  70. #define cmClrFlag(f,m) ((f) & (~(m))) //< Return 'f' with the bits in 'm' cleared.
  71. #define cmTogFlag(f,m) ((f)^(m)) //< Return 'f' with the bits in 'm' toggled.
  72. #define cmEnaFlag(f,m,b) (b) ? cmSetFlag(f,m) : cmClrFlag(f,m) //< \brief Set or clear bits in 'f' based on bits in 'm' and the state of 'b'.
  73. //<
  74. //< If 'b' == 0 then return 'f' with the bits in 'm' cleared.
  75. //< otherwise return 'f' with the bits in 'm' set.
  76. #define cmMin(v0,v1) ((v0)<(v1) ? (v0) : (v1)) //< Return the minimum arg.
  77. #define cmMax(v0,v1) ((v0)>(v1) ? (v0) : (v1)) //< Return the maximum arg.
  78. #define cmStringNullGuard(p) ((p)==NULL?"<null>":(p)) //< If 'p'==NULL return the static string "<null>" otherwise return 'p'.
  79. #define cmStringLen(s) ((s)==NULL? 0 : strlen(s))
  80. // Default return code indicating successful function completion.
  81. #define cmOkRC (0)
  82. // Default directory separator character for unix based systems.
  83. #define cmPathSeparatorChar ("/")
  84. #define cmInvalidIdx (0xffffffff) //< cm wide value indicating a invalid or NULL index.
  85. #define cmInvalidId (cmInvalidIdx) //< cm wide value indicating an invalid or NULL numeric id.
  86. #define cmInvalidCnt (cmInvalidIdx) //< cm wide value indicating a invalid or NULL count of items.
  87. #define cmSTATIC_NULL_HANDLE {NULL} //< Default NULL value for cmHandle_t
  88. // Generic data type for implementing opaque object handles.
  89. /*
  90. typedef struct cmHandle_str
  91. {
  92. void* h;
  93. } cmHandle_t;
  94. */
  95. #define cmHandle_t struct { void* h; }
  96. #define cmHandlesAreEqual( a, b ) ((a).h == (b).h) //< Test if two cmHandle_t values are equivalent.
  97. #define cmHandlesAreNotEqual( a, b ) (!cmHandlesAreEqual(a,b)) //< Test if two cmHandle_t value are not equivalent.
  98. // Data type commonly used as a function return value. Functions returning cmRC_t values
  99. // return cmOkRC (0) to indicate successful completion or some other value to indicate
  100. // some kind of exceptional conidtion. In general the condition indicates an unexpected condition
  101. // such as resource exhaution, or a missing file.
  102. typedef unsigned cmRC_t;
  103. // A data type which indicates a system dependent error. This is generally an abstraction for an 'errno'
  104. // like code.
  105. typedef int cmSysErrCode_t; // same as errno
  106. // cmChar_t is a data type used to indicate that a char is being used to hold human readable
  107. // text. Eventually this type will be used to locate and handle unicode based strings.
  108. typedef char cmChar_t;
  109. typedef unsigned int cmUInt32_t; //< This typedef is used to indicate that the type must be an unsigned 32 bit integer.
  110. typedef unsigned short cmUInt16_t; //< This typedef is used to indicate that hte type must be an unsigned 16 bit integer.
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. //)
  115. //}
  116. #endif