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 <string>
21 #include <stdexcept>
22 #include <sstream>
23 
24 #include <ros/ros.h>
25 
26 namespace pilz_utils
27 {
28 
32 class GetParamException : public std::runtime_error
33 {
34 public:
35  GetParamException(const std::string& msg);
36 };
37 
38 inline GetParamException::GetParamException(const std::string& msg)
39  : std::runtime_error (msg)
40 {
41 
42 }
43 
44 template<class T>
45 T getParam(const ros::NodeHandle& nh, const std::string& param_name)
46 {
47  T ret_val;
48  if ( !nh.getParam(param_name, ret_val) )
49  {
50  std::ostringstream os;
51  os << "Parameter \"" << param_name << "\" not given";
52  throw GetParamException(os.str());
53  }
54  return ret_val;
55 }
56 
57 }
58 
59 #endif // PILZ_UTILS_GET_PARAM_H
Exception used by the getParam function.
Definition: get_param.h:32
T getParam(const ros::NodeHandle &nh, const std::string &param_name)
Definition: get_param.h:45
GetParamException(const std::string &msg)
Definition: get_param.h:38
bool getParam(const std::string &key, std::string &s) const


pilz_utils
Author(s):
autogenerated on Tue Feb 2 2021 03:50:14