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.

165 lines
5.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2004 Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef TALK_BASE_COMMON_H_
  28. #define TALK_BASE_COMMON_H_
  29. #include "talk/base/basictypes.h"
  30. #include "talk/base/constructormagic.h"
  31. #if defined(_MSC_VER)
  32. // warning C4355: 'this' : used in base member initializer list
  33. #pragma warning(disable:4355)
  34. #endif
  35. //////////////////////////////////////////////////////////////////////
  36. // General Utilities
  37. //////////////////////////////////////////////////////////////////////
  38. // Note: UNUSED is also defined in basictypes.h
  39. #ifndef UNUSED
  40. #define UNUSED(x) Unused(static_cast<const void*>(&x))
  41. #define UNUSED2(x, y) Unused(static_cast<const void*>(&x)); \
  42. Unused(static_cast<const void*>(&y))
  43. #define UNUSED3(x, y, z) Unused(static_cast<const void*>(&x)); \
  44. Unused(static_cast<const void*>(&y)); \
  45. Unused(static_cast<const void*>(&z))
  46. #define UNUSED4(x, y, z, a) Unused(static_cast<const void*>(&x)); \
  47. Unused(static_cast<const void*>(&y)); \
  48. Unused(static_cast<const void*>(&z)); \
  49. Unused(static_cast<const void*>(&a))
  50. #define UNUSED5(x, y, z, a, b) Unused(static_cast<const void*>(&x)); \
  51. Unused(static_cast<const void*>(&y)); \
  52. Unused(static_cast<const void*>(&z)); \
  53. Unused(static_cast<const void*>(&a)); \
  54. Unused(static_cast<const void*>(&b))
  55. inline void Unused(const void*) {}
  56. #endif // UNUSED
  57. #ifndef WIN32
  58. #define strnicmp(x, y, n) strncasecmp(x, y, n)
  59. #define stricmp(x, y) strcasecmp(x, y)
  60. // TODO: Remove this. std::max should be used everywhere in the code.
  61. // NOMINMAX must be defined where we include <windows.h>.
  62. #define stdmax(x, y) std::max(x, y)
  63. #else
  64. #define stdmax(x, y) talk_base::_max(x, y)
  65. #endif
  66. #define ARRAY_SIZE(x) (static_cast<int>(sizeof(x) / sizeof(x[0])))
  67. /////////////////////////////////////////////////////////////////////////////
  68. // Assertions
  69. /////////////////////////////////////////////////////////////////////////////
  70. #ifndef ENABLE_DEBUG
  71. #define ENABLE_DEBUG _DEBUG
  72. #endif // !defined(ENABLE_DEBUG)
  73. #if ENABLE_DEBUG
  74. namespace talk_base {
  75. // Break causes the debugger to stop executing, or the program to abort
  76. void Break();
  77. // LogAssert writes information about an assertion to the log
  78. void LogAssert(const char* function, const char* file, int line,
  79. const char* expression);
  80. inline bool Assert(bool result, const char* function, const char* file,
  81. int line, const char* expression) {
  82. if (!result) {
  83. LogAssert(function, file, line, expression);
  84. Break();
  85. return false;
  86. }
  87. return true;
  88. }
  89. } // namespace talk_base
  90. #if defined(_MSC_VER) && _MSC_VER < 1300
  91. #define __FUNCTION__ ""
  92. #endif
  93. #ifndef ASSERT
  94. #define ASSERT(x) \
  95. (void)talk_base::Assert((x), __FUNCTION__, __FILE__, __LINE__, #x)
  96. #endif
  97. #ifndef VERIFY
  98. #define VERIFY(x) talk_base::Assert((x), __FUNCTION__, __FILE__, __LINE__, #x)
  99. #endif
  100. #else // !ENABLE_DEBUG
  101. namespace talk_base {
  102. inline bool ImplicitCastToBool(bool result) { return result; }
  103. } // namespace talk_base
  104. #ifndef ASSERT
  105. #define ASSERT(x) (void)0
  106. #endif
  107. #ifndef VERIFY
  108. #define VERIFY(x) talk_base::ImplicitCastToBool(x)
  109. #endif
  110. #endif // !ENABLE_DEBUG
  111. #define COMPILE_TIME_ASSERT(expr) char CTA_UNIQUE_NAME[expr]
  112. #define CTA_UNIQUE_NAME CTA_MAKE_NAME(__LINE__)
  113. #define CTA_MAKE_NAME(line) CTA_MAKE_NAME2(line)
  114. #define CTA_MAKE_NAME2(line) constraint_ ## line
  115. // Forces compiler to inline, even against its better judgement. Use wisely.
  116. #if defined(__GNUC__)
  117. #define FORCE_INLINE __attribute__((always_inline))
  118. #elif defined(WIN32)
  119. #define FORCE_INLINE __forceinline
  120. #else
  121. #define FORCE_INLINE
  122. #endif
  123. // Borrowed from Chromium's base/compiler_specific.h.
  124. // Annotate a virtual method indicating it must be overriding a virtual
  125. // method in the parent class.
  126. // Use like:
  127. // virtual void foo() OVERRIDE;
  128. #if defined(WIN32)
  129. #define OVERRIDE override
  130. #elif defined(__clang__)
  131. #define OVERRIDE override
  132. #else
  133. #define OVERRIDE
  134. #endif
  135. #endif // TALK_BASE_COMMON_H_