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.

84 lines
3.0 KiB

6 years ago
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef FIRMessaging_xcodeproj_FIRMessagingDefines_h
  17. #define FIRMessaging_xcodeproj_FIRMessagingDefines_h
  18. #define _FIRMessaging_VERBOSE_LOGGING 1
  19. // Verbose Logging
  20. #if (_FIRMessaging_VERBOSE_LOGGING)
  21. #define FIRMessaging_DEV_VERBOSE_LOG(...) NSLog(__VA_ARGS__)
  22. #else
  23. #define FIRMessaging_DEV_VERBOSE_LOG(...) do { } while (0)
  24. #endif // FIRMessaging_VERBOSE_LOGGING
  25. // WEAKIFY & STRONGIFY
  26. // Helper macro.
  27. #define _FIRMessaging_WEAKNAME(VAR) VAR ## _weak_
  28. #define FIRMessaging_WEAKIFY(VAR) __weak __typeof__(VAR) _FIRMessaging_WEAKNAME(VAR) = (VAR);
  29. #define FIRMessaging_STRONGIFY(VAR) \
  30. _Pragma("clang diagnostic push") \
  31. _Pragma("clang diagnostic ignored \"-Wshadow\"") \
  32. __strong __typeof__(VAR) VAR = _FIRMessaging_WEAKNAME(VAR); \
  33. _Pragma("clang diagnostic pop")
  34. // Type Conversions (used for NSInteger etc)
  35. #ifndef _FIRMessaging_L
  36. #define _FIRMessaging_L(v) (long)(v)
  37. #endif
  38. #ifndef _FIRMessaging_UL
  39. #define _FIRMessaging_UL(v) (unsigned long)(v)
  40. #endif
  41. #endif
  42. // Debug Assert
  43. #ifndef _FIRMessagingDevAssert
  44. // we directly invoke the NSAssert handler so we can pass on the varargs
  45. // (NSAssert doesn't have a macro we can use that takes varargs)
  46. #if !defined(NS_BLOCK_ASSERTIONS)
  47. #define _FIRMessagingDevAssert(condition, ...) \
  48. do { \
  49. if (!(condition)) { \
  50. [[NSAssertionHandler currentHandler] \
  51. handleFailureInFunction:(NSString *) \
  52. [NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
  53. file:(NSString *)[NSString stringWithUTF8String:__FILE__] \
  54. lineNumber:__LINE__ \
  55. description:__VA_ARGS__]; \
  56. } \
  57. } while(0)
  58. #else // !defined(NS_BLOCK_ASSERTIONS)
  59. #define _FIRMessagingDevAssert(condition, ...) do { } while (0)
  60. #endif // !defined(NS_BLOCK_ASSERTIONS)
  61. #endif // _FIRMessagingDevAssert
  62. // Invalidates the initializer from which it's called.
  63. #ifndef FIRMessagingInvalidateInitializer
  64. #define FIRMessagingInvalidateInitializer() \
  65. do { \
  66. [self class]; /* Avoid warning of dead store to |self|. */ \
  67. _FIRMessagingDevAssert(NO, @"Invalid initializer."); \
  68. return nil; \
  69. } while (0)
  70. #endif