Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/NimBLEAttValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,23 @@ class NimBLEAttValue {
/*********************** Template Functions ************************/

# if __cplusplus < 201703L
/**
* @brief Template to set value to the value of a char array using strnlen.
* @param [in] s A reference to a char array.
* @details Only used for char array types to correctly determine length via strnlen.
*/
template <typename T>
# ifdef _DOXYGEN_
bool
# else
typename std::enable_if<std::is_array<T>::value &&
std::is_same<typename std::remove_extent<T>::type, char>::value,
bool>::type
# endif
setValue(const T& s) {
return setValue(reinterpret_cast<const uint8_t*>(s), strnlen(s, sizeof(T)));
}

/**
* @brief Template to set value to the value of <type\>val.
* @param [in] v The <type\>value to set.
Expand All @@ -263,7 +280,10 @@ class NimBLEAttValue {
# ifdef _DOXYGEN_
bool
# else
typename std::enable_if<!std::is_pointer<T>::value && !Has_c_str_length<T>::value && !Has_data_size<T>::value, bool>::type
typename std::enable_if<!std::is_pointer<T>::value && !Has_c_str_length<T>::value && !Has_data_size<T>::value &&
!(std::is_array<T>::value &&
std::is_same<typename std::remove_extent<T>::type, char>::value),
bool>::type
# endif
setValue(const T& v) {
return setValue(reinterpret_cast<const uint8_t*>(&v), sizeof(T));
Expand Down Expand Up @@ -334,6 +354,9 @@ class NimBLEAttValue {
}
} else if constexpr (Has_c_str_length<T>::value) {
return setValue(reinterpret_cast<const uint8_t*>(s.c_str()), s.length());
} else if constexpr (std::is_array<T>::value &&
std::is_same<typename std::remove_extent<T>::type, char>::value) {
return setValue(reinterpret_cast<const uint8_t*>(s), strnlen(s, sizeof(s)));
} else {
return setValue(reinterpret_cast<const uint8_t*>(&s), sizeof(s));
}
Expand Down