Skip to content

Commit

Permalink
getROSArg function in init.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Karsten1987 committed Nov 6, 2015
1 parent 4ee44bd commit 5db2088
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions clients/roscpp/include/ros/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ ROSCPP_DECL bool isStarted();
*/
ROSCPP_DECL CallbackQueue* getGlobalCallbackQueue();

/**
* \brief searches the command line arguments for the given arg parameter. In case this argument is not found
* an empty string is returned.
*
* \param argc the number of command-line arguments
* \param argv the command-line arguments
* \param arg argument to search for
*/
ROSCPP_DECL std::string getROSArg(int argc, const char* const* argv, const std::string& arg);

/**
* \brief returns a vector of program arguments that do not include any ROS remapping arguments. Useful if you need
* to parse your arguments to determine your node name
Expand Down
14 changes: 14 additions & 0 deletions clients/roscpp/src/libros/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,20 @@ void init(const VP_string& remappings, const std::string& name, uint32_t options
init(remappings_map, name, options);
}

std::string getROSArg(int argc, const char* const* argv, const std::string& arg)
{
for (int i = 0; i < argc; ++i)
{
std::string str_arg = argv[i];
size_t pos = str_arg.find(":=");
if (str_arg.substr(0,pos) == arg)
{
return str_arg.substr(pos+2);
}
}
return "";
}

void removeROSArgs(int argc, const char* const* argv, V_string& args_out)
{
for (int i = 0; i < argc; ++i)
Expand Down

0 comments on commit 5db2088

Please sign in to comment.