c++ 多状态设置
2012-08-13 10:00:34 来源:WEB开发网核心提示:// 王智泉enum {ST_1 = 0x01 << 1;// 状态1ST_2 = 0x01 << 2;// 状态2ST_3 = 0x01 << 3;// 状态3ST_4 = 0x01 << 4;// 状态4ST_5 = 0x01 << 5;// 状态5};c
// 王智泉
enum {
ST_1 = 0x01 << 1; // 状态1
ST_2 = 0x01 << 2; // 状态2
ST_3 = 0x01 << 3; // 状态3
ST_4 = 0x01 << 4; // 状态4
ST_5 = 0x01 << 5; // 状态5
};
class StateTest
{
public:
StateTest():_state(0){}
~StateTest(){}
// 设置指定状态
// @param tag 状态
// @param enable 是否打开
void setState(int tag, bool enable)
{
if (enable)
_state |= tag;
else
_state &= ~tag;
}
// 指定的状态是否打开
bool isStateEnable(int tag) const
{
return (_state & tag) != 0;
}
private:
long long _state;
};
更多精彩
赞助商链接
