ros2_control - rolling
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#include <type_traits>
21
22#include "rcpputils/pointer_traits.hpp"
23
24#ifdef _WIN32
25#define __PRETTY_FUNCTION__ __FUNCTION__
26#endif
27
28#define THROW_ON_NULLPTR(pointer) \
29 static_assert( \
30 rcpputils::is_pointer<typename std::remove_reference<decltype(pointer)>::type>::value, \
31 #pointer " has to be a pointer"); \
32 if (!pointer) \
33 { \
34 throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + " failed. " #pointer " is null."); \
35 }
36
37#define THROW_ON_NOT_NULLPTR(pointer) \
38 static_assert( \
39 rcpputils::is_pointer<typename std::remove_reference<decltype(pointer)>::type>::value, \
40 #pointer " has to be a pointer"); \
41 if (pointer) \
42 { \
43 throw std::runtime_error( \
44 std::string(__PRETTY_FUNCTION__) + " failed. " #pointer " would leak memory"); \
45 }
46
47#endif // HARDWARE_INTERFACE__MACROS_HPP_