From 13f7fb796621cf4e1fc52018868ec0905cb629f8 Mon Sep 17 00:00:00 2001 From: Anay Wadhera Date: Tue, 4 Apr 2023 12:28:35 -0700 Subject: [PATCH] Remove generic variant of MediumSelector, we only use bool as the indicator type. PiperOrigin-RevId: 521834776 --- connections/medium_selector.h | 29 +++++++++---------- .../GNCSupportedMediums+CppConversions.h | 5 +--- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/connections/medium_selector.h b/connections/medium_selector.h index ceaeeb10..92673732 100644 --- a/connections/medium_selector.h +++ b/connections/medium_selector.h @@ -14,6 +14,7 @@ #ifndef CORE_MEDIUM_SELECTOR_H_ #define CORE_MEDIUM_SELECTOR_H_ +#include #include "proto/connections_enums.pb.h" namespace nearby { @@ -21,27 +22,25 @@ namespace connections { using Medium = ::location::nearby::proto::connections::Medium; -// Generic type: allows definition of a feature T for every Medium. -template -struct MediumSelector { - T bluetooth; - T ble; - T web_rtc; - T wifi_lan; - T wifi_hotspot; - T wifi_direct; +struct BooleanMediumSelector { + bool bluetooth; + bool ble; + bool web_rtc; + bool wifi_lan; + bool wifi_hotspot; + bool wifi_direct; - constexpr bool Any(T value) const { + constexpr bool Any(bool value) const { return bluetooth == value || ble == value || web_rtc == value || wifi_lan == value || wifi_hotspot == value || wifi_direct == value; } - constexpr bool All(T value) const { + constexpr bool All(bool value) const { return bluetooth == value && ble == value && web_rtc == value && wifi_lan == value && wifi_hotspot == value && wifi_direct == value; } - constexpr int Count(T value) const { + constexpr int Count(bool value) const { int count = 0; if (bluetooth == value) count++; if (ble == value) count++; @@ -52,7 +51,7 @@ struct MediumSelector { return count; } - constexpr MediumSelector& SetAll(T value) { + constexpr BooleanMediumSelector& SetAll(bool value) { bluetooth = value; ble = value; web_rtc = value; @@ -62,7 +61,7 @@ struct MediumSelector { return *this; } - std::vector GetMediums(T value) const { + std::vector GetMediums(bool value) const { std::vector mediums; // Mediums are sorted in order of decreasing preference. if (wifi_lan == value) mediums.push_back(Medium::WIFI_LAN); @@ -75,8 +74,6 @@ struct MediumSelector { } }; -using BooleanMediumSelector = MediumSelector; - } // namespace connections } // namespace nearby diff --git a/connections/swift/NearbyCoreAdapter/Sources/GNCSupportedMediums+CppConversions.h b/connections/swift/NearbyCoreAdapter/Sources/GNCSupportedMediums+CppConversions.h index f8b5777f..e2825430 100644 --- a/connections/swift/NearbyCoreAdapter/Sources/GNCSupportedMediums+CppConversions.h +++ b/connections/swift/NearbyCoreAdapter/Sources/GNCSupportedMediums+CppConversions.h @@ -19,10 +19,7 @@ namespace nearby { namespace connections { -template -class MediumSelector; - -using BooleanMediumSelector = MediumSelector; +class BooleanMediumSelector; } // namespace connections } // namespace nearby