ros2_control - humble
Loading...
Searching...
No Matches
macros.hpp
1// Copyright 2017 Open Source Robotics Foundation, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef HARDWARE_INTERFACE__MACROS_HPP_
16#define HARDWARE_INTERFACE__MACROS_HPP_
17
18#include <stdexcept>
19#include <string>
20
21#include "rcpputils/pointer_traits.hpp"
22
23#ifdef _WIN32
24#define __PRETTY_FUNCTION__ __FUNCTION__
25#endif
26
27#define THROW_ON_NULLPTR(pointer) \
28 static_assert( \
29 rcpputils::is_pointer<typename std::remove_reference<decltype(pointer)>::type>::value, \
30 #pointer " has to be a pointer"); \
31 if (!pointer) \
32 { \
33 throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + " failed. " #pointer " is null."); \
34 }
35
36#define THROW_ON_NOT_NULLPTR(pointer) \
37 static_assert( \
38 rcpputils::is_pointer<typename std::remove_reference<decltype(pointer)>::type>::value, \
39 #pointer " has to be a pointer"); \
40 if (pointer) \
41 { \
42 throw std::runtime_error( \
43 std::string(__PRETTY_FUNCTION__) + " failed. " #pointer " would leak memory"); \
44 }
45
46#endif // HARDWARE_INTERFACE__MACROS_HPP_