GPBBootstrap.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // The Objective C runtime has complete enough info that most protos don’t end
  31. // up using this, so leaving it on is no cost or very little cost. If you
  32. // happen to see it causing bloat, this is the way to disable it. If you do
  33. // need to disable it, try only disabling it for Release builds as having
  34. // full TextFormat can be useful for debugging.
  35. #ifndef GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
  36. #define GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 0
  37. #endif
  38. // Most uses of protocol buffers don't need field options, by default the
  39. // static data will be compiled out, define this to 1 to include it. The only
  40. // time you need this is if you are doing introspection of the protocol buffers.
  41. #ifndef GPBOBJC_INCLUDE_FIELD_OPTIONS
  42. #define GPBOBJC_INCLUDE_FIELD_OPTIONS 0
  43. #endif
  44. // Used in the generated code to give sizes to enums. int32_t was chosen based
  45. // on the fact that Protocol Buffers enums are limited to this range.
  46. // The complexity and double definition here are so we get the nice name
  47. // for objective C, but also define the name with a trailing underscore so
  48. // the Swift bridge will have one where the names line up to support short
  49. // names since they are scoped to the enum.
  50. // https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-XID_11
  51. #define GPB_ENUM(X) enum X##_ : int32_t X; typedef NS_ENUM(int32_t, X##_)
  52. // GPB_ENUM_FWD_DECLARE is used for forward declaring enums ex:
  53. // GPB_ENUM_FWD_DECLARE(Foo_Enum)
  54. // @property (nonatomic) Foo_Enum value;
  55. #define GPB_ENUM_FWD_DECLARE(_name) enum _name : int32_t
  56. // Based upon CF_INLINE. Forces inlining in release.
  57. #if !defined(DEBUG)
  58. #define GPB_INLINE static __inline__ __attribute__((always_inline))
  59. #else
  60. #define GPB_INLINE static __inline__
  61. #endif
  62. // For use in public headers that might need to deal with ARC.
  63. #ifndef GPB_UNSAFE_UNRETAINED
  64. #if __has_feature(objc_arc)
  65. #define GPB_UNSAFE_UNRETAINED __unsafe_unretained
  66. #else
  67. #define GPB_UNSAFE_UNRETAINED
  68. #endif
  69. #endif
  70. // If property name starts with init we need to annotate it to get past ARC.
  71. // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
  72. #define GPB_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
  73. // The protoc-gen-objc version which works with the current version of the
  74. // generated Objective C sources. In general we don't want to change the
  75. // runtime interfaces (or this version) as it means everything has to be
  76. // regenerated.
  77. #define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30000