Skip to content

Commit 1935608

Browse files
authored
Support nested Windows namespace (#904)
1 parent 2073422 commit 1935608

File tree

7 files changed

+58
-12
lines changed

7 files changed

+58
-12
lines changed

cppwinrt/code_writers.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ namespace cppwinrt
16191619
else if (optional)
16201620
{
16211621
auto format = R"( if (%) *% = nullptr;
1622-
Windows::Foundation::IInspectable winrt_impl_%;
1622+
winrt::Windows::Foundation::IInspectable winrt_impl_%;
16231623
)";
16241624

16251625
w.write(format, param_name, param_name, param_name);
@@ -1961,7 +1961,7 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable<T, D, %>
19611961

19621962
if (!found)
19631963
{
1964-
w.write(", Windows::Foundation::IInspectable");
1964+
w.write(", winrt::Windows::Foundation::IInspectable");
19651965
}
19661966
}
19671967

@@ -2314,11 +2314,11 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable<T, D, %>
23142314
if (empty(generics))
23152315
{
23162316
auto format = R"( struct __declspec(empty_bases) % :
2317-
Windows::Foundation::IInspectable,
2317+
winrt::Windows::Foundation::IInspectable,
23182318
impl::consume_t<%>%
23192319
{
23202320
%(std::nullptr_t = nullptr) noexcept {}
2321-
%(void* ptr, take_ownership_from_abi_t) noexcept : Windows::Foundation::IInspectable(ptr, take_ownership_from_abi) {}
2321+
%(void* ptr, take_ownership_from_abi_t) noexcept : winrt::Windows::Foundation::IInspectable(ptr, take_ownership_from_abi) {}
23222322
%(% const&) noexcept = default;
23232323
%(%&&) noexcept = default;
23242324
%& operator=(% const&) & noexcept = default;
@@ -2349,11 +2349,11 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable<T, D, %>
23492349

23502350
auto format = R"( template <%>
23512351
struct __declspec(empty_bases) % :
2352-
Windows::Foundation::IInspectable,
2352+
winrt::Windows::Foundation::IInspectable,
23532353
impl::consume_t<%>%
23542354
{%
23552355
%(std::nullptr_t = nullptr) noexcept {}
2356-
%(void* ptr, take_ownership_from_abi_t) noexcept : Windows::Foundation::IInspectable(ptr, take_ownership_from_abi) {}
2356+
%(void* ptr, take_ownership_from_abi_t) noexcept : winrt::Windows::Foundation::IInspectable(ptr, take_ownership_from_abi) {}
23572357
%(% const&) noexcept = default;
23582358
%(%&&) noexcept = default;
23592359
%& operator=(% const&) & noexcept = default;
@@ -2925,7 +2925,7 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable<T, D, %>
29252925

29262926
auto format = R"( inline %::%(%)
29272927
{
2928-
Windows::Foundation::IInspectable %, %;
2928+
winrt::Windows::Foundation::IInspectable %, %;
29292929
*this = % { return f.%(%%%, %); });
29302930
}
29312931
)";
@@ -3056,15 +3056,15 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable<T, D, %>
30563056
if (has_fastabi(type))
30573057
{
30583058
format = R"( inline %::%() :
3059-
%(impl::call_factory_cast<%(*)(Windows::Foundation::IActivationFactory const&), %>([](Windows::Foundation::IActivationFactory const& f) { return impl::fast_activate<%>(f); }))
3059+
%(impl::call_factory_cast<%(*)(winrt::Windows::Foundation::IActivationFactory const&), %>([](winrt::Windows::Foundation::IActivationFactory const& f) { return impl::fast_activate<%>(f); }))
30603060
{
30613061
}
30623062
)";
30633063
}
30643064
else
30653065
{
30663066
format = R"( inline %::%() :
3067-
%(impl::call_factory_cast<%(*)(Windows::Foundation::IActivationFactory const&), %>([](Windows::Foundation::IActivationFactory const& f) { return f.template ActivateInstance<%>(); }))
3067+
%(impl::call_factory_cast<%(*)(winrt::Windows::Foundation::IActivationFactory const&), %>([](winrt::Windows::Foundation::IActivationFactory const& f) { return f.template ActivateInstance<%>(); }))
30683068
{
30693069
}
30703070
)";

cppwinrt/component_writers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ catch (...) { return winrt::to_hresult(); }
347347

348348
if (!default_constructor)
349349
{
350-
w.write(R"( [[noreturn]] Windows::Foundation::IInspectable ActivateInstance() const
350+
w.write(R"( [[noreturn]] winrt::Windows::Foundation::IInspectable ActivateInstance() const
351351
{
352352
throw hresult_not_implemented();
353353
}
@@ -831,7 +831,7 @@ catch (...) { return winrt::to_hresult(); }
831831
auto format = R"(namespace winrt::@::factory_implementation
832832
{
833833
template <typename D, typename T, typename... I>
834-
struct __declspec(empty_bases) %T : implements<D, Windows::Foundation::IActivationFactory%, I...>
834+
struct __declspec(empty_bases) %T : implements<D, winrt::Windows::Foundation::IActivationFactory%, I...>
835835
{
836836
using instance_type = @::%;
837837

cppwinrt/type_writers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ namespace cppwinrt
504504
}
505505
else
506506
{
507-
write("Windows::Foundation::IInspectable");
507+
write("winrt::Windows::Foundation::IInspectable");
508508
}
509509
}
510510
else

test/test_component/Windows.Class.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "pch.h"
2+
#include "Windows.Class.h"
3+
#include "Windows.Class.g.cpp"
4+
5+
namespace winrt::test_component::Windows::implementation
6+
{
7+
void Class::StaticMethod()
8+
{
9+
throw hresult_not_implemented();
10+
}
11+
void Class::Method()
12+
{
13+
throw hresult_not_implemented();
14+
}
15+
}

test/test_component/Windows.Class.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
#include "Windows.Class.g.h"
3+
4+
namespace winrt::test_component::Windows::implementation
5+
{
6+
struct Class : ClassT<Class>
7+
{
8+
Class() = default;
9+
10+
static void StaticMethod();
11+
void Method();
12+
};
13+
}
14+
namespace winrt::test_component::Windows::factory_implementation
15+
{
16+
struct Class : ClassT<Class, implementation::Class>
17+
{
18+
};
19+
}

test/test_component/test_component.idl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,14 @@ namespace test_component
277277
}
278278
}
279279
}
280+
281+
namespace Windows
282+
{
283+
runtimeclass Class
284+
{
285+
Class();
286+
static void StaticMethod();
287+
void Method();
288+
}
289+
}
280290
}

test/test_component/test_component.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@
620620
<ClCompile Include="Velocity.Class1.cpp" />
621621
<ClCompile Include="Velocity.Class2.cpp" />
622622
<ClCompile Include="Velocity.Class4.cpp" />
623+
<ClCompile Include="Windows.Class.cpp" />
623624
</ItemGroup>
624625
<ItemGroup>
625626
<ClInclude Include="Class.h" />
@@ -628,6 +629,7 @@
628629
<ClInclude Include="Velocity.Class1.h" />
629630
<ClInclude Include="Velocity.Class2.h" />
630631
<ClInclude Include="Velocity.Class4.h" />
632+
<ClInclude Include="Windows.Class.h" />
631633
</ItemGroup>
632634
<ItemGroup>
633635
<None Include="exports.def" />

0 commit comments

Comments
 (0)