Euclid
Geometry Processing and Shape Analysis in C++
Euclid::ProPtr< T > Class Template Reference

A potentially resource owning pointer. More...

#include <Memory.h>

Public Types

using pointer = T *
 
using element_type = T
 

Public Member Functions

constexpr ProPtr () noexcept
 Default constructor.
 
constexpr ProPtr (std::nullptr_t) noexcept
 Construct from nullptr_t.
 
 ProPtr (pointer p, bool own=false) noexcept
 Construct from pointer. More...
 
 ProPtr (const ProPtr &pro)=delete
 Non-copyable.
 
 ProPtr (ProPtr &&pro) noexcept
 Move constructor.
 
template<typename U >
 ProPtr (ProPtr< U > &&pro) noexcept
 Move construct from a derived type.
 
 ~ProPtr ()
 Desctructor. More...
 
ProPtroperator= (const ProPtr &pro)=delete
 Non-copyable.
 
ProPtroperator= (std::nullptr_t) noexcept
 Copy assignment from nullptr. More...
 
ProPtroperator= (ProPtr &&pro) noexcept
 Move assignment operator.
 
template<typename U >
ProPtroperator= (ProPtr< U > &&pro) noexcept
 Move assignment from a derived type.
 
pointer release () noexcept
 Release the ownership(if owns) and return the data.
 
void reset (pointer p=pointer(), bool own=false) noexcept
 Reset the ProPtr. More...
 
void swap (ProPtr &pro) noexcept
 Swap this ProPtr with another, both resource and ownership.
 
pointer get () const noexcept
 Get the underlying resource.
 
 operator bool () const noexcept
 Return true if resource is valid.
 
std::add_lvalue_reference< T >::type operator* () const
 Return the data being pointed to.
 
pointer operator-> () const noexcept
 Return the raw pointer.
 
bool owns () const noexcept
 Return whether this pointer owns the resource.
 

Detailed Description

template<typename T>
class Euclid::ProPtr< T >

This class wraps up raw pointers who might or might not own the underlying resource. The motivation of this design is that when constructing complex algorithms one may need to use a lot of components, and some of them may share commonn internal computations. So it's desired that they are computed once and used everywhere as long as the user kept the underlying resource valid. This class will automatically manage the resource in one place and free the data when it goes out of scope.

Constructor & Destructor Documentation

template<typename T>
Euclid::ProPtr< T >::ProPtr ( pointer  p,
bool  own = false 
)
inlineexplicitnoexcept
Parameters
pThe raw pointer.
ownWhether to own the underlying memory. Default is false and this class acts just like a raw pointer. Set to true to act like a unique_ptr.
template<typename T>
Euclid::ProPtr< T >::~ProPtr ( )
inline

Free the memory if owns.

Member Function Documentation

template<typename T>
ProPtr& Euclid::ProPtr< T >::operator= ( std::nullptr_t  )
inlinenoexcept

Equals to call reset(nullptr).

template<typename T>
void Euclid::ProPtr< T >::reset ( pointer  p = pointer(),
bool  own = false 
)
inlinenoexcept

Note

Self-reset is not checked. Double owning is not checked either. Proceed with caution.


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