diff options
author | Lutz Bichler <Lutz.Bichler@bmw.de> | 2020-10-27 10:02:03 +0100 |
---|---|---|
committer | Lutz Bichler <Lutz.Bichler@bmw.de> | 2020-10-27 10:02:03 +0100 |
commit | 89720d3c63bbd22cbccc80cdc92c2f2dd20193ba (patch) | |
tree | 591c45dba85c98fdd8e141827bdb6e82aaad4f59 /include/CommonAPI/RangedInteger.hpp | |
parent | 99ebf3461f51e4899f06457d6aafdaa4adecd278 (diff) | |
download | genivi-common-api-runtime-master.tar.gz |
Diffstat (limited to 'include/CommonAPI/RangedInteger.hpp')
-rw-r--r-- | include/CommonAPI/RangedInteger.hpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/include/CommonAPI/RangedInteger.hpp b/include/CommonAPI/RangedInteger.hpp new file mode 100644 index 0000000..ded4158 --- /dev/null +++ b/include/CommonAPI/RangedInteger.hpp @@ -0,0 +1,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 |