BLE: Add Duration::forever() function.

pull/8738/head
Vincent Coubard 2018-11-21 10:22:21 +00:00
parent 7b0cb27427
commit 07c05917e0
1 changed files with 22 additions and 1 deletions

View File

@ -49,8 +49,18 @@ struct DefaultRange<uint32_t> {
typedef Range<0, 0xFFFFFFFF> type;
};
template<uint32_t V>
struct Forever {
static const uint32_t VALUE = V;
};
template<typename Rep, uint32_t TB, typename Range = typename DefaultRange<Rep>::type >
template<
typename Rep,
uint32_t TB,
typename Range = typename DefaultRange<Rep>::type,
typename Forever = void*
>
struct Duration {
Duration() : duration() { }
@ -93,6 +103,11 @@ struct Duration {
return &duration;
}
static Duration forever()
{
return Duration(Forever::VALUE);
}
private:
static Rep clamp(Rep in) {
if (in < MIN) {
@ -211,6 +226,12 @@ bool operator>(Duration<Rep, Us, Range> lhs, Duration<Rep, Us, Range> rhs) {
return rhs < lhs;
}
/* ---------------------- Static variable initialization -------------------- */
template<uint32_t V>
const uint32_t Forever<V>::VALUE;
}
#endif //BLE_COMMON_DURATION_H_