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
24 changes: 13 additions & 11 deletions cppwinrt/type_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ namespace cppwinrt
return result;
}

static bool transform_special_numeric_type(std::string_view& name)
{
if (name == "Matrix3x2") { name = "float3x2"; return true; }
else if (name == "Matrix4x4") { name = "float4x4"; return true; }
else if (name == "Plane") { name = "plane"; return true; }
else if (name == "Quaternion") { name = "quaternion"; return true; }
else if (name == "Vector2") { name = "float2"; return true; }
else if (name == "Vector3") { name = "float3"; return true; }
else if (name == "Vector4") { name = "float4"; return true; }
return false;
}

struct writer : writer_base<writer>
{
using writer_base<writer>::write;
Expand Down Expand Up @@ -277,8 +289,6 @@ namespace cppwinrt
return;
}

// TODO: get rid of all these renames once parity with cppwinrt.exe has been reached...

if (name == "EventRegistrationToken" && ns == "Windows.Foundation")
{
write("winrt::event_token");
Expand All @@ -291,16 +301,8 @@ namespace cppwinrt
{
auto category = get_category(type);

if (ns == "Windows.Foundation.Numerics")
if (ns == "Windows.Foundation.Numerics" && transform_special_numeric_type(name))
{
if (name == "Matrix3x2") { name = "float3x2"; }
else if (name == "Matrix4x4") { name = "float4x4"; }
else if (name == "Plane") { name = "plane"; }
else if (name == "Quaternion") { name = "quaternion"; }
else if (name == "Vector2") { name = "float2"; }
else if (name == "Vector3") { name = "float3"; }
else if (name == "Vector4") { name = "float4"; }

write("winrt::@::%", ns, name);
}
else if (category == category::struct_type)
Expand Down
18 changes: 18 additions & 0 deletions test/test/rational.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "pch.h"
#include "winrt/test_component.h"
#include "winrt/Windows.Foundation.Numerics.h"

using namespace winrt;
using namespace test_component;

TEST_CASE("rational")
{
Simple simple;
Windows::Foundation::Numerics::Rational rational = simple.ReturnRational();
REQUIRE(rational.Numerator == 123);
REQUIRE(rational.Denominator == 456);

Windows::Foundation::Numerics::float2 vector2 = simple.ReturnVector2();
REQUIRE(vector2.x == 123.0);
REQUIRE(vector2.y == 456.0);
}
1 change: 1 addition & 0 deletions test/test/test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="rational.cpp" />
<ClCompile Include="return_params.cpp" />
<ClCompile Include="return_params_abi.cpp" />
<ClCompile Include="single_threaded_observable_vector.cpp" />
Expand Down
10 changes: 10 additions & 0 deletions test/test_component/Simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ namespace winrt::test_component::implementation
// All we care about static events (for now) is that they build.
static event_token StaticEvent(Windows::Foundation::EventHandler<IInspectable> const&) { return {}; }
static void StaticEvent(event_token) { }

Windows::Foundation::Numerics::float2 ReturnVector2()
{
return { 123.0, 456.0 };
}

Windows::Foundation::Numerics::Rational ReturnRational()
{
return { 123, 456 };
}
};
}
namespace winrt::test_component::factory_implementation
Expand Down
3 changes: 3 additions & 0 deletions test/test_component/test_component.idl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ namespace test_component
Windows.Foundation.IAsyncAction Action(Windows.Foundation.DateTime value);
Object Object(Windows.Foundation.DateTime value);
static event Windows.Foundation.EventHandler<Object> StaticEvent;

Windows.Foundation.Numerics.Vector2 ReturnVector2();
Windows.Foundation.Numerics.Rational ReturnRational();
}

runtimeclass DeferrableEventArgs
Expand Down