ConvertShared.hpp
Go to the documentation of this file.
1 
28 /*
29  * ConvertShared.hpp
30  */
31 
32 #ifndef LVR2_UTIL_CONVERT_SHARED_H_
33 #define LVR2_UTIL_CONVERT_SHARED_H_
34 
35 #include <memory>
36 #include <boost/shared_ptr.hpp>
37 namespace lvr2
38 {
39 
40 namespace {
41  template<class SharedPointer> struct Holder {
42  SharedPointer p;
43 
44  Holder(const SharedPointer &p) : p(p) {}
45  Holder(const Holder &other) : p(other.p) {}
46  Holder(Holder &&other) : p(std::move(other.p)) {}
47 
48  void operator () (...) { p.reset(); }
49  };
50 }
51 
52 template<class T> std::shared_ptr<T> to_std_ptr(const boost::shared_ptr<T> &p) {
53  typedef Holder<std::shared_ptr<T>> H;
54  if(H *h = boost::get_deleter<H, T>(p)) {
55  return h->p;
56  } else {
57  return std::shared_ptr<T>(p.get(), Holder<boost::shared_ptr<T>>(p));
58  }
59 }
60 
61 template<class T> boost::shared_ptr<T> to_boost_ptr(const std::shared_ptr<T> &p){
62  typedef Holder<boost::shared_ptr<T>> H;
63  if(H * h = std::get_deleter<H, T>(p)) {
64  return h->p;
65  } else {
66  return boost::shared_ptr<T>(p.get(), Holder<std::shared_ptr<T>>(p));
67  }
68 }
69 }
70 #endif /* LVR2_UTIL_CONVERT_SHARED_H_ */
p
SharedPointer p
Definition: ConvertShared.hpp:42
lvr2::to_std_ptr
std::shared_ptr< T > to_std_ptr(const boost::shared_ptr< T > &p)
Definition: ConvertShared.hpp:52
std
Definition: HalfEdge.hpp:124
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::to_boost_ptr
boost::shared_ptr< T > to_boost_ptr(const std::shared_ptr< T > &p)
Definition: ConvertShared.hpp:61


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:23