Opened 13 years ago

Closed 13 years ago

#3264 closed Feature Requests (fixed)

open config file

Reported by: Diederick C. Niehorster <dcnieho@…> Owned by: Sascha Ochsenknecht
Milestone: Boost 1.42.0 Component: program_options
Version: Boost 1.39.0 Severity: Optimization
Keywords: Cc: s.ochsenknecht@…

Description

It would be nice if it is possible to call parse_config_file(const std::basic_string<charT>&, const options_description&, bool allow_unregistered = false); also, next to parse_config_file(std::basic_istream<charT>&, const options_description&, bool allow_unregistered = false); where parse_config_file would take care of opening the file. This would allow for less boiler-plate on part of the user and optimizes the interface for parsign the config file.

Change History (4)

comment:1 by Diederick C. Niehorster <dcnieho@…>, 13 years ago

Sorry, that needed some formatting:

It would be nice if it is possible to call

parse_config_file(const std::basic_string<charT>&, const options_description&, bool allow_unregistered = false);

also, next to

parse_config_file(std::basic_istream<charT>&, const options_description&, bool allow_unregistered = false);

where parse_config_file would take care of opening the file. This would allow for less boiler-plate on part of the user and optimizes the interface for parsign the config file.

comment:2 by s.ochsenknecht@…, 13 years ago

Cc: s.ochsenknecht@… added

I see one problem here. How to determine if a ifstream or a wifstream should be used? Both take (const char*) as type for the file name.

One Solution could be: We can implement a template with a basic_string<char> and basic_string<wchar_t> instantiation for the file name. So, if the file name comes with a basic_string<wchar_t> then we use wifstream, the file name has to be converted to (const char* ).

template<charT>
parse_config_file(const std::basic_string<charT>&, ...);

Another solution could be: The function takes const char* parameter for file name which is directly passed to ifstream/wifstream:

template<charT>
parse_config_file(const char*, ...);

But how the user can choose now between ifstream and wifstream?

comment:3 by Sascha Ochsenknecht, 13 years ago

Milestone: Boost 1.40.0Boost 1.42.0
Owner: changed from Vladimir Prus to Sascha Ochsenknecht
Status: newassigned

Implemented option (2). The template parameter is mandatory (char or wchar_t). Default template parameter are not allowed for functions.

Cheers, SAscha

comment:4 by Sascha Ochsenknecht, 13 years ago

Resolution: fixed
Status: assignedclosed

(In [58248]) Allow passing file name to parse_config_file(), Fixes #3264

Note: See TracTickets for help on using tickets.