Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add parameter helpers (redo of #233) - #237

Merged
gerkey merged 4 commits into
masterfrom
param_helpers2
Jul 8, 2016
Merged

gerkey merged 4 commits into
masterfrom
param_helpers2

Conversation

@gerkey

@gerkey gerkey commented Jul 8, 2016

Copy link
Copy Markdown
Member

This is a replacement for #233, with the same diff (because I once again went into the weeds while attempting to rebase; I'll get the hang of that eventually).

  • Linux:
    • Build Status
  • OS X:
    • Build Status

@gerkey gerkey added in progress Actively being worked on (Kanban column) in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jul 8, 2016
{
std::vector<std::string> names;
names.push_back(parameter_name);
auto vars = get_parameters(names);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what case is vars.size() > 1 valid? Should that also be checked for?

Also, it seems as if these two functions could be de-duplicated a little bit, though that might just end up being more complicated. I could, however, imagine:

template<typename T>
T
get_parameter_impl(const std::string & parameter_name, std::function<T()> parameter_not_found_handler)
{
  std::vector<std::string> names;
  names.push_back(parameter_name);
  auto vars = get_parameters(names);
  if ((vars.size() == 0) || (vars[0].get_type() == rclcpp::parameter::PARAMETER_NOT_SET)) {
    return parameter_not_found_handler();
  } else {
    return static_cast<T>(vars[0].get_value<T>());
  } 
}

template<typename T>
T
get_parameter(const std::string & parameter_name, const T & default_value)
{
  return get_parameter_impl(parameter_name, [&default_value]() { return default_value; });
}

template<typename T>
T
get_parameter(const std::string & parameter_name)
{
  return get_parameter_impl(parameter_name, []() { throw std::runtime_error("Parameter not set"); });
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion, thanks! Done, with minor tweaks, in a1b4e15.

@wjwwood

wjwwood commented Jul 8, 2016

Copy link
Copy Markdown
Member

Other than a comment, the code changes lgtm.

@gerkey

gerkey commented Jul 8, 2016

Copy link
Copy Markdown
Member Author

Tests are in ros2/system_tests#155.

@gerkey

gerkey commented Jul 8, 2016

Copy link
Copy Markdown
Member Author

New CI, this time with the tests from ros2/system_tests#155 included:

  • Linux:
    • Build Status
  • OS X:
    • Build Status

@gerkey
gerkey merged commit fc0d539 into master Jul 8, 2016
@gerkey gerkey removed the in review Waiting for review (Kanban column) label Jul 8, 2016
@gerkey
gerkey deleted the param_helpers2 branch July 8, 2016 22:45
Karsten1987 pushed a commit that referenced this pull request Dec 7, 2016
* add parameter helpers

* respond to comments

* remove unnecessary indent comments

* replace temp variable assignment with explicit constructor invocation
nnmm pushed a commit to ApexAI/rclcpp that referenced this pull request Jul 9, 2022
* Implement a basic YAML based parameter parser for ros2 nodes

* Add README file

* Fix the issues after moving from rcutils_yaml_param_parser to rcl_yaml_param_parser

  - rename folders from rcutils_yaml_param_parser to rcl_yaml_param_parser
  - rename project, header guards and include statements from rcutils_yaml_param_parser to rcl_yaml_param_parser
  - move type declaration in separat file and namespace new structures
  - Fix the code review comments from Mikael

* Few minor changes

   - Changed "params" string to "ros__parameters"
   - Add -Wall, -Wextra and -Wpedantic falgs
   - Fix the compile warning with the new flags

* Fix the changes made in the design of C structure

  - Remove the node_namespaces entry in rcl_params_t
  - Change the type of num_nodes and num_params to size_t

* depend on libyaml_vendor (ros2#236)

* Fix cmake setting standard(C and C++) and add byte_array in C struct

*   Remove C11 so that it defaults to C99

* [rcl_yaml_param_parser] fix export symbols (ros2#237)

* add visibility macros

* remove unused macro

* Support for multi level node and parameter name spaces

* Additional fixes and cleanups

  - Support for string namespace seperator
  - Provide parameter structure init function API
  - name cleanups

* off by 1

* Call yaml_parser_delete()

* fclose(yaml_file)

* free() allocated paths

* Call yaml_event_delete()

* completely deallcoate string array

* Few cleanup changes

  - Add install command into CMakelists.txt
  - Replace one of the zero_allocate with reallocate
  - Pass allocator state
  - Fix int32_t -> rcl_ret_t return value

* Don't include unistd.h

* Use size_t for array indices

* Just pass the allocator in the init function
DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this pull request Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants