libcm is a C development framework with an emphasis on audio signal processing applications.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

cmGlobal.h 5.9KB

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