Skip to content
Open
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
32 changes: 28 additions & 4 deletions cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ namespace cppwinrt
return { w, write_close_namespace };
}

[[nodiscard]] static finish_with wrap_impl_namespace_without_export(writer& w)
{
auto format = R"(namespace winrt::impl
{
)";

w.write(format);

return { w, write_close_namespace };
}

[[nodiscard]] static finish_with wrap_std_namespace(writer& w)
{
w.write(R"(namespace std
Expand Down Expand Up @@ -873,14 +884,29 @@ namespace cppwinrt
w.write(" % %;\n", get_field_abi(w, field), field.Name());
}

static void write_struct_abi(writer& w, TypeDef const& type)
static void write_struct_abi_type(writer& w, TypeDef const& type)
{
auto abi_guard = w.push_abi_types(true);

auto format = R"( struct struct_%
{
% };
template <> struct abi<@::%>
)";

type_name type_name(type);
auto impl_name = get_impl_name(type_name.name_space, type_name.name);

w.write(format,
impl_name,
bind_each<write_field_abi>(type.FieldList()));

}

static void write_struct_abi_specialization(writer& w, TypeDef const& type)
{
auto abi_guard = w.push_abi_types(true);

auto format = R"( template <> struct abi<@::%>
{
using type = struct_%;
};
Expand All @@ -890,8 +916,6 @@ namespace cppwinrt
auto impl_name = get_impl_name(type_name.name_space, type_name.name);

w.write(format,
impl_name,
bind_each<write_field_abi>(type.FieldList()),
type_name.name_space, type_name.name,
impl_name);

Expand Down
13 changes: 11 additions & 2 deletions cppwinrt/file_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace cppwinrt
w.write_each<write_forward>(members.contracts);
}
{
auto wrap_impl = wrap_impl_namespace(w);
auto wrap_impl = wrap_impl_namespace_without_export(w);
w.write_each<write_category>(members.interfaces, "interface_category");
w.write_each<write_category>(members.classes, "class_category");
w.write_each<write_category>(members.enums, "enum_category");
Expand All @@ -119,7 +119,16 @@ namespace cppwinrt
w.write_each<write_interface_abi>(members.interfaces);
w.write_each<write_delegate_abi>(members.delegates);
w.write_each<write_consume>(members.interfaces);
w.write_each<write_struct_abi>(members.structs);
}

{
auto wrap_impl = wrap_impl_namespace(w);
w.write_each<write_struct_abi_type>(members.structs);
}

{
auto wrap_impl = wrap_impl_namespace_without_export(w);
w.write_each<write_struct_abi_specialization>(members.structs);
}

write_close_file_guard(w);
Expand Down