链接两个枚举类型成员 [英] Link two enumated type members

查看:187
本文介绍了链接两个枚举类型成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我包装IDirect3D8类(基本上,重新实现它),我使用DXGI枚举适配器模式。出现了问题。

I am wrapping the IDirect3D8 class (basically, re-implementing it) and I used DXGI to enumerate adapter modes. There comes the problem.

D3DDISPLAYMODE的Format成员需要它是D3DFORMAT枚举类型的成员,虽然IDXGIOutput :: GetDisplayModeList返回,显然是DXGI_FORMAT枚举的成员类型,这完全不同于D3DFORMAT。我需要的DXGI_FORMAT成员链接到D3DFORMAT的。

D3DDISPLAYMODE's Format member requires that it be a member of the D3DFORMAT enumerated type, though IDXGIOutput::GetDisplayModeList returns, obviously, a member of the DXGI_FORMAT enumerated type, which is completely different from D3DFORMAT. I need to link the DXGI_FORMAT members to the D3DFORMAT ones.

我的第一个想法是写一个检查类型,并将其重定向到正确的D3DFORMAT成员,因此功能,但这不是一个很好的主意(他们在D3DFORMAT的67个成员)。然后我想出了一个想法,我可以有一个数组的索引是DXGI_FORMAT成员的值,他们的值将是相应的D3DFORMAT成员,但我不知道 - 可能有一个更好的方法,我会浪费时间。是否有这样做的更好或者更简单的方法?

My first idea was to write a function which checks the type and redirects it to the proper D3DFORMAT member, accordingly, but this isn't a very nice idea (they're 67 members in D3DFORMAT). Then I came up with the idea that I could have an array whose indices would be the values of the DXGI_FORMAT members and their values would be the corresponding D3DFORMAT members, but I'm not sure - there might be a better way and I'll be wasting time. Is there a better or easier way of doing this?

推荐答案

无论你是否真的需要这种映射取决于你的具体实施。但是,我看不到一个更好的方法来映射这些枚举。静态数组常量是更多的内存和运行效率比的std ::地图的std :: multimap中,因为钥匙/ indices是连续的,并且键和值只需要(8 - )32位。
,而在初始化数组常量可以比将值转换为地图或动态数组容易出现更多的错误。

Whether or not you really require this mapping depends on your specific implementation. However, I can't see a better way to map those enumerators. A static array constant is more memory and runtime efficient than std::map or std::multimap, because the keys/indices are contiguous and both, keys and values require just (8 - ) 32 bits each. But initializing the array constant can be more error prone than putting values into a map or an array dynamically.

要避免误差修改,批注键(等于实际的数组索引值)...

To avoid erros, annotate the key (with a value equal to the actual array index)...

const D3DFORMAT dxgi_d3d_format_mapping[] = {
    /*DXGI_FORMAT_UNKNOWN*/                   D3DFMT_UNKNOWN,
    /*DXGI_FORMAT_R32G32B32A32_TYPELESS*/     D3DFMT_A32B32G32R32F,
    //.
    //.
    //.
};

...如果可用,请使用C99语法,在这种情况下应该首选: / p>

... or if available, use the C99 syntax, which should be preferred in this case:

const D3DFORMAT dxgi_d3d_format_mapping[] = {
    [DXGI_FORMAT_UNKNOWN]                = D3DFMT_UNKNOWN,
    [DXGI_FORMAT_R32G32B32A32_TYPELESS]  = D3DFMT_A32B32G32R32F,
    //.
    //.
    //.
};

用法很明显,但也许索引检查不会受到伤害:

Usage is obvious, but perhaps, index checking wouldn't hurt:

assert( 0 <= dxgi_fmt && dxgi_fmt < (sizeof(dxgi_d3d_format_mapping)/sizeof(D3DFORMAT)) );
D3DFORMAT d3d_fmt = dxgi_d3d_format_mapping[dxgi_fmt];

这篇关于链接两个枚举类型成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