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 ]


In reply to Re: Bitmask or Named permissions by halley
in thread Bitmask or Named permissions by linux454

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.