ExperimentalFeature.h (3511B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <vector> 5 #include <string> 6 #include <type_traits> 7 #include "AppInstallerStrings.h" 8 9 namespace AppInstaller::Settings 10 { 11 using namespace std::string_view_literals; 12 struct UserSettings; 13 14 struct ExperimentalFeature 15 { 16 // To add an experimental feature 17 // 1 - add a flag in this enum, before Max 18 // 2 - add a setting in Setting enum in UserSettings.h 19 // 3 - follow how to add setting instructions 20 // 4 - provide implementation in ExperimentalFeature.cpp 21 enum class Feature : unsigned 22 { 23 None = 0x0, 24 // Before making DirectMSI non-experimental, it should be part of manifest validation. 25 DirectMSI = 0x1, 26 Resume = 0x2, 27 Font = 0x4, 28 Max, // This MUST always be after all experimental features 29 30 // Features listed after Max will not be shown with the features command 31 // This can be used to hide highly experimental features (or these example ones) 32 ExperimentalCmd = 0x10000, 33 ExperimentalArg = 0x20000, 34 }; 35 36 using Feature_t = std::underlying_type_t<ExperimentalFeature::Feature>; 37 38 ExperimentalFeature(std::string_view name, std::string_view jsonName, std::string_view link, Feature feature) : 39 m_name(name), m_jsonName(jsonName), m_link(link), m_feature(feature) {} 40 41 ~ExperimentalFeature() = default; 42 43 ExperimentalFeature(const ExperimentalFeature&) = default; 44 ExperimentalFeature& operator=(const ExperimentalFeature&) = default; 45 46 ExperimentalFeature(ExperimentalFeature&&) = default; 47 ExperimentalFeature& operator=(ExperimentalFeature&&) = default; 48 49 static bool IsEnabled(Feature feature); 50 51 #ifndef AICLI_DISABLE_TEST_HOOKS 52 static bool IsEnabled(Feature feature, const UserSettings& userSettings); 53 #endif 54 55 static ExperimentalFeature GetFeature(ExperimentalFeature::Feature feature); 56 static std::vector<ExperimentalFeature> GetAllFeatures(); 57 58 std::string_view Name() const { return m_name; } 59 Utility::LocIndView JsonName() const { return m_jsonName; } 60 std::string_view Link() const { return m_link; } 61 Feature GetFeature() const { return m_feature; } 62 63 private: 64 std::string_view m_name; 65 Utility::LocIndView m_jsonName; 66 std::string_view m_link; 67 Feature m_feature; 68 }; 69 70 inline ExperimentalFeature::Feature operator|(ExperimentalFeature::Feature lhs, ExperimentalFeature::Feature rhs) 71 { 72 return static_cast<ExperimentalFeature::Feature> ( 73 static_cast<ExperimentalFeature::Feature_t>(lhs) | 74 static_cast<ExperimentalFeature::Feature_t>(rhs)); 75 } 76 77 inline ExperimentalFeature::Feature& operator|=(ExperimentalFeature::Feature& lhs, ExperimentalFeature::Feature rhs) 78 { 79 lhs = lhs | rhs; 80 return lhs; 81 } 82 83 inline ExperimentalFeature::Feature operator&(ExperimentalFeature::Feature lhs, ExperimentalFeature::Feature rhs) 84 { 85 return static_cast<ExperimentalFeature::Feature>( 86 static_cast<ExperimentalFeature::Feature_t>(lhs) & 87 static_cast<ExperimentalFeature::Feature_t>(rhs)); 88 } 89 90 inline ExperimentalFeature::Feature& operator&=(ExperimentalFeature::Feature& lhs, ExperimentalFeature::Feature rhs) 91 { 92 lhs = lhs & rhs; 93 return lhs; 94 } 95 }