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 };
59 
60 struct KernelVersion {
61 
KernelVersionKernelVersion62     constexpr KernelVersion() : KernelVersion(0u, 0u, 0u) {}
KernelVersionKernelVersion63     constexpr KernelVersion(size_t v, size_t mj, size_t mi) :
64             version(v), majorRev(mj), minorRev(mi) {}
65 
66     size_t version;
67     size_t majorRev;
68     size_t minorRev;
69 
70     inline bool operator==(const KernelVersion &other) const {
71         return version == other.version
72             && majorRev == other.majorRev
73             && minorRev == other.minorRev;
74     }
75     inline bool operator!=(const KernelVersion &other) const {
76         return !((*this) == other);
77     }
78 };
79 
80 } // namespace vintf
81 } // namespace android
82 
83 #endif // ANDROID_VINTF_VERSION_H
84