Flags64 Class - Storing 64 flags in one Int64

I’ve saw people needing it. So, I’ll share my contribution.


It enables you to write easily, things like, registering options, statuses, checkboxes, etc; in a simple packed form, usable in any database backends (as all them supports Integers):

[code]Dim i As Int64 = getIntegerFlagsFromDatabase()
Dim f As New Flags64(i)

If not f.Flag(12) Then // Something still not done!

f.Flag(12, True) // Set it done

f.Flag(18, CheckBox1.Value) // Also stores the value of the Checkbox1



That takes me back to writing adventure games on the BBC Model B
Each bit was an attribute of an object
Light Source
… etc

Really packed them in!

and that computer had to make as much use of limited resources as it could… a few bytes could mean the difference between a running program and an “out of memory” condition. And almost all variable space was pre-allocated, with the exception of the “stack”

not to mention that computer had no idea was a 64bit integer was :slight_smile: [or even a 32bit one]

Updated. Version 2.0 now supports named flags, letting code more readable and maintainable.



[code]f.Flag(n, “my flag name”) // set a name for flag n

f.Flag(“my flag name”, true|false) // sets a named flag to true or false

f.Flag(“my flag name”) // returns the named flag value (true or false)


If flagSet1.Flag("Is Printable") Then // flagSet1 contains more than a dozen flags PrintThat() flagSet1.Flag("Printed", True) // Store that we already printed it at least once End flagSet2.Flag("Polimorphic", True) // Set "polimorphic" to True in the Int64 flagSet2