2121#include " syscfg/syscfg.h"
2222#if CONFIG_BT_NIMBLE_ENABLED
2323
24- # ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
25- # include < Arduino.h>
24+ /* Enables the use of Arduino String class for attribute values */
25+ # ifndef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
26+ # define NIMBLE_CPP_ARDUINO_STRING_AVAILABLE (__has_include(<Arduino.h>))
27+ # endif
28+
29+ # if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
30+ # include < WString.h>
2631# endif
2732
2833# include < string>
@@ -78,8 +83,7 @@ template <typename T, typename = void>
7883struct Has_value_type : std::false_type {};
7984
8085template <typename T>
81- struct Has_value_type <T, decltype (void (sizeof (typename T::value_type)))>
82- : std::true_type {};
86+ struct Has_value_type <T, decltype (void (sizeof (typename T::value_type)))> : std::true_type {};
8387
8488/* *
8589 * @brief A specialized container class to hold BLE attribute values.
@@ -103,7 +107,8 @@ class NimBLEAttValue {
103107 * @param[in] init_len The initial size in bytes.
104108 * @param[in] max_len The max size in bytes that the value can be.
105109 */
106- NimBLEAttValue (uint16_t init_len = MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_INIT_LENGTH), uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
110+ NimBLEAttValue (uint16_t init_len = MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_INIT_LENGTH),
111+ uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
107112
108113 /* *
109114 * @brief Construct with an initial value from a buffer.
@@ -145,7 +150,7 @@ class NimBLEAttValue {
145150 NimBLEAttValue (const std::vector<uint8_t > vec, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN)
146151 : NimBLEAttValue(&vec[0 ], vec.size(), max_len) {}
147152
148- # ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
153+ # if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
149154 /* *
150155 * @brief Construct with an initial value from an Arduino String.
151156 * @param str An Arduino String containing to the initial value to set.
@@ -292,10 +297,7 @@ class NimBLEAttValue {
292297 typename std::enable_if<Has_data_size<T>::value && Has_value_type<T>::value, bool >::type
293298# endif
294299 setValue (const T& v) {
295- return setValue (
296- reinterpret_cast <const uint8_t *>(v.data ()),
297- v.size () * sizeof (typename T::value_type)
298- );
300+ return setValue (reinterpret_cast <const uint8_t *>(v.data ()), v.size () * sizeof (typename T::value_type));
299301 }
300302
301303 /* *
@@ -398,7 +400,7 @@ class NimBLEAttValue {
398400 /* * @brief Inequality operator */
399401 bool operator !=(const NimBLEAttValue& source) const { return !(*this == source); }
400402
401- # ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
403+ # if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
402404 /* * @brief Operator; Get the value as an Arduino String value. */
403405 operator String () const { return String (reinterpret_cast <char *>(m_attr_value)); }
404406# endif
0 commit comments