Bit flags in template variable

A field in a file is a combination of enum values, like:

enum <unsigned short> Flags {
    foo = 1,
    bar = 2,
    baz = 4
};

Where the field value could be 6, meaning “bar | baz”. When it’s a single value, it displays as expected (i.e. 1 = “foo”), but combined results just show the numerical value instead of the set flags.

Is there a way to have the value column of the template show the combination of flags for a given enum type?

010 Editor does not have a built-in flags type right now although we may add one in the future. For right now you can replicate a flags type using a custom ‘read’ function. Something like this should work:

enum <unsigned short> FlagsBase {
    foo = 1,
    bar = 2,
    baz = 4
};
typedef FlagsBase Flags <read=ReadFlags>;

string ReadFlags( Flags &f )
{
    string str;
    if( f & foo )
        str += EnumToString(foo) + " | ";
    if( f & bar )    
        str += EnumToString(bar) + " | ";
    if( f & baz )    
        str += EnumToString(baz) + " | ";
    return str;
}

Let us know if you have any trouble getting this to work.

Graeme
SweetScape Software