[Program Options] Input information as std::string

Hi, I have a situation where I would like to parse the command line options not as (int argc, char **argv) template<typename charT> basic_parsed_options< charT > parse_command_line(int argc, const charT *const argv, const options_description &, int style = 0, function1< std::pair< std::string, std::string >, const std::string & > ext = ext_parser()); but as a std::string. The std::string is the equivalent of the command line but obtain either from reading some file or cut and paste. E.g. my input string would be something like "myprog 817382 --lod="lod.cfg" --radius=3.0" With such string as the above, I'd like to know how I should pass it to boost::program_options Regards -- Nicholas Yue Graphics - RenderMan, Visualization, OpenGL, HDF5 Custom Dev - C++ porting, OSX, Linux, Windows Management - Recruitment, career management http://www.proceduralinsight.com/ http://au.linkedin.com/in/nicholasyue

On 14.07.2012 16:56, Nicholas Yue wrote:
Hi,
I have a situation where I would like to parse the command line options not as (int argc, char **argv)
template<typename charT> basic_parsed_options< charT > parse_command_line(int argc, const charT *const argv, const options_description &, int style = 0, function1< std::pair< std::string, std::string >, const std::string & > ext = ext_parser());
but as a std::string.
The std::string is the equivalent of the command line but obtain either from reading some file or cut and paste.
E.g. my input string would be something like "myprog 817382 --lod="lod.cfg" --radius=3.0"
With such string as the above, I'd like to know how I should pass it to boost::program_options
Hi Nicolas, I am afraid you'd have to tokenize this string according to the rules you want. For windows, there's parse_winmain function that does that, but for Linux, there's no such function because: - On Linux, program entry point always has array of chars - Implementing tokenization for linux might be even trickier than for windows. Sorry, Volodya

Sorry, a little late to the party with this response. The bad news: there is no evidence that Boost::po includes any code to tokenize a string like what you have below. Boost::po::command_line_parser takes as input an already-parsed argc and argv. The good news is that I doubt that Boost::po has any "special" code that "knows" that argc and argv came from the standard command line. If you were to use any of the parsing techniques suggested by Vladimir (or any other parsing technique that you prefer) to make your string into a integer count of char[]'s, and an array of char[] pointers, with the first being "filler," then I'll bet that command_line_parser(count, array) would do exactly what you want. Charles From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Nicholas Yue Sent: Saturday, July 14, 2012 5:57 AM To: boost-users@lists.boost.org Subject: [Boost-users] [Program Options] Input information as std::string Hi, I have a situation where I would like to parse the command line options not as (int argc, char **argv) template<typename charT> basic_parsed_options< charT > parse_command_line(int argc, const charT *const argv, const options_description &, int style = 0, function1< std::pair< std::string, std::string >, const std::string & > ext = ext_parser()); but as a std::string. The std::string is the equivalent of the command line but obtain either from reading some file or cut and paste. E.g. my input string would be something like "myprog 817382 --lod="lod.cfg" --radius=3.0" With such string as the above, I'd like to know how I should pass it to boost::program_options Regards -- Nicholas Yue Graphics - RenderMan, Visualization, OpenGL, HDF5 Custom Dev - C++ porting, OSX, Linux, Windows Management - Recruitment, career management http://www.proceduralinsight.com/ http://au.linkedin.com/in/nicholasyue
participants (3)
-
Charles Mills
-
Nicholas Yue
-
Vladimir Prus