libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmGlobal.h 6.5KB

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