Created
September 22, 2011 09:30
-
-
Save cloderic/1234411 to your computer and use it in GitHub Desktop.
C/C++ bitsets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car | |
{ | |
public: | |
Car() | |
:_status(0x00) | |
{ | |
} | |
void setLocked() | |
{ | |
_status |= statusLocked; | |
} | |
void setParked() | |
{ | |
_status |= statusParked; | |
} | |
void unsetLocked() | |
{ | |
_status &= (~statusLocked); | |
} | |
void unsetParked() | |
{ | |
_status &= (~statusParked); | |
} | |
void toggleLocked() | |
{ | |
_status ^= statusLocked; | |
} | |
void toggleParked() | |
{ | |
car ^= statusParked; | |
} | |
bool isLocked() const | |
{ | |
return car & statusLocked; | |
} | |
bool isParked() const | |
{ | |
return car & statusParked; | |
} | |
private: | |
static const char statusLocked = 0x01; // 0000 0001 | |
static const char statusParked = 0x02; // 0000 0010 | |
char _status; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment