诸暨麻将添加redis
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.
 
 
 
 
 
 

230 lines
8.5 KiB

  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. // Author: kenton@google.com (Kenton Varda) and others
  31. //
  32. // Contains basic types and utilities used by the rest of the library.
  33. #ifndef GOOGLE_PROTOBUF_COMMON_H__
  34. #define GOOGLE_PROTOBUF_COMMON_H__
  35. #include <algorithm>
  36. #include <iostream>
  37. #include <map>
  38. #include <memory>
  39. #include <set>
  40. #include <string>
  41. #include <vector>
  42. #include <google/protobuf/stubs/port.h>
  43. #include <google/protobuf/stubs/macros.h>
  44. #include <google/protobuf/stubs/platform_macros.h>
  45. #ifndef PROTOBUF_USE_EXCEPTIONS
  46. #if defined(_MSC_VER) && defined(_CPPUNWIND)
  47. #define PROTOBUF_USE_EXCEPTIONS 1
  48. #elif defined(__EXCEPTIONS)
  49. #define PROTOBUF_USE_EXCEPTIONS 1
  50. #else
  51. #define PROTOBUF_USE_EXCEPTIONS 0
  52. #endif
  53. #endif
  54. #if PROTOBUF_USE_EXCEPTIONS
  55. #include <exception>
  56. #endif
  57. #if defined(__APPLE__)
  58. #include <TargetConditionals.h> // for TARGET_OS_IPHONE
  59. #endif
  60. #if defined(__ANDROID__) || defined(GOOGLE_PROTOBUF_OS_ANDROID) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || defined(GOOGLE_PROTOBUF_OS_IPHONE)
  61. #include <pthread.h>
  62. #endif
  63. #include <google/protobuf/port_def.inc>
  64. namespace std {}
  65. namespace google {
  66. namespace protobuf {
  67. namespace internal {
  68. // Some of these constants are macros rather than const ints so that they can
  69. // be used in #if directives.
  70. // The current version, represented as a single integer to make comparison
  71. // easier: major * 10^6 + minor * 10^3 + micro
  72. #define GOOGLE_PROTOBUF_VERSION 3011000
  73. // A suffix string for alpha, beta or rc releases. Empty for stable releases.
  74. #define GOOGLE_PROTOBUF_VERSION_SUFFIX ""
  75. // The minimum header version which works with the current version of
  76. // the library. This constant should only be used by protoc's C++ code
  77. // generator.
  78. static const int kMinHeaderVersionForLibrary = 3011000;
  79. // The minimum protoc version which works with the current version of the
  80. // headers.
  81. #define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3011000
  82. // The minimum header version which works with the current version of
  83. // protoc. This constant should only be used in VerifyVersion().
  84. static const int kMinHeaderVersionForProtoc = 3011000;
  85. // Verifies that the headers and libraries are compatible. Use the macro
  86. // below to call this.
  87. void PROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion,
  88. const char* filename);
  89. // Converts a numeric version number to a string.
  90. std::string PROTOBUF_EXPORT VersionString(int version);
  91. } // namespace internal
  92. // Place this macro in your main() function (or somewhere before you attempt
  93. // to use the protobuf library) to verify that the version you link against
  94. // matches the headers you compiled against. If a version mismatch is
  95. // detected, the process will abort.
  96. #define GOOGLE_PROTOBUF_VERIFY_VERSION \
  97. ::google::protobuf::internal::VerifyVersion( \
  98. GOOGLE_PROTOBUF_VERSION, GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION, \
  99. __FILE__)
  100. // ===================================================================
  101. // from google3/util/utf8/public/unilib.h
  102. class StringPiece;
  103. namespace internal {
  104. // Checks if the buffer contains structurally-valid UTF-8. Implemented in
  105. // structurally_valid.cc.
  106. PROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len);
  107. inline bool IsStructurallyValidUTF8(const std::string& str) {
  108. return IsStructurallyValidUTF8(str.data(), static_cast<int>(str.length()));
  109. }
  110. // Returns initial number of bytes of structually valid UTF-8.
  111. PROTOBUF_EXPORT int UTF8SpnStructurallyValid(const StringPiece& str);
  112. // Coerce UTF-8 byte string in src_str to be
  113. // a structurally-valid equal-length string by selectively
  114. // overwriting illegal bytes with replace_char (typically ' ' or '?').
  115. // replace_char must be legal printable 7-bit Ascii 0x20..0x7e.
  116. // src_str is read-only.
  117. //
  118. // Returns pointer to output buffer, src_str.data() if no changes were made,
  119. // or idst if some bytes were changed. idst is allocated by the caller
  120. // and must be at least as big as src_str
  121. //
  122. // Optimized for: all structurally valid and no byte copying is done.
  123. //
  124. PROTOBUF_EXPORT char* UTF8CoerceToStructurallyValid(const StringPiece& str,
  125. char* dst,
  126. char replace_char);
  127. } // namespace internal
  128. // ===================================================================
  129. // Shutdown support.
  130. // Shut down the entire protocol buffers library, deleting all static-duration
  131. // objects allocated by the library or by generated .pb.cc files.
  132. //
  133. // There are two reasons you might want to call this:
  134. // * You use a draconian definition of "memory leak" in which you expect
  135. // every single malloc() to have a corresponding free(), even for objects
  136. // which live until program exit.
  137. // * You are writing a dynamically-loaded library which needs to clean up
  138. // after itself when the library is unloaded.
  139. //
  140. // It is safe to call this multiple times. However, it is not safe to use
  141. // any other part of the protocol buffers library after
  142. // ShutdownProtobufLibrary() has been called. Furthermore this call is not
  143. // thread safe, user needs to synchronize multiple calls.
  144. PROTOBUF_EXPORT void ShutdownProtobufLibrary();
  145. namespace internal {
  146. // Register a function to be called when ShutdownProtocolBuffers() is called.
  147. PROTOBUF_EXPORT void OnShutdown(void (*func)());
  148. // Run an arbitrary function on an arg
  149. PROTOBUF_EXPORT void OnShutdownRun(void (*f)(const void*), const void* arg);
  150. template <typename T>
  151. T* OnShutdownDelete(T* p) {
  152. OnShutdownRun([](const void* pp) { delete static_cast<const T*>(pp); }, p);
  153. return p;
  154. }
  155. // Strongly references the given variable such that the linker will be forced
  156. // to pull in this variable's translation unit.
  157. template <typename T>
  158. void StrongReference(const T& var) {
  159. auto volatile unused = &var;
  160. (void)&unused; // Use address to avoid an extra load of "unused".
  161. }
  162. } // namespace internal
  163. #if PROTOBUF_USE_EXCEPTIONS
  164. class FatalException : public std::exception {
  165. public:
  166. FatalException(const char* filename, int line, const std::string& message)
  167. : filename_(filename), line_(line), message_(message) {}
  168. virtual ~FatalException() throw();
  169. virtual const char* what() const throw();
  170. const char* filename() const { return filename_; }
  171. int line() const { return line_; }
  172. const std::string& message() const { return message_; }
  173. private:
  174. const char* filename_;
  175. const int line_;
  176. const std::string message_;
  177. };
  178. #endif
  179. // This is at the end of the file instead of the beginning to work around a bug
  180. // in some versions of MSVC.
  181. using std::string;
  182. } // namespace protobuf
  183. } // namespace google
  184. #include <google/protobuf/port_undef.inc>
  185. #endif // GOOGLE_PROTOBUF_COMMON_H__