xref: /aosp_15_r20/external/oboe/include/oboe/Version.h (revision 05767d913155b055644481607e6fa1e35e2fe72c)
1 /*
2  * Copyright 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef OBOE_VERSIONINFO_H
18 #define OBOE_VERSIONINFO_H
19 
20 #include <cstdint>
21 
22 /**
23  * A note on use of preprocessor defines:
24  *
25  * This is one of the few times when it's suitable to use preprocessor defines rather than constexpr
26  * Why? Because C++11 requires a lot of boilerplate code to convert integers into compile-time
27  * string literals. The preprocessor, despite it's lack of type checking, is more suited to the task
28  *
29  * See: https://stackoverflow.com/questions/6713420/c-convert-integer-to-string-at-compile-time/26824971#26824971
30  *
31  */
32 
33 // Type: 8-bit unsigned int. Min value: 0 Max value: 255. See below for description.
34 #define OBOE_VERSION_MAJOR 1
35 
36 // Type: 8-bit unsigned int. Min value: 0 Max value: 255. See below for description.
37 #define OBOE_VERSION_MINOR 8
38 
39 // Type: 16-bit unsigned int. Min value: 0 Max value: 65535. See below for description.
40 #define OBOE_VERSION_PATCH 2
41 
42 #define OBOE_STRINGIFY(x) #x
43 #define OBOE_TOSTRING(x) OBOE_STRINGIFY(x)
44 
45 // Type: String literal. See below for description.
46 #define OBOE_VERSION_TEXT \
47         OBOE_TOSTRING(OBOE_VERSION_MAJOR) "." \
48         OBOE_TOSTRING(OBOE_VERSION_MINOR) "." \
49         OBOE_TOSTRING(OBOE_VERSION_PATCH)
50 
51 // Type: 32-bit unsigned int. See below for description.
52 #define OBOE_VERSION_NUMBER ((OBOE_VERSION_MAJOR << 24) | (OBOE_VERSION_MINOR << 16) | OBOE_VERSION_PATCH)
53 
54 namespace oboe {
55 
56 const char * getVersionText();
57 
58 /**
59  * Oboe versioning object
60  */
61 struct Version {
62     /**
63      * This is incremented when we make breaking API changes. Based loosely on https://semver.org/.
64      */
65     static constexpr uint8_t Major = OBOE_VERSION_MAJOR;
66 
67     /**
68      * This is incremented when we add backwards compatible functionality. Or set to zero when MAJOR is
69      * incremented.
70      */
71     static constexpr uint8_t Minor = OBOE_VERSION_MINOR;
72 
73     /**
74      * This is incremented when we make backwards compatible bug fixes. Or set to zero when MINOR is
75      * incremented.
76      */
77     static constexpr uint16_t Patch = OBOE_VERSION_PATCH;
78 
79     /**
80      * Version string in the form MAJOR.MINOR.PATCH.
81      */
82     static constexpr const char * Text = OBOE_VERSION_TEXT;
83 
84     /**
85      * Integer representation of the current Oboe library version. This will always increase when the
86      * version number changes so can be compared using integer comparison.
87      */
88     static constexpr uint32_t Number = OBOE_VERSION_NUMBER;
89 };
90 
91 } // namespace oboe
92 #endif //OBOE_VERSIONINFO_H
93