BLE: Cleanup bounded and document it.

pull/8738/head
Vincent Coubard 2018-11-21 09:59:08 +00:00
parent e9c0f587af
commit 80db38c60a
2 changed files with 67 additions and 7 deletions

View File

@ -21,9 +21,29 @@
namespace ble {
template<typename T, int32_t Min, int32_t Max>
/**
* Restrict values of an integer type to a defined range.
*
* The range is a closed interval that includes its left-bound (Min) and
* right-bound value (Max).
*
* @tparam Rep The C++ integer type used to represent the values.
* @tparam Min Minimum value allowed.
* @tparam Max maximum value allowed.
*/
template<typename Rep, Rep Min, Rep Max>
struct Bounded {
Bounded(T v) : _value(v) {
/**
* Construct a bounded integer.
*
* If v is out of the range [Min : Max] then if it is less than Min the
* value of the bounded integer will be Min and if it greater than Max then
* the value of the bounded integer will be Max.
*
* @param v The value to store.
*/
Bounded(Rep v) : _value(v)
{
if (v < Min) {
_value = v;
} else if (v > Max) {
@ -31,17 +51,57 @@ struct Bounded {
}
}
T value() const {
/**
* Access the inner value.
*
* @return The current value.
*/
Rep value() const {
return _value;
}
static const T min = Min;
static const T max = Max;
/**
* The left-bound value.
*
* @return The lowest value that can be represented by this type
*/
static Rep min()
{
return Min;
}
/**
* The right-bound value.
*
* @return The highest value that can be represented by this type
*/
static Rep max()
{
return Max;
}
/**
* The left-bound value.
*/
static const Rep MIN;
/**
* The right-bound value.
*/
static const Rep MAX;
private:
T _value;
Rep _value;
};
/* ---------------------- Static variable initialization -------------------- */
template<typename T, T Min, T Max>
const T Bounded<T, Min, Max>::MIN = Min;
template<typename T, T Min, T Max>
const T Bounded<T, Min, Max>::MAX = Max;
} // namespace ble
#endif //BLE_COMMON_BOUNDED_H_

View File

@ -41,7 +41,7 @@ public:
scan_window_t scanWindow = scan_window_t::min(),
conn_interval_t minConnectionInterval = conn_interval_t::min(),
conn_interval_t maxConnectionInterval = conn_interval_t::max(),
slave_latency_t slaveLatency = slave_latency_t::min,
slave_latency_t slaveLatency = slave_latency_t::min(),
supervision_timeout_t connectionSupervisionTimeout = supervision_timeout_t::max(),
phy_t phy = phy_t::LE_1M,
conn_event_length_t minEventLength = conn_event_length_t::min(),