static void write_component_g_h()

in cppwinrt/component_writers.h [732:888]


    static void write_component_g_h(writer& w, TypeDef const& type)
    {
        auto type_name = type.TypeName();
        auto type_namespace = type.TypeNamespace();
        auto factories = get_factories(w, type);
        bool const non_static = !empty(type.InterfaceImpl());

        if (non_static)
        {
            auto format = R"(namespace winrt::@::implementation
{
    template <typename D%, typename... I>
    struct __declspec(empty_bases) %_base : implements<D, @::%%%, %I...>%%%
    {
        using base_type = %_base;
        using class_type = @::%;
        using implements_type = typename %_base::implements_type;
        using implements_type::implements_type;
        %
        hstring GetRuntimeClassName() const
        {
            return L"%.%";
        }
%%%%    };
}
)";

            auto base_type = get_base_class(type);
            std::string composable_base_name;
            std::string base_type_parameter;
            std::string base_type_argument;
            std::string no_module_lock;
            std::string external_requires;

            if (base_type)
            {
                bool const external_base_type = !settings.component_filter.includes(base_type);

                if (external_base_type)
                {
                    composable_base_name = w.write_temp("using composable_base = %;", base_type);
                    auto base_interfaces = get_interfaces(w, base_type);
                    uint32_t base_interfaces_count{};
                    external_requires = ",\n        impl::require<D";

                    for (auto&&[name, info] : base_interfaces)
                    {
                        if (info.overridable || is_always_disabled(info.type))
                        {
                            continue;
                        }

                        ++base_interfaces_count;
                        external_requires += ", ";
                        external_requires += name;
                    }

                    if (base_interfaces_count)
                    {
                        external_requires += '>';
                    }
                    else
                    {
                        external_requires.clear();
                    }
                }
                else
                {
                    base_type_parameter = ", typename B";
                    base_type_argument = ", B";
                    no_module_lock = "no_module_lock, ";
                }
            }

            w.write(format,
                type_namespace,
                base_type_parameter,
                type_name,
                type_namespace,
                type_name,
                bind<write_component_interfaces>(type),
                base_type_argument,
                no_module_lock,
                external_requires,
                bind<write_component_class_base>(type),
                bind<write_component_override_defaults>(type),
                type_name,
                type_namespace,
                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),
                bind<write_component_tearoff>(type, !base_type_parameter.empty()));
        }

        if (has_factory_members(w, type))
        {
            auto format = R"(namespace winrt::@::factory_implementation
{
    template <typename D, typename T, typename... I>
    struct __declspec(empty_bases) %T : implements<D, winrt::Windows::Foundation::IActivationFactory%, I...>
    {
        using instance_type = @::%;

        hstring GetRuntimeClassName() const
        {
            return L"%.%";
        }
%    };
}
)";

            w.write(format,
                type_namespace,
                type_name,
                bind<write_component_factory_interfaces>(factories),
                type_namespace,
                type_name,
                type_namespace,
                type_name,
                bind<write_component_forwarders>(factories));
        }

        if (non_static)
        {
            auto format = R"(
#if defined(WINRT_FORCE_INCLUDE_%_XAML_G_H) || __has_include("%.xaml.g.h")
#include "%.xaml.g.h"
#else

namespace winrt::@::implementation
{
    template <typename D, typename... I>
    using %T = %_base<D, I...>;
}

#endif
)";

            std::string upper(type_name);
            std::transform(upper.begin(), upper.end(), upper.begin(), [](char c) {return static_cast<char>(::toupper(c)); });

            auto include_path = get_generated_component_filename(type);

            w.write(format,
                upper,
                include_path,
                include_path,
                type_namespace,
                type_name,
                type_name);
        }
    }