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 //     http://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/port_platform.h"
19 #include "google/cloud/internal/version_info.h"
20 #include <string>
21 
22 #define GOOGLE_CLOUD_CPP_VCONCAT(Ma, Mi) v##Ma
23 #define GOOGLE_CLOUD_CPP_VEVAL(Ma, Mi) GOOGLE_CLOUD_CPP_VCONCAT(Ma, Mi)
24 #define GOOGLE_CLOUD_CPP_NS                              \
25   GOOGLE_CLOUD_CPP_VEVAL(GOOGLE_CLOUD_CPP_VERSION_MAJOR, \
26                          GOOGLE_CLOUD_CPP_VERSION_MINOR)
27 
28 namespace google {
29 /**
30  * Contains all the Google Cloud C++ Library APIs.
31  */
32 namespace cloud {
33 /**
34  * The Google Cloud C++ Library inlined, versioned namespace.
35  *
36  * Applications may need to link multiple versions of the Google Cloud C++
37  * Libraries, for example, if they link a library that uses an older version of
38  * the libraries than they do.  This namespace is inlined, so applications can
39  * use `google::cloud::Foo` in their source, but the symbols are versioned,
40  * i.e., the symbol becomes `google::cloud::v1::Foo`.
41  *
42  * Note that, consistent with the semver.org guidelines, the v0 version makes
43  * no guarantees with respect to backwards compatibility.
44  */
45 inline namespace GOOGLE_CLOUD_CPP_NS {
46 /**
47  * The Google Cloud Storage C++ Client major version.
48  *
49  * @see https://semver.org/spec/v2.0.0.html for details.
50  */
version_major()51 int constexpr version_major() { return GOOGLE_CLOUD_CPP_VERSION_MAJOR; }
52 
53 /**
54  * The Google Cloud Storage C++ Client minor version.
55  *
56  * @see https://semver.org/spec/v2.0.0.html for details.
57  */
version_minor()58 int constexpr version_minor() { return GOOGLE_CLOUD_CPP_VERSION_MINOR; }
59 
60 /**
61  * The Google Cloud Storage C++ Client patch version.
62  *
63  * @see https://semver.org/spec/v2.0.0.html for details.
64  */
version_patch()65 int constexpr version_patch() { return GOOGLE_CLOUD_CPP_VERSION_PATCH; }
66 
67 namespace internal {
68 auto constexpr kMaxMinorVersions = 100;
69 auto constexpr kMaxPatchVersions = 100;
70 }  // namespace internal
71 
72 /// A single integer representing the Major/Minor/Patch version.
version()73 int constexpr version() {
74   static_assert(version_minor() < internal::kMaxMinorVersions,
75                 "version_minor() should be < kMaxMinorVersions");
76   static_assert(version_patch() < internal::kMaxPatchVersions,
77                 "version_patch() should be < kMaxPatchVersions");
78   return internal::kMaxPatchVersions *
79              (internal::kMaxMinorVersions * version_major() + version_minor()) +
80          version_patch();
81 }
82 
83 /// The version as a string, in MAJOR.MINOR.PATCH+gitrev format.
84 std::string version_string();
85 
86 }  // namespace GOOGLE_CLOUD_CPP_NS
87 }  // namespace cloud
88 }  // namespace google
89 
90 #endif  // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_VERSION_H
91