Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::AnyPtr< T > Class Template Reference

#include <src/libslic3r/AnyPtr.hpp>

+ Inheritance diagram for Slic3r::AnyPtr< T >:

Public Member Functions

template<class TT = T, class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
 AnyPtr (TT *p=nullptr)
 
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
 AnyPtr (std::unique_ptr< TT > p)
 
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
 AnyPtr (std::shared_ptr< TT > p)
 
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
 AnyPtr (std::weak_ptr< TT > p)
 
 ~AnyPtr ()=default
 
 AnyPtr (AnyPtr &&other) noexcept
 
 AnyPtr (const AnyPtr &other)=delete
 
AnyPtroperator= (AnyPtr &&other) noexcept
 
AnyPtroperator= (const AnyPtr &other)=delete
 
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
AnyPtroperator= (TT *p)
 
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
AnyPtroperator= (std::unique_ptr< TT > p)
 
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
AnyPtroperator= (std::shared_ptr< TT > p)
 
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
AnyPtroperator= (std::weak_ptr< TT > p)
 
const T & operator* () const
 
T & operator* ()
 
T * operator-> ()
 
const T * operator-> () const
 
T * get ()
 
const T * get () const
 
 operator bool () const
 
std::shared_ptr< T > get_shared_cpy () const
 
void convert_unique_to_shared ()
 
bool is_owned () const noexcept
 

Private Types

enum  { RawPtr , UPtr , ShPtr , WkPtr }
 

Static Private Member Functions

template<class Self >
static T * get_ptr (Self &&s)
 

Private Attributes

boost::variant< T *, std::unique_ptr< T >, std::shared_ptr< T >, std::weak_ptr< T > > ptr
 

Detailed Description

template<class T>
class Slic3r::AnyPtr< T >

Member Enumeration Documentation

◆ anonymous enum

template<class T >
anonymous enum
private
Enumerator
RawPtr 
UPtr 
ShPtr 
WkPtr 
21{ RawPtr, UPtr, ShPtr, WkPtr };
@ ShPtr
Definition AnyPtr.hpp:21
@ WkPtr
Definition AnyPtr.hpp:21
@ UPtr
Definition AnyPtr.hpp:21
@ RawPtr
Definition AnyPtr.hpp:21

Constructor & Destructor Documentation

◆ AnyPtr() [1/6]

template<class T >
template<class TT = T, class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
Slic3r::AnyPtr< T >::AnyPtr ( TT *  p = nullptr)
inline
42 : ptr{p}
43 {}
boost::variant< T *, std::unique_ptr< T >, std::shared_ptr< T >, std::weak_ptr< T > > ptr
Definition AnyPtr.hpp:23

◆ AnyPtr() [2/6]

template<class T >
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
Slic3r::AnyPtr< T >::AnyPtr ( std::unique_ptr< TT >  p)
inline
45 : ptr{std::unique_ptr<T>(std::move(p))}
46 {}

◆ AnyPtr() [3/6]

template<class T >
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
Slic3r::AnyPtr< T >::AnyPtr ( std::shared_ptr< TT >  p)
inline
48 : ptr{std::shared_ptr<T>(std::move(p))}
49 {}

◆ AnyPtr() [4/6]

template<class T >
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
Slic3r::AnyPtr< T >::AnyPtr ( std::weak_ptr< TT >  p)
inline
51 : ptr{std::weak_ptr<T>(std::move(p))}
52 {}

◆ ~AnyPtr()

template<class T >
Slic3r::AnyPtr< T >::~AnyPtr ( )
default

◆ AnyPtr() [5/6]

template<class T >
Slic3r::AnyPtr< T >::AnyPtr ( AnyPtr< T > &&  other)
inlinenoexcept
56: ptr{std::move(other.ptr)} {}

◆ AnyPtr() [6/6]

template<class T >
Slic3r::AnyPtr< T >::AnyPtr ( const AnyPtr< T > &  other)
delete

Member Function Documentation

◆ convert_unique_to_shared()

template<class T >
void Slic3r::AnyPtr< T >::convert_unique_to_shared ( )
inline
116 {
117 if (ptr.which() == UPtr)
118 ptr = std::shared_ptr<T>{std::move(boost::get<std::unique_ptr<T>>(ptr))};
119 }

References Slic3r::AnyPtr< T >::ptr, and Slic3r::AnyPtr< T >::UPtr.

◆ get() [1/2]

template<class T >
T * Slic3r::AnyPtr< T >::get ( )
inline
80{ return get_ptr(*this); }
static T * get_ptr(Self &&s)
Definition AnyPtr.hpp:25

References Slic3r::AnyPtr< T >::get_ptr().

Referenced by Slic3r::AnyPtr< T >::get_ptr(), Slic3r::GUI::MeshClipper::set_mesh(), Slic3r::GUI::MeshClipper::set_mesh(), Slic3r::GUI::MeshClipper::set_negative_mesh(), and Slic3r::GUI::MeshClipper::set_negative_mesh().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get() [2/2]

template<class T >
const T * Slic3r::AnyPtr< T >::get ( ) const
inline
81{ return get_ptr(*this); }

References Slic3r::AnyPtr< T >::get_ptr().

+ Here is the call graph for this function:

◆ get_ptr()

