免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2554 | 回复: 8
打印 上一主题 下一主题

如何实现某个参数标识之间的互斥?谢谢! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-07-28 16:08 |只看该作者 |倒序浏览
比如说函数test(..., int dwFlags),其中参数dwFlags有三组标识如下:

//标识1(组内flags要求互斥)
flags1_1
flags1_2
flags1_3
//标识2(组内flags要求互斥)
flags2_1
flags2_2
flags2_3
//标识3(组内不做要求)
flags3_1
flags3_2

三组标识可以通过 | 来定义参数dwFlags的属性,但标识1和标识2中不能同时有两个存在,举个简单的例子来说就是:
dwFlags = flags1_1 | flags1_2;是非法的,但
dwFlags = flags1_1 | flags2_1 | flags3*;是合法的(总知来说就是:标识1或标识2只能任取其一或不取,标识3可以全取或都不取)
请教高手在c/c++中如何实现?

非常感谢!!!


说的可能不清楚,下面是英文描述,谢谢!
dwFlags: Specifies the flags that can be used for drawing the text. This can be
a logical OR of one of the items selected from each of the entries below:
Horizontal alignment -- (mutually exclusive within this group)
ZIDF_ALIGN_LEFT: Left justified
ZIDF_ALIGN_CENTER: Centered
ZIDF_ALIGN_RIGHT: Right justified
Vertical alignment -- (mutually exclusive within this group)
ZIDF_ALIGN_TOP: Align text with top of rectangle specified
ZIDF_ALIGN_MIDDLE: Place text in the middle of the specified rectangle
ZIDF_ALIGN_BOTTOM: Align text with the bottom of the rectangle specified
Text Format Flags
ZIDF_TEXT_INVERTED: Inverted text (highlights)
ZIDF_TEXT_TRANSPARENT: Background is preserved

论坛徽章:
0
2 [报告]
发表于 2007-07-28 16:41 |只看该作者
平时调人家的接口没觉得,自己要给别人提供这种接口,实现起来才发现不是那么简单,有请高手出马,哈哈!

论坛徽章:
0
3 [报告]
发表于 2007-07-28 17:47 |只看该作者
分别掩掉,然后判断是不是2的幂?

论坛徽章:
0
4 [报告]
发表于 2007-07-29 00:57 |只看该作者
多设几位不就好了么.

论坛徽章:
0
5 [报告]
发表于 2007-07-29 11:48 |只看该作者
没太懂。下面这样行吗?
#define ZIDF_ALIGN_LEFT 0x04 // Left justified: 100
#define ZIDF_ALIGN_CENTER 0x02 // Centered: 010
#define ZIDF_ALIGN_RIGHT 0x01 // Right justified 001

//Vertical alignment -- (mutually exclusive within this group)
#define ZIDF_ALIGN_TOP 0x20 // Align text with top:00 100 000
#define ZIDF_ALIGN_MIDDLE 0x10 //Place text in the middle:00 010 000
#define ZIDF_ALIGN_BOTTOM 0x08 // Align text with the bottom:00 001 000

//Text Format Flags
#define ZIDF_TEXT_INVERTED 0x40 // Inverted text (highlights):01 000 000
#define ZIDF_TEXT_TRANSPARENT 0x80
// Background is preserved:10 000 000

程序中要对dwFlags加点控制:dwFlags && 0x07 限于4,2,1,dwFlags && 0x38 再移三位限于4,2,1

论坛徽章:
0
6 [报告]
发表于 2007-08-03 13:50 |只看该作者
没有明白楼楼的意思

招聘 : c/c++研发
论坛徽章:
0
7 [报告]
发表于 2007-08-03 17:04 |只看该作者
没太明白

[ 本帖最后由 jerryhua 于 2007-8-3 17:10 编辑 ]

招聘 : c/c++研发
论坛徽章:
0
8 [报告]
发表于 2007-08-03 17:07 |只看该作者
#define ZIDF_ALIGN_LEFT 0x88 // Left justified: 100 01 00 0
#define ZIDF_ALIGN_CENTER 0x90 // Centered: 100 10 00 0
#define ZIDF_ALIGN_RIGHT 0x98 // Right justified 100 11 00 0

//Vertical alignment -- (mutually exclusive within this group)
#define ZIDF_ALIGN_TOP 0x42 // Align text with top:010 00 01 0
#define ZIDF_ALIGN_MIDDLE 0x44 //Place text in the middle:010 00 10 0
#define ZIDF_ALIGN_BOTTOM 0x46 // Align text with the bottom:010 00 11 0

//Text Format Flags
#define ZIDF_TEXT_INVERTED 0x20 // Inverted text (highlights):001 00 00 0
#define ZIDF_TEXT_TRANSPARENT 0x21 // Background is preserved:001 00 00 1

#define   TAG(x)  (x)&0xe0   //0xe0:111 00 00 0

使用时先判断:
if(TAG(flag1)&TAG(flag2)==TAG(flag1))
    printf("不合法");
else
    dwFlags = flag1 | flag2

按我理解楼主的意思,看这样行不。

论坛徽章:
0
9 [报告]
发表于 2007-08-03 19:53 |只看该作者
如果是检查传过来的dwFlags,且每个flag都是由unsigned int的某一位1表示的,
,flag1_1、flag1_2、flag1_3之间的互斥可以这样,
if (!(dwFlags & flag1_1) +!(dwFlags&flag1_2)+!(dwFlags & flag1_3) <= 1)
          error;
检查任意几位的合法性都可以这么做。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP