c++ 多状态设置

http://blog.csdn.net/wzq9706/article/details/7858711


// 王智泉
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;

};


原文地址:https://www.cnblogs.com/iapp/p/3631787.html