Aikido
BackwardCompatibility.hpp
Go to the documentation of this file.
1 // This header is for supporting OMPL across the multiple versions that include
2 // API breaking changes. Currently, the most part is to support changes from the
3 // usage of Boost to C++11 STL equivalents.
4 
5 #ifndef AIKIDO_PLANNER_OMPL_BACKWARDCOMPATIBILITY_HPP_
6 #define AIKIDO_PLANNER_OMPL_BACKWARDCOMPATIBILITY_HPP_
7 
8 #include <ompl/config.h>
9 
10 // clang-format off
11 
12 #define OMPL_VERSION_AT_LEAST(x,y,z) \
13  (OMPL_MAJOR_VERSION > x || (OMPL_MAJOR_VERSION >= x && \
14  (OMPL_MINOR_VERSION > y || (OMPL_MINOR_VERSION >= y && \
15  OMPL_PATCH_VERSION >= z))))
16 
17 #define OMPL_MAJOR_MINOR_VERSION_AT_LEAST(x,y) \
18  (OMPL_MAJOR_VERSION > x || (OMPL_MAJOR_VERSION >= x && \
19  (OMPL_MINOR_VERSION > y || (OMPL_MINOR_VERSION >= y))))
20 
21 #define OMPL_VERSION_AT_MOST(x,y,z) \
22  (OMPL_MAJOR_VERSION < x || (OMPL_MAJOR_VERSION <= x && \
23  (OMPL_MINOR_VERSION < y || (OMPL_MINOR_VERSION <= y && \
24  OMPL_PATCH_VERSION <= z))))
25 
26 #define OMPL_MAJOR_MINOR_VERSION_AT_MOST(x,y) \
27  (OMPL_MAJOR_VERSION < x || (OMPL_MAJOR_VERSION <= x && \
28  (OMPL_MINOR_VERSION < y || (OMPL_MINOR_VERSION <= y))))
29 
30 // clang-format on
31 
32 #if OMPL_VERSION_AT_LEAST(1, 2, 0)
33 #include <memory>
34 #else
35 #include <boost/smart_ptr.hpp>
36 #include <boost/bind.hpp>
37 #endif
38 
39 namespace aikido {
40 namespace planner {
41 namespace ompl {
42 
43 #if OMPL_VERSION_AT_LEAST(1, 2, 0)
44 
45 #define OMPL_PLACEHOLDER(ph) std::placeholders::ph
46 
47 template <class T>
48 using ompl_shared_ptr = std::shared_ptr<T>;
49 
50 template <class T>
51 using ompl_weak_ptr = std::weak_ptr<T>;
52 
53 template <class T, class... Args>
55 {
56  return std::make_shared<T>(std::forward<Args>(args)...);
57 }
58 
59 template <class T, class U>
61 {
62  return std::dynamic_pointer_cast<T>(r);
63 }
64 
65 template <class T, class U>
67 {
68  return std::static_pointer_cast<T>(r);
69 }
70 
71 template <class F, class... Args>
72 auto ompl_bind(F&& f, Args&&... args)
73  -> decltype(std::bind(std::forward<F>(f), std::forward<Args>(args)...))
74 {
75  return std::bind(std::forward<F>(f), std::forward<Args>(args)...);
76 }
77 
78 #else // OMPL_VERSION_AT_LEAST(1,2,0)
79 
80 #define OMPL_PLACEHOLDER(ph) ph
81 
82 template <class T>
83 using ompl_shared_ptr = boost::shared_ptr<T>;
84 
85 template <class T>
86 using ompl_weak_ptr = boost::weak_ptr<T>;
87 
88 template <class T, class... Args>
90 {
91  return boost::make_shared<T>(std::forward<Args>(args)...);
92 }
93 
94 template <class T, class U>
96 {
97  return boost::dynamic_pointer_cast<T>(r);
98 }
99 
100 template <class T, class U>
102 {
103  return boost::static_pointer_cast<T>(r);
104 }
105 
106 template <class F, class... Args>
107 auto ompl_bind(F&& f, Args&&... args)
108  -> decltype(boost::bind(std::forward<F>(f), std::forward<Args>(args)...))
109 {
110  return boost::bind(std::forward<F>(f), std::forward<Args>(args)...);
111 }
112 
113 #endif // OMPL_VERSION_AT_LEAST(1,2,0)
114 
115 } // namespace ompl
116 } // namespace planner
117 } // namespace aikido
118 
119 #endif // AIKIDO_PLANNER_OMPL_BACKWARDCOMPATIBILITY_HPP_
aikido::planner::ompl::ompl_shared_ptr
boost::shared_ptr< T > ompl_shared_ptr
Definition: BackwardCompatibility.hpp:83
aikido
Format of serialized trajectory in YAML.
Definition: algorithm.hpp:4
aikido::planner::ompl::ompl_static_pointer_cast
ompl_shared_ptr< T > ompl_static_pointer_cast(const ompl_shared_ptr< U > &r)
Definition: BackwardCompatibility.hpp:101
aikido::planner::ompl::ompl_dynamic_pointer_cast
ompl_shared_ptr< T > ompl_dynamic_pointer_cast(const ompl_shared_ptr< U > &r)
Definition: BackwardCompatibility.hpp:95
aikido::planner::ompl::ompl_weak_ptr
boost::weak_ptr< T > ompl_weak_ptr
Definition: BackwardCompatibility.hpp:86
aikido::planner::ompl::ompl_bind
auto ompl_bind(F &&f, Args &&... args) -> decltype(boost::bind(std::forward< F >(f), std::forward< Args >(args)...))
Definition: BackwardCompatibility.hpp:107
aikido::planner::ompl::ompl_make_shared
ompl_shared_ptr< T > ompl_make_shared(Args &&... args)
Definition: BackwardCompatibility.hpp:89