Skip to content
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

feature request: get access to argc argv and variables_map #1277

Closed
Titzi90 opened this issue Sep 25, 2014 · 3 comments
Closed

feature request: get access to argc argv and variables_map #1277

Titzi90 opened this issue Sep 25, 2014 · 3 comments

Comments

@Titzi90
Copy link
Contributor

Titzi90 commented Sep 25, 2014

It would be nice to have a hpx_main function giving you access to the hpx variables through the variables_map and as well to the argv and argc containing the left over command line options.
This would help a lot to port existing codes using argc and argv to hpx.

@hkaiser
Copy link
Member

hkaiser commented Sep 26, 2014

this is already possible: IIUC, you would like to not only keep the command line option handling of an existing application in place but you would like to be able to additionally define your own options.

using boost::program_options;
int hpx_main(variable_map& vm)
{
    // vm will hold the information about all command line options described 
    // by the options_description below

    // you can access the unknown command line here:
    std::string unknown_command_line = 
        hpx::get_config_entry("hpx.unknown_cmd_line", "");

#if defined(BOOST_WINDOWS)
    std::vector<std::string> args = split_winmain(unknown_command_line);
#else
    std::vector<std::string> args = split_unix(unknown_command_line);
#endif

    // handle the 'old' options...
}

int main(int argc, char* argv[])
{
    // Configure application-specific options
    options_description desc_commandline(
        "Usage: " HPX_APPLICATION_STRING " [options]");

    desc_commandline.add_options()
         ( "foo", "some value")
    ;

    // allow for unknown options
    std::vector<std::string> cfg;
    cfg.push_back("hpx.commandline.allow_unknown=1");

    return hpx::init(desc_commandline, argc, argv, cfg);
}

Let me know if that's not what you need, there are many more options for handling command line arguments in HPX.

@hkaiser
Copy link
Member

hkaiser commented Sep 29, 2014

Does this solve your issue or do you need more information/other functionality?

@Titzi90
Copy link
Contributor Author

Titzi90 commented Sep 29, 2014

That looks interesting. i did't know that hpx::get_config_entry("hpx.unknown_cmd_line", "") exist.
From the args:std::vector<std::string> it should be no problem to generate argc:int and argv:char** data structures used by the original program.
I think this solves my problems. Thanks

@Titzi90 Titzi90 closed this as completed Sep 29, 2014
@hkaiser hkaiser added this to the 0.9.9 milestone Sep 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants