From bd4f7646f55c91c7fd5dfa697fedb85c79758550 Mon Sep 17 00:00:00 2001 From: Anay Wadhera Date: Thu, 6 Apr 2023 13:34:39 -0700 Subject: [PATCH] Refactor windows medium selector to remove generic type PiperOrigin-RevId: 522422530 --- connections/c/connection_options_w.h | 4 +-- connections/c/medium_selector_w.h | 39 ++++++++++++++-------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/connections/c/connection_options_w.h b/connections/c/connection_options_w.h index 88919553..9a2f7497 100644 --- a/connections/c/connection_options_w.h +++ b/connections/c/connection_options_w.h @@ -15,6 +15,7 @@ #define THIRD_PARTY_NEARBY_CONNECTIONS_C_CONNECTION_OPTIONS_W_H_ #include +#include "connections/c/dll_config.h" #include "connections/c/medium_selector_w.h" #include "connections/c/options_base_w.h" @@ -24,9 +25,6 @@ extern "C" { #define MAX_MEDIUMS 6 -// Feature On/Off switch for mediums. -using BooleanMediumSelector = MediumSelectorW; - // Connection Options: used for both Advertising and Discovery. // All fields are mutable, to make the type copy-assignable. struct DLL_API ConnectionOptionsW : public OptionsBaseW { diff --git a/connections/c/medium_selector_w.h b/connections/c/medium_selector_w.h index e18acdd2..555cad0e 100644 --- a/connections/c/medium_selector_w.h +++ b/connections/c/medium_selector_w.h @@ -14,36 +14,38 @@ #ifndef THIRD_PARTY_NEARBY_CONNECTIONS_C_MEDIUM_SELECTOR_W_H_ #define THIRD_PARTY_NEARBY_CONNECTIONS_C_MEDIUM_SELECTOR_W_H_ +#include + #include "proto/connections_enums.pb.h" namespace nearby::windows { using MediumW = ::location::nearby::proto::connections::Medium; -// Generic type: allows definition of a feature T for every Medium. -template -struct MediumSelectorW { - T bluetooth; - T ble; - T web_rtc; - T wifi_lan; - T wifi_hotspot; - T wifi_direct; +// Feature On/Off switch for mediums. +struct BooleanMediumSelectorW { + bool bluetooth; + bool ble; + bool web_rtc; + bool wifi_lan; + bool wifi_hotspot; + bool wifi_direct; - constexpr MediumSelectorW() = default; - constexpr MediumSelectorW(const MediumSelectorW&) = default; - constexpr MediumSelectorW& operator=(const MediumSelectorW&) = default; - constexpr bool Any(const T& value) const { + BooleanMediumSelectorW() = default; + constexpr BooleanMediumSelectorW(const BooleanMediumSelectorW&) = default; + constexpr BooleanMediumSelectorW& operator=(const BooleanMediumSelectorW&) = + default; + constexpr bool Any(const bool value) const { return bluetooth == value || ble == value || web_rtc == value || wifi_lan == value || wifi_hotspot == value || wifi_direct == value; } - constexpr bool All(const T& value) const { + constexpr bool All(const bool value) const { return bluetooth == value && ble == value && web_rtc == value && wifi_lan == value && wifi_hotspot == value && wifi_direct == value; } - constexpr int Count(const T& value) const { + constexpr int Count(const bool value) const { int count = 0; if (bluetooth == value) ++count; if (ble == value) ++count; @@ -54,7 +56,7 @@ struct MediumSelectorW { return count; } - constexpr MediumSelectorW& SetAll(const T& value) { + constexpr BooleanMediumSelectorW& SetAll(const bool value) { bluetooth = value; ble = value; web_rtc = value; @@ -64,7 +66,7 @@ struct MediumSelectorW { return *this; } - std::vector GetMediums(const T& value) const { + std::vector GetMediums(const bool value) const { std::vector mediums; // Mediums are sorted in order of decreasing preference. if (wifi_lan == value) mediums.push_back(MediumW::WIFI_LAN); @@ -77,9 +79,6 @@ struct MediumSelectorW { } }; -// Feature On/Off switch for mediums. -using BooleanMediumSelectorW = MediumSelectorW; - } // namespace nearby::windows #endif // THIRD_PARTY_NEARBY_CONNECTIONS_C_MEDIUM_SELECTOR_W_H_