in reply to Bitmask or Named permissions

When I was writing C++ regularly, I developed a quick class that represented "modes" like an IRC channel or user. That is, the caller could manipulate modes with simple mode strings, and the application could configure legal modes and special modes ahead of time.

From memory, C++ code would work something like:

CMode mode = new CMode("abcd*eAB"); mode = "beB"; // mode.Clear(); mode.SetModes("beB"); mode += "a"; // mode.SetModes("a"); mode -= "b"; // mode.ClearModes("b"); mode += "d Jones"; // mode.SetModes("d", "Jones"); if (mode & "a") { ... } // mode.IsModeSet("a")

The special handling of "d*" meant that mode "d" took an argument, and you could have any number of them. (Kinda like "/mode #chan +b n!i@h" on IRC.)

Limits, similar to that of bitfields, are that you have a fixed and arbitrary set of fields. Benefits over bitfields are that it's fairly easy to expose the flags to the end user in a consistent way.

--
[ e d @ h a l l e y . c c ]