www.mooseframework.org
Functions
CastUniquePointer.h File Reference

Go to the source code of this file.

Functions

template<typename T_DEST , typename T_SRC , typename T_DELETER >
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast (std::unique_ptr< T_SRC, T_DELETER > &src)
 These are reworked from https://stackoverflow.com/a/11003103. More...
 
template<typename T_DEST , typename T_SRC >
std::unique_ptr< T_DEST > dynamic_pointer_cast (std::unique_ptr< T_SRC > &src)
 

Function Documentation

◆ dynamic_pointer_cast() [1/2]

template<typename T_DEST , typename T_SRC >
std::unique_ptr<T_DEST> dynamic_pointer_cast ( std::unique_ptr< T_SRC > &  src)

Definition at line 40 of file CastUniquePointer.h.

41 {
42  if (!src)
43  return std::unique_ptr<T_DEST>(nullptr);
44 
45  T_DEST * dest_ptr = dynamic_cast<T_DEST *>(src.get());
46  if (!dest_ptr)
47  return std::unique_ptr<T_DEST>(nullptr);
48 
49  std::unique_ptr<T_DEST> dest_temp(dest_ptr);
50 
51  src.release();
52 
53  return dest_temp;
54 }

◆ dynamic_pointer_cast() [2/2]

template<typename T_DEST , typename T_SRC , typename T_DELETER >
std::unique_ptr<T_DEST, T_DELETER> dynamic_pointer_cast ( std::unique_ptr< T_SRC, T_DELETER > &  src)

These are reworked from https://stackoverflow.com/a/11003103.

New GitHub Repo here: https://github.com/friedmud/unique_ptr_cast

Definition at line 22 of file CastUniquePointer.h.

23 {
24  if (!src)
25  return std::unique_ptr<T_DEST, T_DELETER>(nullptr);
26 
27  T_DEST * dest_ptr = dynamic_cast<T_DEST *>(src.get());
28  if (!dest_ptr)
29  return std::unique_ptr<T_DEST, T_DELETER>(nullptr);
30 
31  std::unique_ptr<T_DEST, T_DELETER> dest_temp(dest_ptr, std::move(src.get_deleter()));
32 
33  src.release();
34 
35  return dest_temp;
36 }

Referenced by NonlinearSystemBase::addBoundaryCondition(), NonlinearSystemBase::addKernel(), MooseObjectWarehouse< Indicator >::addObject(), and ComputeMortarFunctor< compute_stage >::ComputeMortarFunctor().