• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 // Author: kenton@google.com (Kenton Varda) and others
9 //
10 // Contains basic types and utilities used by the rest of the library.
11 
12 #ifndef GOOGLE_PROTOBUF_COMMON_H__
13 #define GOOGLE_PROTOBUF_COMMON_H__
14 
15 #include <algorithm>
16 #include <iostream>
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 #include "absl/strings/string_view.h"
22 #include "google/protobuf/stubs/platform_macros.h"
23 #include "google/protobuf/stubs/port.h"
24 
25 #if defined(__APPLE__)
26 #include <TargetConditionals.h>  // for TARGET_OS_IPHONE
27 #endif
28 
29 #if defined(__ANDROID__) || defined(GOOGLE_PROTOBUF_OS_ANDROID) || \
30     (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) ||             \
31     defined(GOOGLE_PROTOBUF_OS_IPHONE)
32 #include <pthread.h>
33 #endif
34 
35 #include "google/protobuf/port_def.inc"
36 
37 namespace std {}
38 
39 namespace google {
40 namespace protobuf {
41 namespace internal {
42 
43 // Some of these constants are macros rather than const ints so that they can
44 // be used in #if directives.
45 
46 // The current version, represented as a single integer to make comparison
47 // easier:  major * 10^6 + minor * 10^3 + micro
48 #define GOOGLE_PROTOBUF_VERSION 5029004
49 
50 // A suffix string for alpha, beta or rc releases. Empty for stable releases.
51 #define GOOGLE_PROTOBUF_VERSION_SUFFIX ""
52 
53 // Verifies that the protobuf version a program was compiled with matches what
54 // it is linked/running with. Use the macro below to call this function.
55 void PROTOBUF_EXPORT VerifyVersion(int protobufVersionCompiledWith,
56                                    const char* filename);
57 
58 // Converts a numeric version number to a string.
59 std::string PROTOBUF_EXPORT
60 VersionString(int version);  // NOLINT(runtime/string)
61 
62 // Prints the protoc compiler version (no major version)
63 std::string PROTOBUF_EXPORT
64 ProtocVersionString(int version);  // NOLINT(runtime/string)
65 
66 }  // namespace internal
67 
68 // Place this macro in your main() function (or somewhere before you attempt
69 // to use the protobuf library) to verify that the version you link against
70 // matches the headers you compiled against.  If a version mismatch is
71 // detected, the process will abort.
72 #define GOOGLE_PROTOBUF_VERIFY_VERSION \
73   ::google::protobuf::internal::VerifyVersion(GOOGLE_PROTOBUF_VERSION, __FILE__)
74 
75 // This lives in message_lite.h now, but we leave this here for any users that
76 // #include common.h and not message_lite.h.
77 PROTOBUF_EXPORT void ShutdownProtobufLibrary();
78 
79 namespace internal {
80 
81 // Strongly references the given variable such that the linker will be forced
82 // to pull in this variable's translation unit.
83 template <typename T>
StrongReference(const T & var)84 void StrongReference(const T& var) {
85   auto volatile unused = &var;
86   (void)&unused;  // Use address to avoid an extra load of "unused".
87 }
88 
89 }  // namespace internal
90 }  // namespace protobuf
91 }  // namespace google
92 
93 #include "google/protobuf/port_undef.inc"
94 
95 #endif  // GOOGLE_PROTOBUF_COMMON_H__
96