diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-05-30 05:06:12 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-05-30 05:06:12 +0000 |
commit | 02c18fcb826e63ce7c654d44e9f0afe1eafa7a64 (patch) | |
tree | 4b664cea541657858cdccb4a275092cba62d0960 /include | |
parent | 571542d1f0fad81963afb81640118dc7d06547ba (diff) |
Added BoolSet utility class
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1564 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'include')
-rw-r--r-- | include/base.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/include/base.h b/include/base.h index d253c5dc3..13c361c0b 100644 --- a/include/base.h +++ b/include/base.h @@ -88,5 +88,70 @@ public: char* GetExt(std::string key); }; +const int bitfields[] = {1,2,4,8,16,32,64,128}; +const int inverted_bitfields[] = {~1,~2,~4,~8,~16,~32,~64,~128}; + +/** BoolSet is a utility class designed to hold eight bools in a bitmask. + * Use BoolSet::Set and BoolSet::Get to set and get bools in the bitmask, + * and Unset and Invert for special operations upon them. + */ +class BoolSet +{ + char bits; + + public: + + /** The default constructor initializes the BoolSet to all values unset. + */ + BoolSet(); + + /** This constructor copies the default bitmask from a char + */ + BoolSet(char bitmask); + + /** The Set method sets one bool in the set. + * + * @param number The number of the item to set. This must be between 0 and 7. + */ + void Set(int number); + + /** The Get method returns the value of one bool in the set + * + * @param number The number of the item to retrieve. This must be between 0 and 7. + * + * @return True if the item is set, false if it is unset. + */ + bool Get(int number); + + /** The Unset method unsets one value in the set + * + * @param number The number of the item to set. This must be between 0 and 7. + */ + void Unset(int number); + + /** The Unset method inverts (flips) one value in the set + * + * @param number The number of the item to invert. This must be between 0 and 7. + */ + void Invert(int number); + + /** Compare two BoolSets + */ + bool operator==(BoolSet other); + + /** OR two BoolSets together + */ + BoolSet operator|(BoolSet other); + + /** AND two BoolSets together + */ + BoolSet operator&(BoolSet other); + + /** Assign one BoolSet to another + */ + bool operator=(BoolSet other); +}; + + #endif |