Skip to content

Commit 2e78884

Browse files
authored
Merge pull request #1124 from OpenRTM/manager_arg
getParameterByModulename()'s bug fixed
2 parents 7090007 + 5f49f72 commit 2e78884

File tree

2 files changed

+53
-55
lines changed

2 files changed

+53
-55
lines changed

src/lib/rtm/ManagerServant.cpp

Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -323,65 +323,37 @@ namespace RTM
323323

324324
std::string ManagerServant::getParameterByModulename(const std::string& param_name, std::string &module_name)
325325
{
326-
size_t pos0 = module_name.find("&" + param_name + "=");
327-
size_t pos1 = module_name.find("?" + param_name + "=");
328-
329-
if (pos0 == std::string::npos && pos1 == std::string::npos)
330-
{
331-
return "";
332-
}
333-
334-
size_t pos = 0;
335-
if (pos0 == std::string::npos)
336-
{
337-
pos = pos1;
338-
}
339-
else
340-
{
341-
pos = pos0;
342-
}
343-
344-
std::string paramstr;
345-
size_t endpos = module_name.find('&', pos + 1);
346-
347-
348-
if (endpos == std::string::npos)
349-
{
350-
endpos = module_name.find('?', pos + 1);
351-
352-
if (endpos == std::string::npos)
353-
{
354-
paramstr = module_name.substr((pos + 1));
355-
356-
}
357-
else
358-
{
359-
paramstr = module_name.substr((pos + 1), endpos);
360-
}
361-
}
362-
else
363-
{
364-
paramstr = module_name.substr((pos + 1), endpos);
365-
}
366-
RTC_VERBOSE(("%s arg: %s", param_name.c_str(), paramstr.c_str()));
367-
368-
size_t eqpos = paramstr.find('=');
369-
370-
paramstr = paramstr.substr(eqpos + 1);
326+
size_t param_start = module_name.find(param_name + "=");
371327

328+
if (param_start == std::string::npos)
329+
{ // no specified param
330+
return "";
331+
}
372332

373-
RTC_DEBUG(("%s is %s", param_name.c_str(), paramstr.c_str()));
333+
size_t param_end = module_name.find("&", param_start);
374334

375-
if (endpos == std::string::npos)
376-
{
377-
module_name = module_name.substr(0, pos);
378-
}
379-
else
380-
{
381-
module_name = module_name.substr(0, pos) + module_name.substr(endpos);
382-
}
335+
if (param_end == std::string::npos)
336+
{ // param is end of param list
337+
param_end = module_name.length();
338+
}
383339

384-
return paramstr;
340+
// extract param's value
341+
// module_name?....param_name=param_value
342+
// substr( ^ arg1 ^ arg2 ^ )
343+
std::string param_value =
344+
module_name.substr(param_start + param_name.length() + 1,
345+
param_end - param_start - param_name.length() - 1);
346+
RTC_DEBUG(("%s is %s", param_name.c_str(), param_value.c_str()));
347+
// remove specified param
348+
if (module_name[param_start - 1] == '?')
349+
{ // module_name?{param_name=param_value}: remove {}
350+
module_name.erase(param_start, param_end - param_start + 1);
351+
}
352+
if (module_name[param_start - 1] == '&')
353+
{ // module_name?other_param...{&param_name=param_value}: remove {}
354+
module_name.erase(param_start - 1, param_end - param_start + 1);
355+
}
356+
return param_value;
385357
}
386358

387359
/*!

src/lib/rtm/ManagerServant.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,32 @@ namespace RTM
703703
* @endif
704704
*/
705705
void updateMasterManager();
706+
/*
707+
* @if jp
708+
* @brief create引数から指定されたキーの値を返す
709+
*
710+
* create引数から指定されたキーを値を返すとともに、そのキーと値を削除した引
711+
* 数を返す。
712+
* module_name: module_name?param1=value1&param2=value2&param3...
713+
* param_name: param2
714+
* の場合
715+
* 返り値: value2
716+
* module_name: module_name?param1=value1&param3...
717+
* となる。
718+
*
719+
* @else @brief returns value of specified param_name from create arg
720+
*
721+
* This function returns the value of specified param_name from
722+
* create argument, and delete param_name=value from the create
723+
* arg string. If the arguments are
724+
* module_name: module_name?param1=value1&param2=value2&param3...
725+
* param_name: param2
726+
* this function returns
727+
* ret value: value2
728+
* module_name: module_name?param1=value1&param3...
729+
*
730+
* @endif
731+
*/
706732
std::string getParameterByModulename(const std::string& param_name, std::string &module_name);
707733
static bool isProcessIDManager(const std::string& mgrname);
708734

0 commit comments

Comments
 (0)