IDS peak AFL v2.0.1
Loading...
Searching...
No Matches
peak_common_range.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
16
17#include <type_traits>
18
19namespace peak
20{
21namespace common
22{
23
24namespace detail
25{
26
42template <typename T>
43class RangeT : public detail::IntervalT<T>
44{
45
46public:
47 static_assert(std::is_arithmetic<T>::value, "Template argument of Interval must be arithmetic.");
48
49 using type = T;
50
63 constexpr RangeT(T minimum, T maximum, T increment)
64 : detail::IntervalT<T>(minimum, maximum)
65 , m_increment{ increment }
66 {
67 if (increment > maximum - minimum)
68 {
69 throw peak::common::InvalidParameterException("The given increment is larger than the total range!");
70 }
71 }
72
81 {
82 return m_increment;
83 }
84
95 constexpr bool operator==(const RangeT& rhs) const
96 {
97 return detail::IntervalT<T>::operator==(rhs) && m_increment == rhs.m_increment;
98 }
99
108 constexpr bool operator!=(const RangeT& rhs) const
109 {
110 return !(rhs == *this);
111 }
112
113private:
114 T m_increment;
115};
116
117} // namespace detail
118
133
148
163
178
179
180} // namespace common
181} // namespace peak
Thrown when a function receives an invalid parameter.
Definition peak_common_exceptions.hpp:49
Represents a continuous numeric interval with inclusive lower and upper bounds.
Definition peak_common_interval.hpp:44
constexpr IntervalT(double minimum, double maximum)
Definition peak_common_interval.hpp:61
constexpr bool operator==(const IntervalT< H > &rhs) const
Compares two intervals for equality (integral types).
Definition peak_common_interval.hpp:109
Represents a numeric range with defined boundaries and a fixed increment.
Definition peak_common_range.hpp:44
constexpr bool operator==(const RangeT &rhs) const
Compares this range with another for equality.
Definition peak_common_range.hpp:95
constexpr T GetIncrement() const
Retrieves the increment value associated with this range.
Definition peak_common_range.hpp:80
constexpr RangeT(T minimum, T maximum, T increment)
Constructs a range with specified minimum, maximum, and increment values.
Definition peak_common_range.hpp:63
constexpr bool operator!=(const RangeT &rhs) const
Compares this range with another for inequality.
Definition peak_common_range.hpp:108
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.h:86
detail::RangeT< int32_t > Range
Alias for a range of 32-bit signed integers.
Definition peak_common_range.hpp:147
detail::RangeT< float > RangeF
Alias for a range of 32-bit floating-point numbers.
Definition peak_common_range.hpp:162
detail::RangeT< uint8_t > RangeU8
Alias for a range of 8-bit unsigned integers.
Definition peak_common_range.hpp:177
detail::RangeT< uint32_t > RangeU
Alias for a range of 32-bit unsigned integers.
Definition peak_common_range.hpp:132
Namespace for internal implementation details and low-level types.
Definition peak_common_math.hpp:24
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:22