Skip to content

Implementing flag_count and flag_get #16

@n-s-kiselev

Description

@n-s-kiselev

You have the following comment in example.c:

 // TODO: Would be nice to have some sort of mechanism to inspect all the defined flags
 //   Maybe just expose flag_global_context? But I'm afraid that this will make changing
 //   its internal structure in a backward compatible way more difficult...
 //   But the only reason we may want to change it right now is to make the array of the
 //   flags dynamic. Maybe we should just make it dynamic and finally expose the internal
 //   structure for good?

What about implementing functions flag_count and flag_get(i) as a compromise?

I mean, the API could look like:

size_t flag_count(void);
const Flag_Info *flag_get(size_t index);

where Flag_Info is a structure, something like:

typedef struct {
    const char *name;
    Flag_Type   type;
    const char *desc;
    const void *value;  // or provide a separate function to read the current value 
} Flag_Info;

In this case, the Flag_Context stays private, but we can iterate for (size_t i = 0; i < flag_count(); ++i) and collect metadata if needed.
We may also add more fields to Flag_Info, for example, a default value or a field that indicates whether “was this flag provided?”, or something else.

Should I try to implement this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions