Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#3751 closed Feature Requests (fixed)

I suggest to substitute "multiple_sources.cpp" on an offered variant.

Reported by: Alex Bukreev <bucreev@…> Owned by: Vladimir Prus
Milestone: Boost 1.42.0 Component: program_options
Version: Boost 1.41.0 Severity: Cosmetic
Keywords: Cc:

Description

The offered variant shows possibility of the assign in the command line of a filename of a configuration.

Attachments (2)

multiple_sources.cpp (3.5 KB ) - added by Alex Bukreev <bucreev@…> 13 years ago.
required_test.patch (1.6 KB ) - added by Sascha Ochsenknecht 13 years ago.
example

Download all attachments as: .zip

Change History (13)

by Alex Bukreev <bucreev@…>, 13 years ago

Attachment: multiple_sources.cpp added

comment:1 by Sascha Ochsenknecht, 13 years ago

Resolution: fixed
Status: newclosed

(In [58289]) Enhance example, Fixes #3751, Patch from Alex Bukreev

comment:2 by Sascha Ochsenknecht, 13 years ago

Thanks for enhancement.

I did some small modifications (removed tabs, converted via dos2unix ...). There was also one problem: The value from command line is stored in config_file only after notify() call. I fixed that.

comment:3 by Alex Bukreev <bucreev@…>, 13 years ago

Excuse, but this example has entered in contradicted with new (very useful) property "required". After the first call "notify (vm)" the exception for the options which values are set in the configuration file will be generated. How to be now I do not know. Probably to enter new function for stock-taking of all demanded options.

comment:4 by Sascha Ochsenknecht, 13 years ago

Hm, I'm not sure of what you're talking about? What exception do you mean? What do you try?

Thanks, Sascha

comment:5 by Alex Bukreev <bucreev@…>, 13 years ago

if lines 47-48: "("optimization", po::value<int>(&opt)->default_value(10),"optimization level")" change to: "("optimization", po::value<int>(&opt)->required(),"optimization level")" and exec: multiple_sources.exe there will be an exception in lines 77 (first "notify(vm);").

comment:6 by Sascha Ochsenknecht, 13 years ago

Yes, the "required" check is done in notify().

You can try not to store in existing variables and then remove the first notify() call:

("optimization", po::value<int>()->default_value(10),"optimization level")

I'm going to check why values for existing variables are applied in notify() ...

by Sascha Ochsenknecht, 13 years ago

Attachment: required_test.patch added

example

comment:7 by Sascha Ochsenknecht, 13 years ago

see attached file required_test.patch for better understanding.

comment:8 by Alex Bukreev <bucreev@…>, 13 years ago

Thanks for patch. But it does not work. The default value comes back.

comment:9 by Sascha Ochsenknecht, 13 years ago

Hm, I can not reproduce, debugger shows that config_file is set correctly after the following line:

       string config_file = vm["config"].as< string >();

(default if not given on command line, otherwise set to value given on command line. I use current trunk version

comment:10 by bucreev@…, 13 years ago

Excuse. I did not set parametre in the command line, therefore and received "defaulted ()".

comment:11 by bucreev@…, 13 years ago

I suggest to enter your code as an example "multiple_sources.cpp".

Note: See TracTickets for help on using tickets.