当前位置: 首页>>代码示例>>C++>>正文


C++ type::constructors方法代码示例

本文整理汇总了C++中type::constructors方法的典型用法代码示例。如果您正苦于以下问题:C++ type::constructors方法的具体用法?C++ type::constructors怎么用?C++ type::constructors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在type的用法示例。


在下文中一共展示了type::constructors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: t

custom_attribute::custom_attribute(std::nullptr_t, metadata::custom_attribute_token const& attribute, core::internal_key)
{
    core::assert_initialized(attribute);

    metadata::custom_attribute_row const attribute_row(row_from(attribute));

    static metadata::binding_flags const flags(metadata::binding_attribute::all_instance);

    _attribute = attribute;

    switch (attribute_row.type().table())
    {
    case metadata::table_id::method_def:
    {
        metadata::method_def_token const ctor_token(attribute_row.type().as<metadata::method_def_token>());
        metadata::type_def_token   const owner_token(metadata::find_owner_of_method_def(ctor_token).token());

        type const t(owner_token, core::internal_key());

        auto const constructors(t.constructors(flags));
        auto const constructor_it(core::find_if(constructors, [&](method const& ctor)
        {
            return ctor.metadata_token() == ctor_token.value();
        }));

        if (constructor_it == end(constructors))
            throw core::runtime_error(L"failed to find constructor for attribute");

        _reflected_type    = constructor_it->reflected_type().context(core::internal_key());
        _constructor.get() = &constructor_it->context(core::internal_key());
        break;
    }

    case metadata::table_id::member_ref:
    {
        metadata::member_ref_row const ref_row(row_from(attribute_row.type().as<metadata::member_ref_token>()));
        metadata::member_ref_parent_token const owner_token(ref_row.parent());

        switch (owner_token.table())
        {
        case metadata::table_id::type_ref:
        {
            type const t(owner_token.as<metadata::type_ref_token>(), core::internal_key());
            if (ref_row.name() == L".ctor")
            {
                // TODO Correct detection of contructors

                if (t.constructors(flags).empty())
                    core::assert_not_yet_implemented();

                detail::loader_context const& root(detail::loader_context::from(owner_token.scope()));

                metadata::signature_comparer const compare(&root);

                auto const constructors(t.constructors(flags));
                auto const constructor_it(core::find_if(constructors, [&](method const& ctor)
                {
                    return compare(
                               ref_row.signature().as<metadata::method_signature>(),
                               ctor.context(core::internal_key()).member_signature());
                }));

                if (constructor_it == end(constructors))
                    throw core::runtime_error(L"failed to find constructor for attribute");

                _reflected_type    = constructor_it->reflected_type().context(core::internal_key());
                _constructor.get() = &constructor_it->context(core::internal_key());
                break;
            }
            else
            {
                core::assert_not_yet_implemented();
            }
        }

        default:
        {
            core::assert_not_yet_implemented();
        }
        }

        break;
    }

    default:
    {
        core::assert_unreachable();
    }
    }
}
开发者ID:dbremner,项目名称:cxxreflect,代码行数:90,代码来源:custom_attribute.cpp


注:本文中的type::constructors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。