parameter_magic.h
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2018, Open Source Robotics Foundation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of OSRF nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * Author: David Lu
36 *********************************************************************/
37 
38 #ifndef NAV_CORE_PARAMETER_MAGIC_H
39 #define NAV_CORE_PARAMETER_MAGIC_H
40 
41 namespace nav_core
42 {
43 
52 template<class param_t>
53 param_t loadParameterWithDeprecation(const ros::NodeHandle& nh, const std::string current_name,
54  const std::string old_name, const param_t& default_value)
55 {
56  param_t value;
57  if (nh.hasParam(current_name))
58  {
59  nh.getParam(current_name, value);
60  return value;
61  }
62  if (nh.hasParam(old_name))
63  {
64  ROS_WARN("Parameter %s is deprecated. Please use the name %s instead.", old_name.c_str(), current_name.c_str());
65  nh.getParam(old_name, value);
66  return value;
67  }
68  return default_value;
69 }
70 
76 void warnRenamedParameter(const ros::NodeHandle& nh, const std::string current_name, const std::string old_name)
77 {
78  if (nh.hasParam(old_name))
79  {
80  ROS_WARN("Parameter %s is deprecated (and will not load properly). Use %s instead.", old_name.c_str(), current_name.c_str());
81  }
82 }
83 
84 } // namespace nav_core
85 
86 #endif // NAV_CORE_PARAMETER_MAGIC_H
nav_core::loadParameterWithDeprecation
param_t loadParameterWithDeprecation(const ros::NodeHandle &nh, const std::string current_name, const std::string old_name, const param_t &default_value)
Load a parameter from one of two namespaces. Complain if it uses the old name.
Definition: parameter_magic.h:88
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
ros::NodeHandle::hasParam
bool hasParam(const std::string &key) const
ROS_WARN
#define ROS_WARN(...)
nav_core::warnRenamedParameter
void warnRenamedParameter(const ros::NodeHandle &nh, const std::string current_name, const std::string old_name)
Warn if a parameter exists under a deprecated (and unsupported) name.
Definition: parameter_magic.h:111
nav_core
Definition: base_global_planner.h:43
default_value
def default_value(type_)
ros::NodeHandle


nav_core
Author(s): Eitan Marder-Eppstein, contradict@gmail.com
autogenerated on Mon Mar 6 2023 03:50:21