-
Notifications
You must be signed in to change notification settings - Fork 2
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
Yaml configuration with map of maps #20
Comments
Trying to parse YAML to a map with string keys and structure values fails too.
The above fails again with
|
Hi, thanks. The second case seems reasonable, I'm not sure how I missed it. To think of it, it makes more sense to support it than the currently supported map of arbitrary parameters (FIGCONE_DICT). It seems that it's not impossible to implement and it should work pretty much the same as FIGCONE_NODELIST. The first case is different, and I doubt that I will support mapping of config structure to nested containers. You can register the value type of a map as a user-defined type with StringConverter<std::unordered_map<std::string, std::string>> and implement its parsing by yourself, but I doubt that it's useful) |
Do you mean that currently FIGCONE_DICT supports maps where the value is a structure? Or does it require the value to always be a primitive, like std::string, int, bool, etc.? Regarding the first case (nested containers), I have a YAML configuration which contains servers, index by server_id (string) and the config entry for each server contains a list of authentication parameters, where each server can have a different list of connection parameters. A sample config would be:
So using two nested maps seems like a natural way to handle this kind of configuration. The outer map has server_id (server_1, server_2, etc.) as keys and inner maps as values. The inner map has auth parameter names as keys and auth parameter values as values. So is there a simple way to handle this kind of configuration? For now I work around the problem by changing the config to:
So there is no hurry making changes to the library, for me it is good enough the way it is now. It seems more natural to use two nested maps so it would be nice to have some way to use nested maps, but the workaround that I use is fine with me too. |
It doesn't need to be a primitive, but it can only be read from a simple string value, by using the registered string conversion. Here's an example based on the "User defined types" README section:
So, with the Host structure as a map value it can't automatically parse the following config:
but I think it's possible to add support for it in the future. As for your example
If "server_N" and "server_N_param_N" are arbitrary, and you cannot register a structure with expected field names, then no, there's no better way than using some combination of a node list and a dictionary, like the one you ended up with. figcone's design helps to avoid using string-based maps when you have a defined schema configuration. At the same time, this shift away from using maps for storing configuration hurts flexibility when you need to support configurations with arbitrary key names, as in your example. |
My configuration is more complex than the example that I provided, because it has both a fixed part, which can be put into nested structures, and a dynamic part which is better suited for nested maps. The dynamic part, which in my case contains the auth data is handled by different plugins, so the main code, which parses the config, does not really know the parameter names of the auth data for each server id, so the best thing it can do is put the auth data into a Anyway, thanks for the explanation. I am OK with the workaround that I use. I will leave the issue open in case you find the time to implement support for maps with string keys and structure values. |
It seems that figcone has trouble handling a map of maps, e.g the following config structure
Generates the following error:
The text was updated successfully, but these errors were encountered: