package_spec_parse_result -> PackageSpecParseResult

This commit is contained in:
Alexander Karatarakis 2017-04-03 14:47:30 -07:00
parent d1141e6054
commit 83cde51334
8 changed files with 68 additions and 68 deletions

View File

@ -1,5 +1,5 @@
#pragma once
#include "package_spec_parse_result.h"
#include "PackageSpecParseResult.h"
#include "triplet.h"
#include "vcpkg_expected.h"

View File

@ -3,14 +3,14 @@
namespace vcpkg
{
enum class package_spec_parse_result
enum class PackageSpecParseResult
{
SUCCESS = 0,
TOO_MANY_COLONS,
INVALID_CHARACTERS
};
struct package_spec_parse_result_category_impl final : std::error_category
struct PackageSpecParseResultCategoryImpl final : std::error_category
{
virtual const char* name() const noexcept override;
@ -19,18 +19,18 @@ namespace vcpkg
const std::error_category& package_spec_parse_result_category();
std::error_code make_error_code(package_spec_parse_result e);
std::error_code make_error_code(PackageSpecParseResult e);
package_spec_parse_result to_package_spec_parse_result(int i);
PackageSpecParseResult to_package_spec_parse_result(int i);
package_spec_parse_result to_package_spec_parse_result(std::error_code ec);
PackageSpecParseResult to_package_spec_parse_result(std::error_code ec);
}
// Enable implicit conversion to std::error_code
namespace std
{
template <>
struct is_error_code_enum<vcpkg::package_spec_parse_result> : ::std::true_type
struct is_error_code_enum<vcpkg::PackageSpecParseResult> : ::std::true_type
{
};
}

View File

@ -19,7 +19,7 @@ namespace vcpkg
auto pos2 = spec_as_string.find(':', pos + 1);
if (pos2 != std::string::npos)
{
return std::error_code(package_spec_parse_result::TOO_MANY_COLONS);
return std::error_code(PackageSpecParseResult::TOO_MANY_COLONS);
}
const std::string name = spec_as_string.substr(0, pos);
@ -31,7 +31,7 @@ namespace vcpkg
{
if (std::find_if_not(name.cbegin(), name.cend(), is_valid_package_spec_char) != name.end())
{
return std::error_code(package_spec_parse_result::INVALID_CHARACTERS);
return std::error_code(PackageSpecParseResult::INVALID_CHARACTERS);
}
PackageSpec p;

View File

@ -0,0 +1,47 @@
#include "pch.h"
#include "vcpkg_Checks.h"
#include "PackageSpecParseResult.h"
namespace vcpkg
{
const char* PackageSpecParseResultCategoryImpl::name() const noexcept
{
return "PackageSpecParseResult";
}
std::string PackageSpecParseResultCategoryImpl::message(int ev) const noexcept
{
switch (static_cast<PackageSpecParseResult>(ev))
{
case PackageSpecParseResult::SUCCESS:
return "OK";
case PackageSpecParseResult::TOO_MANY_COLONS:
return "Too many colons";
case PackageSpecParseResult::INVALID_CHARACTERS:
return "Contains invalid characters. Only alphanumeric lowercase ASCII characters and dashes are allowed";
default:
Checks::unreachable(VCPKG_LINE_INFO);
}
}
const std::error_category& package_spec_parse_result_category()
{
static PackageSpecParseResultCategoryImpl instance;
return instance;
}
std::error_code make_error_code(PackageSpecParseResult e)
{
return std::error_code(static_cast<int>(e), package_spec_parse_result_category());
}
PackageSpecParseResult to_package_spec_parse_result(int i)
{
return static_cast<PackageSpecParseResult>(i);
}
PackageSpecParseResult to_package_spec_parse_result(std::error_code ec)
{
return to_package_spec_parse_result(ec.value());
}
}

View File

@ -1,47 +0,0 @@
#include "pch.h"
#include "vcpkg_Checks.h"
#include "package_spec_parse_result.h"
namespace vcpkg
{
const char* package_spec_parse_result_category_impl::name() const noexcept
{
return "package_spec_parse_result";
}
std::string package_spec_parse_result_category_impl::message(int ev) const noexcept
{
switch (static_cast<package_spec_parse_result>(ev))
{
case package_spec_parse_result::SUCCESS:
return "OK";
case package_spec_parse_result::TOO_MANY_COLONS:
return "Too many colons";
case package_spec_parse_result::INVALID_CHARACTERS:
return "Contains invalid characters. Only alphanumeric lowercase ASCII characters and dashes are allowed";
default:
Checks::unreachable(VCPKG_LINE_INFO);
}
}
const std::error_category& package_spec_parse_result_category()
{
static package_spec_parse_result_category_impl instance;
return instance;
}
std::error_code make_error_code(package_spec_parse_result e)
{
return std::error_code(static_cast<int>(e), package_spec_parse_result_category());
}
package_spec_parse_result to_package_spec_parse_result(int i)
{
return static_cast<package_spec_parse_result>(i);
}
package_spec_parse_result to_package_spec_parse_result(std::error_code ec)
{
return to_package_spec_parse_result(ec.value());
}
}

View File

@ -10,7 +10,7 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Microsoft::VisualStudio::CppUnitTestFramework
{
template <>
inline std::wstring ToString<vcpkg::package_spec_parse_result>(const vcpkg::package_spec_parse_result& t)
inline std::wstring ToString<vcpkg::PackageSpecParseResult>(const vcpkg::PackageSpecParseResult& t)
{
return ToString(static_cast<uint32_t>(t));
}
@ -351,7 +351,7 @@ namespace UnitTest1
TEST_METHOD(package_spec_parse)
{
vcpkg::expected<vcpkg::PackageSpec> spec = vcpkg::PackageSpec::from_string("zlib", vcpkg::triplet::X86_WINDOWS);
Assert::AreEqual(vcpkg::package_spec_parse_result::SUCCESS, vcpkg::to_package_spec_parse_result(spec.error_code()));
Assert::AreEqual(vcpkg::PackageSpecParseResult::SUCCESS, vcpkg::to_package_spec_parse_result(spec.error_code()));
Assert::AreEqual("zlib", spec.get()->name().c_str());
Assert::AreEqual(vcpkg::triplet::X86_WINDOWS.canonical_name(), spec.get()->target_triplet().canonical_name());
}
@ -359,7 +359,7 @@ namespace UnitTest1
TEST_METHOD(package_spec_parse_with_arch)
{
vcpkg::expected<vcpkg::PackageSpec> spec = vcpkg::PackageSpec::from_string("zlib:x64-uwp", vcpkg::triplet::X86_WINDOWS);
Assert::AreEqual(vcpkg::package_spec_parse_result::SUCCESS, vcpkg::to_package_spec_parse_result(spec.error_code()));
Assert::AreEqual(vcpkg::PackageSpecParseResult::SUCCESS, vcpkg::to_package_spec_parse_result(spec.error_code()));
Assert::AreEqual("zlib", spec.get()->name().c_str());
Assert::AreEqual(vcpkg::triplet::X64_UWP.canonical_name(), spec.get()->target_triplet().canonical_name());
}
@ -367,7 +367,7 @@ namespace UnitTest1
TEST_METHOD(package_spec_parse_with_multiple_colon)
{
auto ec = vcpkg::PackageSpec::from_string("zlib:x86-uwp:", vcpkg::triplet::X86_WINDOWS).error_code();
Assert::AreEqual(vcpkg::package_spec_parse_result::TOO_MANY_COLONS, vcpkg::to_package_spec_parse_result(ec));
Assert::AreEqual(vcpkg::PackageSpecParseResult::TOO_MANY_COLONS, vcpkg::to_package_spec_parse_result(ec));
}
TEST_METHOD(utf8_to_utf16)

View File

@ -151,7 +151,7 @@
<ClInclude Include="..\include\metrics.h" />
<ClInclude Include="..\include\OptBool.h" />
<ClInclude Include="..\include\PackageSpec.h" />
<ClInclude Include="..\include\package_spec_parse_result.h" />
<ClInclude Include="..\include\PackageSpecParseResult.h" />
<ClInclude Include="..\include\Paragraphs.h" />
<ClInclude Include="..\include\pch.h" />
<ClInclude Include="..\include\PostBuildLint.h" />
@ -226,7 +226,7 @@
<ClCompile Include="..\src\vcpkg_Chrono.cpp" />
<ClCompile Include="..\src\vcpkglib.cpp" />
<ClCompile Include="..\src\PackageSpec.cpp" />
<ClCompile Include="..\src\package_spec_parse_result.cpp" />
<ClCompile Include="..\src\PackageSpecParseResult.cpp" />
<ClCompile Include="..\src\Paragraphs.cpp" />
<ClCompile Include="..\src\SourceParagraph.cpp" />
<ClCompile Include="..\src\StatusParagraph.cpp" />

View File

@ -15,9 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\package_spec_parse_result.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\SourceParagraph.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -180,11 +177,11 @@
<ClCompile Include="..\src\PackageSpec.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\PackageSpecParseResult.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\package_spec_parse_result.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\SourceParagraph.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -314,5 +311,8 @@
<ClInclude Include="..\include\PackageSpec.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\PackageSpecParseResult.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>