什么是" |"在" INT风格= SWT.APPLICATION_MODAL | SWT.OK;"做(以及如何给Google的话)? [英] What does the "|" in "int style = SWT.APPLICATION_MODAL | SWT.OK;" do (and how to Google it)?

查看:316
本文介绍了什么是" |"在" INT风格= SWT.APPLICATION_MODAL | SWT.OK;"做(以及如何给Google的话)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能搜索|在谷歌。如果你发现它在一个软件源$ C ​​$ C,你是想跨preT,你不知道它做什么,你不能要求别人帮忙,你会怎么找出是什么呢?

I can't search for | in Google. If you had found it in a software source code that you are trying to interpret, you didn't know what it does and you couldn't ask other people for help, how would you find out what it does?

推荐答案

在这种情况下,管道操作符的意思是同时使用SWT.APPLICATION_MODAL和SWT.OK为我的弹出框中选择/标志。这是一个非常常用的成语与位域的配置标识,ESP。在窗像SWT或Win32系统。

The pipe operator in this case means "use both SWT.APPLICATION_MODAL and SWT.OK as options/flags for my popup box." It's a very commonly used idiom with bitfield configuration identifiers, esp. in windowing systems like SWT or Win32.

工作原理

管道( | )运算符是按位或运算,也就是说,它计算两个二进制整数值的OR操作。如果您签出在哪里APPLICATION_MODAL和确定的定义,你会发现他们是这样的:

The pipe (|) operator is the bitwise OR operator, that is, it computes an OR operation of the two binary integer values. If you check out where APPLICATION_MODAL and OK are defined, you'll find they are something like this:

...
SWT.OK = 1,                  // 00000001 in binary
SWT.ABORT_RETRY_IGNORE = 2,  // 00000010 in binary
SWT.OK_CANCEL = 4;           // 00000100 in binary
...
SWT.APPLICATION_MODAL = 32;  // 00100000 in binary
... (and so on...)

在位或这些数字的两个(或更多)一起,各个位将每个选项设置:

When you bitwise OR two (or more) of these numbers together, individual bits will be set for each of the options:

int style = SWT.OK | SWT.APPLICATION_MODAL = 00000001 | 00100000 = 00100001

这是去跨preT风格窗口工具包将可以通过做位与这样告诉你想要什么(一个弹出框是模态和有一个确定按钮):

The windowing toolkit that goes to interpret style will be able to tell exactly what you wanted (a popup box that is Modal and has an OK button) by doing a bitwise AND like this:

...
if(style & SWT.OK)
{
    // we want an OK box
}
if(style & SWT.ABORT_RETRY_IGNORE)
{
    // we want an Abort/Retry/Ignore box
}
if(style & SWT.OK_CANCEL)
{
    // we want an OK/Cancel box
}
...
if(style & SWT.APPLICATION_MODAL)
{
    // We want a modal box
}
...

还挺聪明的,在我的愚见。它允许您选择/重单一变量present多个配置选项。诀窍是在期权的整数定义,并确保他们的只有2权力。

Kinda clever, in my humble opinion. It allows you to select/represent multiple configuration options in a single variable. The trick is in the integer definitions of the options, and ensuring that they are only powers of 2.

这篇关于什么是" |"在" INT风格= SWT.APPLICATION_MODAL | SWT.OK;"做(以及如何给Google的话)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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