Platform.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCOREPLATFORM_H
  28. #define ROCKETCOREPLATFORM_H
  29. #if defined __WIN32__ || defined _WIN32
  30. #define ROCKET_PLATFORM_WIN32
  31. #define ROCKET_PLATFORM_NAME "win32"
  32. #if !defined(__MINGW32__)
  33. #pragma warning(disable:4355)
  34. #endif
  35. #elif defined __APPLE_CC__
  36. #define ROCKET_PLATFORM_UNIX
  37. #define ROCKET_PLATFORM_MACOSX
  38. #define ROCKET_PLATFORM_NAME "macosx"
  39. #else
  40. #define ROCKET_PLATFORM_UNIX
  41. #define ROCKET_PLATFORM_LINUX
  42. #define ROCKET_PLATFORM_NAME "linux"
  43. #endif
  44. #if !defined NDEBUG && !defined ROCKET_DEBUG
  45. #define ROCKET_DEBUG
  46. #endif
  47. #if defined __LP64__ || defined _M_X64 || defined __MINGW64__ || defined _LP64
  48. #define ROCKET_ARCH_64
  49. #else
  50. #define ROCKET_ARCH_32
  51. #endif
  52. #if defined(ROCKET_PLATFORM_WIN32) && !defined(__MINGW32__)
  53. // alignment of a member was sensitive to packing
  54. #pragma warning(disable : 4121)
  55. // <type> needs to have dll-interface to be used by clients
  56. #pragma warning(disable : 4251)
  57. // assignment operator could not be generated
  58. #pragma warning(disable : 4512)
  59. // <function> was declared deprecated
  60. #pragma warning(disable : 4996)
  61. #if !defined _CRT_SECURE_NO_DEPRECATE
  62. #define _CRT_SECURE_NO_DEPRECATE
  63. #endif
  64. #endif
  65. // Wraps unused variables in methods or functions to avoid compiler warnings. This should
  66. // be wrapped around the name of all parameters that are wrapped with ROCKET_UNUSED_PARAMETER
  67. // to cover warnings generated by non-llvm/gcc style compilers that can't be covered with
  68. // ROCKET_UNUSED_PARAMETER
  69. #if defined __llvm__
  70. //# define ROCKET_UNUSED(x) UNUSED_ ## x __unused
  71. # define ROCKET_UNUSED(x)
  72. #elif defined __GNUC__
  73. //# define ROCKET_UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
  74. # define ROCKET_UNUSED(x)
  75. #else
  76. # define ROCKET_UNUSED(x) (void)(UNUSED_ ## x)
  77. #endif
  78. // Wraps unused parameter names in method or function declarations. When used, the first lines
  79. // of the function should contain a matching ROCKET_UNUSED call with the name of the function
  80. // as well to cover compilers with no-op ROCKET_UNUSED_PARAMETER macros.
  81. #if defined __llvm__
  82. # define ROCKET_UNUSED_PARAMETER(x) UNUSED_ ## x __attribute__((unused))
  83. #elif defined __GNUC__
  84. # define ROCKET_UNUSED_PARAMETER(x) UNUSED_ ## x __attribute__((__unused__))
  85. #else
  86. # define ROCKET_UNUSED_PARAMETER(x) UNUSED_ ## x
  87. #endif
  88. // ROCKET_UNUSED_ASSERT_PARAMETERS wraps method parameters which are not used in the method other than
  89. // by a ROCKET_ASSERT check. This safely deals with debug versus release mode configurations
  90. // and will warn if the parameter starts being used when compiled with GCC
  91. #ifdef ROCKET_DEBUG
  92. // In this case, the parameter is used by a ROCKET_ASSERT test, so we just pass through as is
  93. # define ROCKET_UNUSED_ASSERT_PARAMETER(x) x
  94. # define ROCKET_UNUSED_ASSERT(x)
  95. #else
  96. // If not in DEBUG builds, this parameter is unused, mark it as such
  97. # if defined __llvm__
  98. # define ROCKET_UNUSED_ASSERT_PARAMETER(x) UNUSED_ ## x __attribute__((unused))
  99. # define ROCKET_UNUSED_ASSERT(x)
  100. # elif defined __GNUC__
  101. # define ROCKET_UNUSED_ASSERT_PARAMETER(x) UNUSED_ ## x __attribute__((__unused__))
  102. # define ROCKET_UNUSED_ASSERT(x)
  103. # else
  104. # define ROCKET_UNUSED_ASSERT_PARAMETER(x) UNUSED_ ## x
  105. # define ROCKET_UNUSED_ASSERT(x) (void)(UNUSED_ ## x)
  106. # endif
  107. #endif
  108. // Wraps functions which are not referenced or exported to avoid compiler warnings
  109. #if defined __llvm__
  110. # define ROCKET_UNUSED_FUNCTION(x) __attribute__((unused)) UNUSED_ ## x
  111. #elif defined __GNUC__
  112. # define ROCKET_UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_ ## x
  113. #else
  114. # define ROCKET_UNUSED_FUNCTION(x) UNUSED_ ## x
  115. #endif
  116. // Squelchs warnings for unused enums in switch statements, this should only be used for special values
  117. // that are known to NEVER be used.
  118. #define ROCKET_UNUSED_SWITCH_ENUM(x) \
  119. case x: \
  120. ROCKET_ERRORMSG("Switch case for unhandled ENUM has been hit! This shouldn't happen! ENUM Name: " # x); \
  121. break;
  122. #endif