Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ namespace cppwinrt
}
else
{
w.write(R"(, u8", ")");
w.write(R"(, L", ")");
}
w.write(", name_v<%>", param.Name());
}
Expand All @@ -366,14 +366,14 @@ namespace cppwinrt

if (empty(generics))
{
auto format = R"( template <> inline constexpr auto& name_v<%> = u8"%.%";
auto format = R"( template <> inline constexpr auto& name_v<%> = L"%.%";
)";

w.write(format, type, type_name.name_space, type_name.name);
}
else
{
auto format = R"( template <%> inline constexpr auto name_v<%> = zcombine(u8"%.%<"%, u8">");
auto format = R"( template <%> inline constexpr auto name_v<%> = zcombine(L"%.%<"%, L">");
)";

w.write(format,
Expand Down
18 changes: 10 additions & 8 deletions cppwinrt/component_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace cppwinrt
if (settings.component_opt)
{
auto format = R"(
if (requal(name, "%.%"))
if (requal(name, L"%.%"))
{
return winrt_make_%();
}
Expand All @@ -120,7 +120,7 @@ namespace cppwinrt
else
{
auto format = R"(
if (requal(name, "%.%"))
if (requal(name, L"%.%"))
{
return winrt::detach_abi(winrt::make<winrt::@::factory_implementation::%>());
}
Expand Down Expand Up @@ -149,11 +149,9 @@ bool __stdcall %_can_unload_now() noexcept
return true;
}

void* __stdcall %_get_activation_factory([[maybe_unused]] std::wstring_view const& wname)
void* __stdcall %_get_activation_factory([[maybe_unused]] std::wstring_view const& name)
{
auto name = winrt::to_string(wname);

auto requal = [](std::string_view const& left, std::string_view const& right) noexcept
auto requal = [](std::wstring_view const& left, std::wstring_view const& right) noexcept
{
return std::equal(left.rbegin(), left.rend(), right.rbegin(), right.rend());
};
Expand Down Expand Up @@ -752,7 +750,7 @@ catch (...) { return winrt::to_hresult(); }
%
hstring GetRuntimeClassName() const
{
return name_of<class_type>();
return L"%.%";
}
%%%% };
}
Expand Down Expand Up @@ -822,6 +820,8 @@ catch (...) { return winrt::to_hresult(); }
type_name,
type_name,
composable_base_name,
type_namespace,
type_name,
bind<write_component_class_override_constructors>(type),
bind<write_component_override_dispatch_base>(type),
bind<write_component_base_call>(type),
Expand All @@ -839,7 +839,7 @@ catch (...) { return winrt::to_hresult(); }

hstring GetRuntimeClassName() const
{
return name_of<instance_type>();
return L"%.%";
}
% };
}
Expand All @@ -851,6 +851,8 @@ catch (...) { return winrt::to_hresult(); }
bind<write_component_factory_interfaces>(factories),
type_namespace,
type_name,
type_namespace,
type_name,
bind<write_component_forwarders>(factories));
}

Expand Down
20 changes: 10 additions & 10 deletions strings/base_foundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ WINRT_EXPORT namespace winrt::Windows::Foundation

