Google Cloud C++ Client  2.7.0
C++ Client Library for Google Cloud Platform
version.h
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_VERSION_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_VERSION_H
17 
18 #include "google/cloud/internal/attributes.h"
19 #include "google/cloud/internal/port_platform.h"
20 #include "google/cloud/internal/version_info.h"
21 #include <string>
22 
23 #define GOOGLE_CLOUD_CPP_VCONCAT(Ma, Mi, Pa) v##Ma##_##Mi##_##Pa
24 #define GOOGLE_CLOUD_CPP_VEVAL(Ma, Mi, Pa) GOOGLE_CLOUD_CPP_VCONCAT(Ma, Mi, Pa)
25 #define GOOGLE_CLOUD_CPP_NS
26  GOOGLE_CLOUD_CPP_VEVAL(GOOGLE_CLOUD_CPP_VERSION_MAJOR,
27  GOOGLE_CLOUD_CPP_VERSION_MINOR,
28  GOOGLE_CLOUD_CPP_VERSION_PATCH)
29 
30 /**
31  * Versioned inline namespace that users should generally avoid spelling.
32  *
33  * The actual inline namespace name will change with each release, and if you
34  * use it your code will be tightly coupled to a specific release. Omitting the
35  * inline namespace name will make upgrading to newer releases easier.
36  *
37  * However, applications may need to link multiple versions of the Google Cloud
38  * C++ Libraries, for example, if they link a library that uses an older
39  * version of the libraries than they do. This namespace is inlined, so
40  * applications can use `google::cloud::Foo` in their source, but the symbols
41  * are versioned, i.e., the symbol becomes `google::cloud::vXYZ::Foo`.
42  */
43 #define GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
44  inline namespace GOOGLE_CLOUD_CPP_NS {
45 #define GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
46  } /* namespace GOOGLE_CLOUD_CPP_NS */
47 
48 // This preprocessor symbol is deprecated and should never be used anywhere. It
49 // exists solely for backward compatibility to avoid breaking anyone who may
50 // have been using it.
51 #define GOOGLE_CLOUD_CPP_GENERATED_NS GOOGLE_CLOUD_CPP_NS
52 
53 namespace google {
54 /**
55  * Contains all the Google Cloud C++ Library APIs.
56  */
57 namespace cloud {
59 
60 /**
61  * The Google Cloud C++ Client major version.
62  *
63  * @see https://semver.org/spec/v2.0.0.html for details.
64  */
65 int constexpr version_major() { return GOOGLE_CLOUD_CPP_VERSION_MAJOR; }
66 
67 /**
68  * The Google Cloud C++ Client minor version.
69  *
70  * @see https://semver.org/spec/v2.0.0.html for details.
71  */
72 int constexpr version_minor() { return GOOGLE_CLOUD_CPP_VERSION_MINOR; }
73 
74 /**
75  * The Google Cloud C++ Client patch version.
76  *
77  * @see https://semver.org/spec/v2.0.0.html for details.
78  */
79 int constexpr version_patch() { return GOOGLE_CLOUD_CPP_VERSION_PATCH; }
80 
81 /**
82  * The Google Cloud C++ Client pre-release version.
83  *
84  * @see https://semver.org/spec/v2.0.0.html for details.
85  */
86 constexpr char const* version_pre_release() {
87  return GOOGLE_CLOUD_CPP_VERSION_PRE_RELEASE;
88 }
89 
90 namespace internal {
91 auto constexpr kMaxMinorVersions = 100;
92 auto constexpr kMaxPatchVersions = 100;
93 } // namespace internal
94 
95 /// A single integer representing the Major/Minor/Patch version.
96 int constexpr version() {
97  static_assert(version_minor() < internal::kMaxMinorVersions,
98  "version_minor() should be < kMaxMinorVersions");
99  static_assert(version_patch() < internal::kMaxPatchVersions,
100  "version_patch() should be < kMaxPatchVersions");
101  return internal::kMaxPatchVersions *
102  (internal::kMaxMinorVersions * version_major() + version_minor()) +
104 }
105 
106 /// The version as a string, in MAJOR.MINOR.PATCH[-PRE][+gitrev] format.
107 std::string version_string();
108 
110 // TODO(#7463) - remove backwards compatibility namespaces
111 namespace v1 = GOOGLE_CLOUD_CPP_NS; // NOLINT(misc-unused-alias-decls)
112 namespace gcpcxxV1 = GOOGLE_CLOUD_CPP_NS; // NOLINT(misc-unused-alias-decls)
113 } // namespace cloud
114 } // namespace google
115 
116 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_VERSION_H