summaryrefslogtreecommitdiff
path: root/include/CommonAPI/RangedInteger.hpp
blob: ded4158575df785528bc65974a12ac6359cae149 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (C) 2015-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#if !defined (COMMONAPI_INTERNAL_COMPILATION)
#error "Only <CommonAPI/CommonAPI.hpp> can be included directly, this file may disappear or change contents."
#endif

#ifndef COMMONAPI_RANGEDINTEGER_HPP
#define COMMONAPI_RANGEDINTEGER_HPP

namespace CommonAPI {
    template <int minimum, int maximum>
    struct RangedInteger {

    	int value_;

    	RangedInteger(int _value):
    		value_(_value) {
    		// assert(_value >= minimum && _value <= maximum);
    	}
    	RangedInteger():
    		value_(minimum) {
    	}
    	~RangedInteger() {}

    	inline RangedInteger& operator= (const int _value) {
    		// assert(_value >= minimum && _value <= maximum);
    		value_ = _value;
    		return (*this);
    	}
        inline operator int() const {
            return value_;
    	}

        inline bool operator==(const RangedInteger &_other) const {
            return (value_ == _other.value_);
        }

        inline bool operator!=(const RangedInteger &_other) const {
            return (value_ != _other.value_);
        }

        inline bool operator<(const RangedInteger &_other) const {
            return (value_ < _other.value_);
        }

        inline bool operator<=(const RangedInteger &_other) const {
            return (value_ <= _other.value_);
        }

        inline bool operator>(const RangedInteger &_other) const {
            return (value_ > _other.value_);
        }

        inline bool operator>=(const RangedInteger &_other) const {
            return (value_ >= _other.value_);
        }

        inline bool operator==(const int &_other) const {
            return (value_ == _other);
        }

        inline bool operator!=(const int &_other) const {
            return (value_ != _other);
        }

        inline bool operator<(const int &_other) const {
            return (value_ < _other);
        }

        inline bool operator<=(const int &_other) const {
            return (value_ <= _other);
        }

        inline bool operator>(const int &_other) const {
            return (value_ > _other);
        }

        inline bool operator>=(const int &_other) const {
            return (value_ >= _other);
        }

        bool validate() const {
    		return value_ <= maximum && value_ >= minimum;
    	}
    };
}

#endif