Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add array-like category type #9

Open
Micovec opened this issue Jan 3, 2024 · 4 comments
Open

Add array-like category type #9

Micovec opened this issue Jan 3, 2024 · 4 comments

Comments

@Micovec
Copy link
Contributor

Micovec commented Jan 3, 2024

I'd love to be able to define multiple instances of a category inside an array.

Currently there's special category that can be defined multiple times to hold config data. Such as:

special {
    key = a
    value = 1
    ...
}

special {
    key = b
    value = 2
    ...
}

However, a special category is required to have a primary key which is then used to retrieve it's config values.

If I wanted to define an unlimited number of categories of the same type I'd then have to use an incremental primary key which I would need to keep track of. Especially it would be even more difficult when I would remove several definitions. A gap in primary key sequence would occur and then I'd have to look for the highest ones and lower them in order to keep them unique and continuous.

So I propose a new syntax for defining multiple instance of the same category without a primary key (similar to json):

array-like-category [
    {
        value = 1
        ...
    },
    {
        value = 2
        ...
    }
]

I tihnk that the comma separating categories isn't necessary.

@vaxerski
Copy link
Member

vaxerski commented Jan 3, 2024

Fair idea, someone also proposed that to me privately before, so I guess it's not such a terrible idea. The question is how would we address them in the API? We still need some ID for them. Maybe just something like

size_t getArrayLikeSpecialCount(const char* name);

and then

std::any getArraySpecialConfigValue(const char* cat, const char* value, size_t idx);

?

edit: fwiw, this syntax would support key-based categories too, no reason to disallow keys from being there.

@Micovec
Copy link
Contributor Author

Micovec commented Jan 3, 2024

That seems reasonable.

Can't be easily iteratable in for loop as it is with iterators but I don't think that's an issue. Plus, an additional API can be added. Something like:

std::vector<std::any> getArrayLikeSpecial(const char* name);

@vaxerski
Copy link
Member

vaxerski commented Jan 3, 2024

we cannot share stl types across lib and app, so that would be a bit painful to query for all strings.

@Micovec
Copy link
Contributor Author

Micovec commented Jan 3, 2024

Ah, didn't know that. Still, your suggestion is good. I can't think of any other way that will be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants