From 80db38c60a4cecd488aad381117b7e8314444b9b Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 21 Nov 2018 09:59:08 +0000 Subject: [PATCH] BLE: Cleanup bounded and document it. --- features/FEATURE_BLE/ble/common/Bounded.h | 72 +++++++++++++++++-- .../ble/gap/ConnectionParameters.h | 2 +- 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/features/FEATURE_BLE/ble/common/Bounded.h b/features/FEATURE_BLE/ble/common/Bounded.h index 192c2387eb..ce076f8bf2 100644 --- a/features/FEATURE_BLE/ble/common/Bounded.h +++ b/features/FEATURE_BLE/ble/common/Bounded.h @@ -21,9 +21,29 @@ namespace ble { -template +/** + * 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 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 +const T Bounded::MIN = Min; + +template +const T Bounded::MAX = Max; + } // namespace ble #endif //BLE_COMMON_BOUNDED_H_ diff --git a/features/FEATURE_BLE/ble/gap/ConnectionParameters.h b/features/FEATURE_BLE/ble/gap/ConnectionParameters.h index 6374067383..f63578b980 100644 --- a/features/FEATURE_BLE/ble/gap/ConnectionParameters.h +++ b/features/FEATURE_BLE/ble/gap/ConnectionParameters.h @@ -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(),