From: Breuninger Matthias (ETAS-DAP/XPC-Fe3) Date: Fri, 31 Jan 2025 12:06:32 +0000 (+0100) Subject: SetValue: Add various string-like type support X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2c75017064ca9f79ff3af7971278bea2e0697024;p=thirdparty%2Flldpd.git SetValue: Add various string-like type support --- diff --git a/src/lib/lldpctl.hpp b/src/lib/lldpctl.hpp index 4d8c0387..c0cf3dc2 100644 --- a/src/lib/lldpctl.hpp +++ b/src/lib/lldpctl.hpp @@ -90,6 +90,24 @@ class LldpErrCategory : public std::error_category { } }; +/** + * @brief Fallback type trait for checking against a const char array. + */ +template +struct is_const_char_array : std::false_type {}; + +/** + * @brief Specialization of @p is_const_char_array for an actual array. + */ +template +struct is_const_char_array : std::true_type {}; + +/** + * @brief Convenience constexpr for @p is_const_char_array value. + */ +template +inline constexpr bool is_const_char_array_v = is_const_char_array::value; + /** * @brief Wrapper class for @p lldpctl_atom_t with automatic lifetime management. */ @@ -252,7 +270,18 @@ class LldpAtom { template void SetValue(lldpctl_key_t key, const T &data) { - if constexpr (std::is_same_v> || + if constexpr (std::is_same_v || + is_const_char_array>::value || + std::is_same_v) { + CHECK_LLDP_P(::lldpctl_atom_set_str(atom_, key, + data), + conn_.get()); + } else if constexpr (std::is_same_v || + std::is_same_v) { + CHECK_LLDP_P(::lldpctl_atom_set_str(atom_, key, + data.data()), + conn_.get()); + } else if constexpr (std::is_same_v> || std::is_same_v>) { CHECK_LLDP_P(::lldpctl_atom_set_str(atom_, key, data.has_value() ? data->data() : nullptr),