1676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong/*
2676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * Copyright (C) 2017 The Android Open Source Project
3676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong *
4676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * Licensed under the Apache License, Version 2.0 (the "License");
5676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * you may not use this file except in compliance with the License.
6676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * You may obtain a copy of the License at
7676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong *
8676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong *      http://www.apache.org/licenses/LICENSE-2.0
9676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong *
10676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * Unless required by applicable law or agreed to in writing, software
11676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * distributed under the License is distributed on an "AS IS" BASIS,
12676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * See the License for the specific language governing permissions and
14676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * limitations under the License.
15676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong */
16676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
17676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
18676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#ifndef ANDROID_VINTF_VERSION_H
19676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#define ANDROID_VINTF_VERSION_H
20676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
21676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#include <stdint.h>
22676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#include <string>
23676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#include <utility>
24676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
25676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongnamespace android {
26676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongnamespace vintf {
27676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
28676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongstruct Version {
29676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
30676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    constexpr Version() : Version(0u, 0u) {}
31676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    constexpr Version(size_t mj, size_t mi) : majorVer(mj), minorVer(mi) {}
32676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
33676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    size_t majorVer;
34676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    size_t minorVer;
35676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
36676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    inline bool operator==(const Version &other) const {
37676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong        return majorVer == other.majorVer && minorVer == other.minorVer;
38676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    }
39676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    inline bool operator!=(const Version &other) const {
40676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong        return !((*this) == other);
41676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    }
42676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    inline bool operator<(const Version &other) const {
43676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong        if (majorVer < other.majorVer)
44676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong            return true;
45676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong        if (majorVer > other.majorVer)
46676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong            return false;
47676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong        return minorVer < other.minorVer;
48676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    }
49676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    inline bool operator>(const Version &other) const {
50676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong        return other < (*this);
51676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    }
52676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    inline bool operator<=(const Version &other) const {
53676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong        return !((*this) > other);
54676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    }
55676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    inline bool operator>=(const Version &other) const {
56676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong        return !((*this) < other);
57676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    }
58676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong};
59676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
603f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongstruct KernelVersion {
613f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong
623f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong    constexpr KernelVersion() : KernelVersion(0u, 0u, 0u) {}
633f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong    constexpr KernelVersion(size_t v, size_t mj, size_t mi) :
643f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong            version(v), majorRev(mj), minorRev(mi) {}
653f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong
663f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong    size_t version;
673f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong    size_t majorRev;
683f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong    size_t minorRev;
693f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong
703f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong    inline bool operator==(const KernelVersion &other) const {
713f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong        return version == other.version
723f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong            && majorRev == other.majorRev
733f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong            && minorRev == other.minorRev;
743f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong    }
753f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong    inline bool operator!=(const KernelVersion &other) const {
763f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong        return !((*this) == other);
773f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong    }
783f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong};
793f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong
80676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong} // namespace vintf
81676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong} // namespace android
82676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
83676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#endif // ANDROID_VINTF_VERSION_H
84