get_param.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Pilz GmbH & Co. KG
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef PILZ_UTILS_GET_PARAM_H
18 #define PILZ_UTILS_GET_PARAM_H
19 
20 #include <sstream>
21 #include <stdexcept>
22 #include <string>
23 
24 #include <ros/ros.h>
25 
26 namespace pilz_utils
27 {
31 class GetParamException : public std::runtime_error
32 {
33 public:
34  GetParamException(const std::string& msg);
35 };
36 
37 inline GetParamException::GetParamException(const std::string& msg) : std::runtime_error(msg)
38 {
39 }
40 
41 template <class T>
42 T getParam(const ros::NodeHandle& nh, const std::string& param_name)
43 {
44  T ret_val;
45  if (!nh.getParam(param_name, ret_val))
46  {
47  std::ostringstream os;
48  os << "Parameter \"" << param_name << "\" not given";
49  throw GetParamException(os.str());
50  }
51  return ret_val;
52 }
53 
54 } // namespace pilz_utils
55 
56 #endif // PILZ_UTILS_GET_PARAM_H
Exception used by the getParam function.
Definition: get_param.h:31
bool getParam(const std::string &key, std::string &s) const
T getParam(const ros::NodeHandle &nh, const std::string &param_name)
Definition: get_param.h:42
GetParamException(const std::string &msg)
Definition: get_param.h:37


pilz_utils
Author(s):
autogenerated on Mon Feb 28 2022 23:13:40