[ANN] New package FlagSets.jl - Manipulate flags bitwise or like sets

FlagSets is based on BitFlags.jl, but with a different concept: FlagSet is a subtype of AbstractSet and implement both set and bitwise operations (each bit is associated with a flag, and so a sequence of bits is associated with a set of flags - where 1 indicates the flag is in the set and 0 indicates it is not in the set).

I implemented this package mainly to create a higher level manipulation of flags from C libraries in Julia. I used to program in Common Lisp and the main interface for handling C libraries (CFFI) translates bit flags to lists of keywords (and vice-versa), which seems more like a high level library. Then I found the package BitFlags, which is nice, but doesn’t have tools for, e.g., getting the list of flags that are set in a BitFlag. Also, each flag is stored in a const variable, which is not bad, but looks like a low level language.

A few examples to illustrate the idea.

julia> @flagset FontFlags::UInt8 bold italic large=8

julia> FontFlags(1)
FontFlags(:bold) = 0x01

julia> FontFlags(:bold, :italic)
FontFlags(:bold, :italic) = 0x03

julia> FontFlags(3) | FontFlags(8)
FontFlags(:bold, :italic, :large) = 0x0b

julia> for flag in FontFlags(3); println(flag) end
bold
italic

julia> :bold in FontFlags(3)
true

Any suggestions, ideas or comments are welcome, of course.

15 Likes