template<class T >
template<class Self >
static T * Slic3r::AnyPtr< T >::get_ptr ( Self &&  s)
inlinestaticprivate
26 {
27 switch (s.ptr.which()) {
28 case RawPtr: return boost::get<T *>(s.ptr);
29 case UPtr: return boost::get<std::unique_ptr<T>>(s.ptr).get();
30 case ShPtr: return boost::get<std::shared_ptr<T>>(s.ptr).get();
31 case WkPtr: {
32 auto shptr = boost::get<std::weak_ptr<T>>(s.ptr).lock();
33 return shptr.get();
34 }
35 }
36
37 return nullptr;
38 }
T * get()
Definition AnyPtr.hpp:80

References Slic3r::AnyPtr< T >::get(), Slic3r::AnyPtr< T >::RawPtr, Slic3r::AnyPtr< T >::ShPtr, Slic3r::AnyPtr< T >::UPtr, and Slic3r::AnyPtr< T >::WkPtr.

Referenced by Slic3r::AnyPtr< T >::get(), Slic3r::AnyPtr< T >::get(), Slic3r::AnyPtr< T >::operator*(), Slic3r::AnyPtr< T >::operator*(), Slic3r::AnyPtr< T >::operator->(), and Slic3r::AnyPtr< T >::operator->().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_shared_cpy()

template<class T >
std::shared_ptr< T > Slic3r::AnyPtr< T >::get_shared_cpy ( ) const
inline
101 {
102 std::shared_ptr<T> ret;
103
104 switch (ptr.which()) {
105 case ShPtr: ret = boost::get<std::shared_ptr<T>>(ptr); break;
106 case WkPtr: ret = boost::get<std::weak_ptr<T>>(ptr).lock(); break;
107 default:
108 ;
109 }
110
111 return ret;
112 }

References Slic3r::AnyPtr< T >::ptr, Slic3r::AnyPtr< T >::ShPtr, and Slic3r::AnyPtr< T >::WkPtr.

◆ is_owned()

template<class T >
bool Slic3r::AnyPtr< T >::is_owned ( ) const
inlinenoexcept
123 {
124 return ptr.which() == UPtr || ptr.which() == ShPtr;
125 }

References Slic3r::AnyPtr< T >::ptr, Slic3r::AnyPtr< T >::ShPtr, and Slic3r::AnyPtr< T >::UPtr.

◆ operator bool()

template<class T >
Slic3r::AnyPtr< T >::operator bool ( ) const
inline
84 {
85 switch (ptr.which()) {
86 case RawPtr: return bool(boost::get<T *>(ptr));
87 case UPtr: return bool(boost::get<std::unique_ptr<T>>(ptr));
88 case ShPtr: return bool(boost::get<std::shared_ptr<T>>(ptr));
89 case WkPtr: {
90 auto shptr = boost::get<std::weak_ptr<T>>(ptr).lock();
91 return bool(shptr);
92 }
93 }
94
95 return false;
96 }

References Slic3r::AnyPtr< T >::ptr, Slic3r::AnyPtr< T >::RawPtr, Slic3r::AnyPtr< T >::ShPtr, Slic3r::AnyPtr< T >::UPtr, and Slic3r::AnyPtr< T >::WkPtr.

◆ operator*() [1/2]

template<class T >
T & Slic3r::AnyPtr< T >::operator* ( )
inline
75{ return *get_ptr(*this); }

References Slic3r::AnyPtr< T >::get_ptr().

+ Here is the call graph for this function:

◆ operator*() [2/2]

template<class T >
const T & Slic3r::AnyPtr< T >::operator* ( ) const
inline
74{ return *get_ptr(*this); }

References Slic3r::AnyPtr< T >::get_ptr().

+ Here is the call graph for this function:

◆ operator->() [1/2]

template<class T >
T * Slic3r::AnyPtr< T >::operator-> ( )
inline
77{ return get_ptr(*this); }

References Slic3r::AnyPtr< T >::get_ptr().

+ Here is the call graph for this function:

◆ operator->() [2/2]

template<class T >
const T * Slic3r::AnyPtr< T >::operator-> ( ) const
inline
78{ return get_ptr(*this); }

References Slic3r::AnyPtr< T >::get_ptr().

+ Here is the call graph for this function:

◆ operator=() [1/6]

template<class T >
AnyPtr & Slic3r::AnyPtr< T >::operator= ( AnyPtr< T > &&  other)
inlinenoexcept
59{ ptr = std::move(other.ptr); return *this; }

References Slic3r::AnyPtr< T >::ptr.

◆ operator=() [2/6]

template<class T >
AnyPtr & Slic3r::AnyPtr< T >::operator= ( const AnyPtr< T > &  other)
delete

◆ operator=() [3/6]

template<class T >
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
AnyPtr & Slic3r::AnyPtr< T >::operator= ( std::shared_ptr< TT >  p)
inline
69{ ptr = p; return *this; }

References Slic3r::AnyPtr< T >::ptr.

◆ operator=() [4/6]

template<class T >
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
AnyPtr & Slic3r::AnyPtr< T >::operator= ( std::unique_ptr< TT >  p)
inline
66{ ptr = std::move(p); return *this; }

References Slic3r::AnyPtr< T >::ptr.

◆ operator=() [5/6]

template<class T >
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
AnyPtr & Slic3r::AnyPtr< T >::operator= ( std::weak_ptr< TT >  p)
inline
72{ ptr = std::move(p); return *this; }

References Slic3r::AnyPtr< T >::ptr.

◆ operator=() [6/6]

template<class T >
template<class TT , class = std::enable_if_t<std::is_convertible_v<TT*, T*>>>
AnyPtr & Slic3r::AnyPtr< T >::operator= ( TT *  p)
inline
63{ ptr = p; return *this; }

References Slic3r::AnyPtr< T >::ptr.

Member Data Documentation

◆ ptr


The documentation for this class was generated from the following file: