Rework OptBool enum
MODIFY
include/OptBool.h
include/OptBool.h
#include <string>
#include <map>
-namespace vcpkg::OptBool
+namespace vcpkg
+{
+ struct OptBool final
{
- enum class Type
+ enum class BackingEnum
{
UNSPECIFIED = 0,
ENABLED,
DISABLED
};
- Type parse(const std::string& s);
+ static OptBool parse(const std::string& s);
+
+ template<class T>
+ static OptBool from_map(const std::map<T, std::string>& map, const T& key);
+
+ constexpr OptBool() : backing_enum(BackingEnum::UNSPECIFIED) {}
+ constexpr explicit OptBool(BackingEnum backing_enum) : backing_enum(backing_enum) { }
+ constexpr operator BackingEnum() const { return backing_enum; }
+
+ private:
+ BackingEnum backing_enum;
+ };
+
+ namespace OptBoolC
+ {
+ constexpr OptBool UNSPECIFIED(OptBool::BackingEnum::UNSPECIFIED);
+ constexpr OptBool ENABLED(OptBool::BackingEnum::ENABLED);
+ constexpr OptBool DISABLED(OptBool::BackingEnum::DISABLED);
+ }
template<class T>
- Type from_map(const std::map<T, std::string>& map, const T& key)
+ OptBool OptBool::from_map(const std::map<T, std::string>& map, const T& key)
{
auto it = map.find(key);
if (it == map.cend())
{
- return Type::UNSPECIFIED;
+ return OptBoolC::UNSPECIFIED;
}
return parse(*it);
}
}
-
-namespace vcpkg
-{
- using OptBoolT = OptBool::Type;
-}
\ No newline at end of file

MODIFY
include/PostBuildLint_BuildInfo.h
include/PostBuildLint_BuildInfo.h
@@ -15,7 +15,7 @@ namespace vcpkg::PostBuildLint
LinkageType::Type crt_linkage;
LinkageType::Type library_linkage;
- std::map<BuildPolicies, OptBoolT> policies;
+ std::map<BuildPolicies, OptBool> policies;
};
BuildInfo read_build_info(const Files::Filesystem& fs, const fs::path& filepath);

MODIFY
include/VcpkgCmdArguments.h
include/VcpkgCmdArguments.h
@@ -14,9 +14,9 @@ namespace vcpkg
std::unique_ptr<std::string> vcpkg_root_dir;
std::unique_ptr<std::string> triplet;
- OptBoolT debug = OptBoolT::UNSPECIFIED;
- OptBoolT sendmetrics = OptBoolT::UNSPECIFIED;
- OptBoolT printmetrics = OptBoolT::UNSPECIFIED;
+ OptBool debug = OptBoolC::UNSPECIFIED;
+ OptBool sendmetrics = OptBoolC::UNSPECIFIED;
+ OptBool printmetrics = OptBoolC::UNSPECIFIED;
std::string command;
std::vector<std::string> command_arguments;

MODIFY
src/OptBool.cpp
src/OptBool.cpp
#include "OptBool.h"
#include "vcpkg_Checks.h"
-namespace vcpkg::OptBool
+namespace vcpkg
{
static const std::string UNSPECIFIED_NAME = "unspecified";
static const std::string ENABLED_NAME = "enabled";
static const std::string DISABLED_NAME = "disabled";
- Type parse(const std::string& s)
+
+ OptBool OptBool::parse(const std::string& s)
{
if (s == UNSPECIFIED_NAME)
{
- return OptBoolT::UNSPECIFIED;
+ return OptBoolC::UNSPECIFIED;
}
if (s == ENABLED_NAME)
{
- return OptBoolT::ENABLED;
+ return OptBoolC::ENABLED;
}
if (s == DISABLED_NAME)
{
- return OptBoolT::DISABLED;
+ return OptBoolC::DISABLED;
}
Checks::exit_with_message(VCPKG_LINE_INFO, "Could not convert string [%s] to OptBool", s);

MODIFY
src/PostBuildLint.cpp
src/PostBuildLint.cpp
@@ -31,8 +31,8 @@ namespace vcpkg::PostBuildLint
std::regex regex;
OutdatedDynamicCrt(const std::string& name, const std::string& regex_as_string)
- : name(name),
- regex(std::regex(regex_as_string, std::regex_constants::icase)) {}
+ : name(name)
+ , regex(std::regex(regex_as_string, std::regex_constants::icase)) {}
};
const std::vector<OutdatedDynamicCrt>& get_outdated_dynamic_crts()
@@ -62,10 +62,10 @@ namespace vcpkg::PostBuildLint
}
template<class T>
- static bool contains_and_enabled(const std::map<T, OptBoolT> map, const T& key)
+ static bool contains_and_enabled(const std::map<T, OptBool> map, const T& key)
{
auto it = map.find(key);
- if (it != map.cend() && it->second == OptBoolT::ENABLED)
+ if (it != map.cend() && it->second == OptBoolC::ENABLED)
{
return true;
}
@@ -73,7 +73,7 @@ namespace vcpkg::PostBuildLint
return false;
}
- static LintStatus check_for_files_in_include_directory(const Files::Filesystem& fs, const std::map<BuildPolicies, OptBoolT>& policies, const fs::path& package_dir)
+ static LintStatus check_for_files_in_include_directory(const Files::Filesystem& fs, const std::map<BuildPolicies, OptBool>& policies, const fs::path& package_dir)
{
if (contains_and_enabled(policies, BuildPoliciesC::EMPTY_INCLUDE_FOLDER))
{
@@ -443,10 +443,10 @@ namespace vcpkg::PostBuildLint
return LintStatus::ERROR_DETECTED;
}
- static LintStatus check_lib_files_are_available_if_dlls_are_available(const std::map<BuildPolicies, OptBoolT>& policies, const size_t lib_count, const size_t dll_count, const fs::path& lib_dir)
+ static LintStatus check_lib_files_are_available_if_dlls_are_available(const std::map<BuildPolicies, OptBool>& policies, const size_t lib_count, const size_t dll_count, const fs::path& lib_dir)
{
auto it = policies.find(BuildPoliciesC::DLLS_WITHOUT_LIBS);
- if (it != policies.cend() && it->second == OptBoolT::ENABLED)
+ if (it != policies.cend() && it->second == OptBoolC::ENABLED)
{
return LintStatus::SUCCESS;
}

MODIFY
src/PostBuildLint_BuildInfo.cpp
src/PostBuildLint_BuildInfo.cpp
@@ -30,7 +30,7 @@ namespace vcpkg::PostBuildLint
{
const BuildPolicies policy = BuildPolicies::parse(p.first);
Checks::check_exit(VCPKG_LINE_INFO, policy != BuildPoliciesC::NULLVALUE, "Unknown policy found: %s", p.first);
- const OptBoolT status = OptBool::parse(p.second);
+ const OptBool status = OptBool::parse(p.second);
build_info.policies.emplace(policy, status);
}

MODIFY
src/VcpkgCmdArguments.cpp
src/VcpkgCmdArguments.cpp
@@ -32,11 +32,11 @@ namespace vcpkg
}
static void parse_switch(
- OptBoolT new_setting,
+ OptBool new_setting,
const std::string& option_name,
- OptBoolT& option_field)
+ OptBool& option_field)
{
- if (option_field != OptBoolT::UNSPECIFIED && option_field != new_setting)
+ if (option_field != OptBoolC::UNSPECIFIED && option_field != new_setting)
{
System::println(System::Color::error, "Error: conflicting values specified for --%s", option_name);
Metrics::track_property("error", "error conflicting switches");
@@ -93,27 +93,27 @@ namespace vcpkg
}
if (arg == "--debug")
{
- parse_switch(OptBoolT::ENABLED, "debug", args.debug);
+ parse_switch(OptBoolC::ENABLED, "debug", args.debug);
continue;
}
if (arg == "--sendmetrics")
{
- parse_switch(OptBoolT::ENABLED, "sendmetrics", args.sendmetrics);
+ parse_switch(OptBoolC::ENABLED, "sendmetrics", args.sendmetrics);
continue;
}
if (arg == "--printmetrics")
{
- parse_switch(OptBoolT::ENABLED, "printmetrics", args.printmetrics);
+ parse_switch(OptBoolC::ENABLED, "printmetrics", args.printmetrics);
continue;
}
if (arg == "--no-sendmetrics")
{
- parse_switch(OptBoolT::DISABLED, "sendmetrics", args.sendmetrics);
+ parse_switch(OptBoolC::DISABLED, "sendmetrics", args.sendmetrics);
continue;
}
if (arg == "--no-printmetrics")
{
- parse_switch(OptBoolT::DISABLED, "printmetrics", args.printmetrics);
+ parse_switch(OptBoolC::DISABLED, "printmetrics", args.printmetrics);
continue;
}

MODIFY
src/vcpkg.cpp
src/vcpkg.cpp
@@ -199,14 +199,14 @@ int wmain(const int argc, const wchar_t* const* const argv)
const VcpkgCmdArguments args = VcpkgCmdArguments::create_from_command_line(argc, argv);
- if (args.printmetrics != OptBoolT::UNSPECIFIED)
- Metrics::set_print_metrics(args.printmetrics == OptBoolT::ENABLED);
- if (args.sendmetrics != OptBoolT::UNSPECIFIED)
- Metrics::set_send_metrics(args.sendmetrics == OptBoolT::ENABLED);
+ if (args.printmetrics != OptBoolC::UNSPECIFIED)
+ Metrics::set_print_metrics(args.printmetrics == OptBoolC::ENABLED);
+ if (args.sendmetrics != OptBoolC::UNSPECIFIED)
+ Metrics::set_send_metrics(args.sendmetrics == OptBoolC::ENABLED);
- if (args.debug != OptBoolT::UNSPECIFIED)
+ if (args.debug != OptBoolC::UNSPECIFIED)
{
- g_debugging = (args.debug == OptBoolT::ENABLED);
+ g_debugging = (args.debug == OptBoolC::ENABLED);
}
if (g_debugging)

Rework OptBool enum