namespace winrt::impl
{
template <> inline constexpr auto& name_v<Windows::Foundation::Point> = u8"Windows.Foundation.Point";
template <> inline constexpr auto& name_v<Windows::Foundation::Size> = u8"Windows.Foundation.Size";
template <> inline constexpr auto& name_v<Windows::Foundation::Rect> = u8"Windows.Foundation.Rect";
template <> inline constexpr auto& name_v<Windows::Foundation::Point> = L"Windows.Foundation.Point";
template <> inline constexpr auto& name_v<Windows::Foundation::Size> = L"Windows.Foundation.Size";
template <> inline constexpr auto& name_v<Windows::Foundation::Rect> = L"Windows.Foundation.Rect";

template <> struct category<Windows::Foundation::Point>
{
Expand All @@ -123,13 +123,13 @@ namespace winrt::impl

#ifdef WINRT_IMPL_NUMERICS

template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float2> = u8"Windows.Foundation.Numerics.Vector2";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float3> = u8"Windows.Foundation.Numerics.Vector3";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float4> = u8"Windows.Foundation.Numerics.Vector4";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float3x2> = u8"Windows.Foundation.Numerics.Matrix3x2";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float4x4> = u8"Windows.Foundation.Numerics.Matrix4x4";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::quaternion> = u8"Windows.Foundation.Numerics.Quaternion";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::plane> = u8"Windows.Foundation.Numerics.Plane";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float2> = L"Windows.Foundation.Numerics.Vector2";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float3> = L"Windows.Foundation.Numerics.Vector3";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float4> = L"Windows.Foundation.Numerics.Vector4";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float3x2> = L"Windows.Foundation.Numerics.Matrix3x2";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::float4x4> = L"Windows.Foundation.Numerics.Matrix4x4";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::quaternion> = L"Windows.Foundation.Numerics.Quaternion";
template <> inline constexpr auto& name_v<Windows::Foundation::Numerics::plane> = L"Windows.Foundation.Numerics.Plane";

template <> struct category<Windows::Foundation::Numerics::float2>
{
Expand Down
175 changes: 120 additions & 55 deletions strings/base_identity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ WINRT_EXPORT namespace winrt

namespace winrt::impl
{
#ifdef __cpp_char8_t
using char_type = char8_t;
#else
using char_type = char;
#endif

template <size_t Size, typename T, size_t... Index>
constexpr std::array<T, Size> to_array(T const* value, std::index_sequence<Index...> const) noexcept
{
Expand All @@ -38,7 +32,7 @@ namespace winrt::impl
}

template <size_t Size>
constexpr auto to_array(char_type const(&value)[Size]) noexcept
constexpr auto to_array(char const(&value)[Size]) noexcept
{
return to_array<Size - 1>(value, std::make_index_sequence<Size - 1>());
}
Expand Down Expand Up @@ -433,7 +427,7 @@ namespace winrt::impl
}

template <size_t Size>
constexpr guid generate_guid(std::array<char_type, Size> const& value) noexcept
constexpr guid generate_guid(std::array<char, Size> const& value) noexcept
{
guid namespace_guid = { 0xd57af411, 0x737b, 0xc042,{ 0xab, 0xae, 0x87, 0x8b, 0x1e, 0x16, 0xad, 0xee } };

Expand All @@ -447,7 +441,7 @@ namespace winrt::impl
template <typename TArg, typename... TRest>
struct arg_collection
{
constexpr static auto data{ combine(to_array(signature<TArg>::data), u8";", arg_collection<TRest...>::data) };
constexpr static auto data{ combine(to_array(signature<TArg>::data), ";", arg_collection<TRest...>::data) };
};

template <typename TArg>
Expand All @@ -473,8 +467,8 @@ namespace winrt::impl
{
combine
(
to_array<char_type>(guid_of<T>()),
std::array<char_type, 1>{ '\0' }
to_array<wchar_t>(guid_of<T>()),
std::array<wchar_t, 1>{ L'\0' }
)
};

Expand All @@ -493,48 +487,98 @@ namespace winrt::impl
return 3;
}

constexpr size_t to_utf8(wchar_t const value, char* buffer) noexcept
{
if (value <= 0x7F)
{
*buffer = static_cast<char>(value);
return 1;
}

if (value <= 0x7FF)
{
*buffer = static_cast<char>(0xC0 | (value >> 6));
*(buffer + 1) = 0x80 | (value & 0x3F);
return 2;
}

*buffer = 0xE0 | (value >> 12);
*(buffer + 1) = 0x80 | ((value >> 6) & 0x3F);
*(buffer + 2) = 0x80 | (value & 0x3F);
return 3;
}

template <typename T>
constexpr size_t to_utf8_size() noexcept
{
auto input = to_array(name_v<T>);
size_t length = 0;

for (wchar_t const element : input)
{
length += to_utf8_size(element);
}

return length;
}

template <typename T>
constexpr auto to_utf8() noexcept
{
auto input = to_array(name_v<T>);
std::array<char, to_utf8_size<T>()> output{};
size_t offset{};

for (wchar_t const element : input)
{
offset += to_utf8(element, &output[offset]);
}

return output;
}

template <typename T>
constexpr guid generic_guid_v{};

template <typename T>
constexpr auto& basic_signature_v = u8"";

template <> inline constexpr auto& basic_signature_v<bool> = u8"b1";
template <> inline constexpr auto& basic_signature_v<int8_t> = u8"i1";
template <> inline constexpr auto& basic_signature_v<int16_t> = u8"i2";
template <> inline constexpr auto& basic_signature_v<int32_t> = u8"i4";
template <> inline constexpr auto& basic_signature_v<int64_t> = u8"i8";
template <> inline constexpr auto& basic_signature_v<uint8_t> = u8"u1";
template <> inline constexpr auto& basic_signature_v<uint16_t> = u8"u2";
template <> inline constexpr auto& basic_signature_v<uint32_t> = u8"u4";
template <> inline constexpr auto& basic_signature_v<uint64_t> = u8"u8";
template <> inline constexpr auto& basic_signature_v<float> = u8"f4";
template <> inline constexpr auto& basic_signature_v<double> = u8"f8";
template <> inline constexpr auto& basic_signature_v<char16_t> = u8"c2";
template <> inline constexpr auto& basic_signature_v<guid> = u8"g16";
template <> inline constexpr auto& basic_signature_v<hstring> = u8"string";
template <> inline constexpr auto& basic_signature_v<Windows::Foundation::IInspectable> = u8"cinterface(IInspectable)";

template <> inline constexpr auto& name_v<bool> = u8"Boolean";
template <> inline constexpr auto& name_v<int8_t> = u8"Int8";
template <> inline constexpr auto& name_v<int16_t> = u8"Int16";
template <> inline constexpr auto& name_v<int32_t> = u8"Int32";
template <> inline constexpr auto& name_v<int64_t> = u8"Int64";
template <> inline constexpr auto& name_v<uint8_t> = u8"UInt8";
template <> inline constexpr auto& name_v<uint16_t> = u8"UInt16";
template <> inline constexpr auto& name_v<uint32_t> = u8"UInt32";
template <> inline constexpr auto& name_v<uint64_t> = u8"UInt64";
template <> inline constexpr auto& name_v<float> = u8"Single";
template <> inline constexpr auto& name_v<double> = u8"Double";
template <> inline constexpr auto& name_v<char16_t> = u8"Char16";
template <> inline constexpr auto& name_v<guid> = u8"Guid";
template <> inline constexpr auto& name_v<hstring> = u8"String";
template <> inline constexpr auto& name_v<hresult> = u8"Windows.Foundation.HResult";
template <> inline constexpr auto& name_v<event_token> = u8"Windows.Foundation.EventRegistrationToken";
template <> inline constexpr auto& name_v<Windows::Foundation::IInspectable> = u8"Object";
template <> inline constexpr auto& name_v<Windows::Foundation::TimeSpan> = u8"Windows.Foundation.TimeSpan";
template <> inline constexpr auto& name_v<Windows::Foundation::DateTime> = u8"Windows.Foundation.DateTime";
template <> inline constexpr auto& name_v<IAgileObject> = u8"IAgileObject";
constexpr auto& basic_signature_v = "";

template <> inline constexpr auto& basic_signature_v<bool> = "b1";
template <> inline constexpr auto& basic_signature_v<int8_t> = "i1";
template <> inline constexpr auto& basic_signature_v<int16_t> = "i2";
template <> inline constexpr auto& basic_signature_v<int32_t> = "i4";
template <> inline constexpr auto& basic_signature_v<int64_t> = "i8";
template <> inline constexpr auto& basic_signature_v<uint8_t> = "u1";
template <> inline constexpr auto& basic_signature_v<uint16_t> = "u2";
template <> inline constexpr auto& basic_signature_v<uint32_t> = "u4";
template <> inline constexpr auto& basic_signature_v<uint64_t> = "u8";
template <> inline constexpr auto& basic_signature_v<float> = "f4";
template <> inline constexpr auto& basic_signature_v<double> = "f8";
template <> inline constexpr auto& basic_signature_v<char16_t> = "c2";
template <> inline constexpr auto& basic_signature_v<guid> = "g16";
template <> inline constexpr auto& basic_signature_v<hstring> = "string";
template <> inline constexpr auto& basic_signature_v<Windows::Foundation::IInspectable> = "cinterface(IInspectable)";

template <> inline constexpr auto& name_v<bool> = L"Boolean";
template <> inline constexpr auto& name_v<int8_t> = L"Int8";
template <> inline constexpr auto& name_v<int16_t> = L"Int16";
template <> inline constexpr auto& name_v<int32_t> = L"Int32";
template <> inline constexpr auto& name_v<int64_t> = L"Int64";
template <> inline constexpr auto& name_v<uint8_t> = L"UInt8";
template <> inline constexpr auto& name_v<uint16_t> = L"UInt16";
template <> inline constexpr auto& name_v<uint32_t> = L"UInt32";
template <> inline constexpr auto& name_v<uint64_t> = L"UInt64";
template <> inline constexpr auto& name_v<float> = L"Single";
template <> inline constexpr auto& name_v<double> = L"Double";
template <> inline constexpr auto& name_v<char16_t> = L"Char16";
template <> inline constexpr auto& name_v<guid> = L"Guid";
template <> inline constexpr auto& name_v<hstring> = L"String";
template <> inline constexpr auto& name_v<hresult> = L"Windows.Foundation.HResult";
template <> inline constexpr auto& name_v<event_token> = L"Windows.Foundation.EventRegistrationToken";
template <> inline constexpr auto& name_v<Windows::Foundation::IInspectable> = L"Object";
template <> inline constexpr auto& name_v<Windows::Foundation::TimeSpan> = L"Windows.Foundation.TimeSpan";
template <> inline constexpr auto& name_v<Windows::Foundation::DateTime> = L"Windows.Foundation.DateTime";
template <> inline constexpr auto& name_v<IAgileObject> = L"IAgileObject";

template <> struct category<bool> { using type = basic_category; };
template <> struct category<int8_t> { using type = basic_category; };
Expand Down Expand Up @@ -565,36 +609,57 @@ namespace winrt::impl
struct category_signature<enum_category, T>
{
using enum_type = std::underlying_type_t<T>;
constexpr static auto data{ combine(u8"enum(", name_v<T>, u8";", signature<enum_type>::data, u8")") };
constexpr static auto data{ combine("enum(", to_utf8<T>(), ";", signature<enum_type>::data, ")") };
};

template <typename... Fields, typename T>
struct category_signature<struct_category<Fields...>, T>
{
constexpr static auto data{ combine(u8"struct(", name_v<T>, u8";", arg_collection<Fields...>::data, u8")") };
constexpr static auto data{ combine("struct(", to_utf8<T>(), ";", arg_collection<Fields...>::data, ")") };
};

template <typename T>
struct category_signature<class_category, T>
{
constexpr static auto data{ combine(u8"rc(", name_v<T>, u8";", signature<winrt::default_interface<T>>::data, u8")") };
constexpr static auto data{ combine("rc(", to_utf8<T>(), ";", signature<winrt::default_interface<T>>::data, ")") };
};

template <typename... Args, typename T>
struct category_signature<generic_category<Args...>, T>
{
constexpr static auto data{ combine(u8"pinterface(", to_array<char_type>(generic_guid_v<T>), u8";", arg_collection<Args...>::data, u8")") };
constexpr static auto data{ combine("pinterface(", to_array<char>(generic_guid_v<T>), ";", arg_collection<Args...>::data, ")") };
};

template <typename T>
struct category_signature<interface_category, T>
{
constexpr static auto data{ to_array<char_type>(guid_of<T>()) };
constexpr static auto data{ to_array<char>(guid_of<T>()) };
};

template <typename T>
struct category_signature<delegate_category, T>
{
constexpr static auto data{ combine(u8"delegate(", to_array<char_type>(guid_of<T>()), u8")") };
constexpr static auto data{ combine("delegate(", to_array<char>(guid_of<T>()), ")") };
};

template <size_t Size>
constexpr std::wstring_view to_wstring_view(std::array<wchar_t, Size> const& value) noexcept
{
return { value.data(), Size - 1 };
}

template <size_t Size>
constexpr std::wstring_view to_wstring_view(wchar_t const (&value)[Size]) noexcept
{
return { value, Size - 1 };
}
}

WINRT_EXPORT namespace winrt
{
template <typename T>
constexpr auto name_of() noexcept
{
return impl::to_wstring_view(impl::name_v<T>);
}
}
2 changes: 1 addition & 1 deletion strings/base_implements.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ namespace winrt::impl
{
static hstring get()
{
return name_of<I>();
return hstring{ name_of<I>() };
}
};

Expand Down
Loading