• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 
18 #ifndef ANDROID_VINTF_VERSION_H
19 #define ANDROID_VINTF_VERSION_H
20 
21 #include <stdint.h>
22 #include <string>
23 #include <utility>
24 
25 namespace android {
26 namespace vintf {
27 
28 struct Version {
29 
VersionVersion30     constexpr Version() : Version(0u, 0u) {}
VersionVersion31     constexpr Version(size_t mj, size_t mi) : majorVer(mj), minorVer(mi) {}
32 
33     size_t majorVer;
34     size_t minorVer;
35 
36     inline bool operator==(const Version &other) const {
37         return majorVer == other.majorVer && minorVer == other.minorVer;
38     }
39     inline bool operator!=(const Version &other) const {
40         return !((*this) == other);
41     }
42     inline bool operator<(const Version &other) const {
43         if (majorVer < other.majorVer)
44             return true;
45         if (majorVer > other.majorVer)
46             return false;
47         return minorVer < other.minorVer;
48     }
49     inline bool operator>(const Version &other) const {
50         return other < (*this);
51     }
52     inline bool operator<=(const Version &other) const {
53         return !((*this) > other);
54     }
55     inline bool operator>=(const Version &other) const {
56         return !((*this) < other);
57     }
58     // Version(2, 1).minorAtLeast(Version(1, 0)) == false
59     // Version(2, 1).minorAtLeast(Version(2, 0)) == true
60     // Version(2, 1).minorAtLeast(Version(2, 1)) == true
61     // Version(2, 1).minorAtLeast(Version(2, 2)) == false
minorAtLeastVersion62     inline bool minorAtLeast(const Version& other) const {
63         return majorVer == other.majorVer && minorVer >= other.minorVer;
64     }
65 };
66 
67 struct KernelVersion {
68 
KernelVersionKernelVersion69     constexpr KernelVersion() : KernelVersion(0u, 0u, 0u) {}
KernelVersionKernelVersion70     constexpr KernelVersion(size_t v, size_t mj, size_t mi) :
71             version(v), majorRev(mj), minorRev(mi) {}
72 
73     size_t version;
74     size_t majorRev;
75     size_t minorRev;
76 
77     inline bool operator==(const KernelVersion &other) const {
78         return version == other.version
79             && majorRev == other.majorRev
80             && minorRev == other.minorRev;
81     }
82     inline bool operator!=(const KernelVersion &other) const {
83         return !((*this) == other);
84     }
85 };
86 
87 } // namespace vintf
88 } // namespace android
89 
90 #endif // ANDROID_VINTF_VERSION_H
91