From 6c37765d2f5dd26b575a43af4cf355908e57c871 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Sat, 7 Nov 2015 00:37:19 +0100 Subject: [PATCH] add getROSArg function to ros init --- clients/roscpp/include/ros/init.h | 10 ++++++++++ clients/roscpp/src/libros/init.cpp | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/clients/roscpp/include/ros/init.h b/clients/roscpp/include/ros/init.h index 093b03e08d..02e84c3684 100644 --- a/clients/roscpp/include/ros/init.h +++ b/clients/roscpp/include/ros/init.h @@ -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 diff --git a/clients/roscpp/src/libros/init.cpp b/clients/roscpp/src/libros/init.cpp index 892de30a10..1435d02700 100644 --- a/clients/roscpp/src/libros/init.cpp +++ b/clients/roscpp/src/libros/init.cpp @@ -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)