config-files with program_options
Hi, I'm trying ro read a config file with the program_options library, but I can't figure out how to read several sections in a config file whithout knowing (the exact) section names. For example I have a config file with N [blockn] sections (n=1...N) in my config file but I don't know N: [block1] name="Name section 1" [block2] name="Name2 section 2" . # there might or might not be more sections with the 'name' option . Is there any support for wildcards in option names so I could write something like options_description Opts_Desc("Config-File Options"); Opts_Desc.add_options() ("*.name", value<string>(), "Name of the block"); or is there a workaround for this problem? Thanks a lot in advance, Anselm Kunstein
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Anselm Kunstein
I'm trying ro read a config file with the program_options library, but I can't figure out how to read several sections in a config file whithout knowing (the exact) section names. For example I have a config file with N [blockn] sections (n=1...N) in my config file but I don't know N:
[block1] name="Name section 1" [block2] name="Name2 section 2" . # there might or might not be more sections with the 'name' option .
Is there any support for wildcards in option names so I could
IF not, the obvious one is to have a known section (such the [general] or the default) where N is defined. Or, loop from n=1 to read blockn until you get an exception saying the section doesn't exist. Or limit the number of blockn sections allowed (to, say, 100), and just loop over all n=1 to N=100, skipping those that lead to exception (ie section not defined, in case not contiguously numbered). Oliver.
Anselm Kunstein wrote:
Hi,
I'm trying ro read a config file with the program_options library, but I can't figure out how to read several sections in a config file whithout knowing (the exact) section names. For example I have a config file with N [blockn] sections (n=1...N) in my config file but I don't know N:
[block1] name="Name section 1" [block2] name="Name2 section 2" . # there might or might not be more sections with the 'name' option .
Is there any support for wildcards in option names so I could write something like
options_description Opts_Desc("Config-File Options"); Opts_Desc.add_options() ("*.name", value<string>(), "Name of the block");
Unfortunately, not yet. It's possible to use wildcards like this: "option*" but not "*.name" I intend to add this, but due to feature freeze this might happen after 1.33 only. - Volodya
participants (3)
-
Anselm Kunstein
-
Oliver Schoenborn
-
Vladimir Prus