DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
i_shared_ptr< T > Class Template Reference

#include <i_shared_ptr.hh>

Collaboration diagram for i_shared_ptr< T >:
[legend]

Public Member Functions

template<typename U , typename = std::enable_if_t<std::is_convertible_v<U *, T *>>>
 i_shared_ptr (const std::shared_ptr< U > &ptr)
 
template<typename U , typename std::enable_if<!std::is_same< T, U >::value, int >::type = 0>
 i_shared_ptr (const i_shared_ptr< U > &other)
 
 i_shared_ptr (const std::shared_ptr< std::remove_const_t< T > > &other)
 
template<typename U >
 i_shared_ptr (i_shared_ptr< U > &&other, typename enable_if_abstract< U >::type *=nullptr)
 
 i_shared_ptr (std::shared_ptr< T > &&other)
 
template<typename First , typename... Rest, typename = std::enable_if_t< !std::is_same_v<std::decay_t<First>, i_shared_ptr<T>> && !is_exact_std_shared_ptr<std::decay_t<First>>::value >>
 i_shared_ptr (First &&first, Rest &&... rest)
 
 i_shared_ptr (T *other)
 
template<typename X = T, typename = std::enable_if_t<std::is_base_of_v< VolumeBuilders::IVolumeBuilder, X>>>
 operator G4VSolid * ()
 
template<typename X = T, typename = std::enable_if_t<std::is_base_of_v< VolumeBuilders::IVolumeBuilder, X>>>
 operator G4LogicalVolume * ()
 
template<typename X = T, typename = std::enable_if_t<std::is_base_of_v< VolumeBuilders::IVolumeBuilder, X>>>
 operator G4VPhysicalVolume * ()
 
template<typename X = T, typename = std::enable_if_t<std::is_base_of_v< VolumeBuilders::IVolumeBuilder, X>>>
 operator G4Transform3D () const
 

Detailed Description

template<typename T>
class DLG4::i_shared_ptr< T >

A wrapper for std::shared_ptr that allows and facilitates many implicit(i) type conversions.

such as from T to i_shared_ptr<T>. Very useful for accepting paramters in a CRTP fluent base class You can accept a type erased class or ctor parameters to it and avoid BOTH the overload (ctor params) AND the templating (handled in the tpe erasing class in ONE place) at the method definition.

WARNING******** DO NOT ADD POINTER DATA TO THIS CLASS. DO NOT DELETE THROUGH shared_ptr BASE REFERENCE. The base class (shared_ptr) has a non-virtual destructor.. Technically any deletion through a base class pointer is undefined behavior according to C++. According to real compilers, It's fine, so long as there is nothing here that requires a delete call or such. This COULD be rewritten to hold the shared pointer instead of inheriting from it. AI even might get it right, might.

Template Parameters
TThe type of the object to be shared.

Definition at line 36 of file i_shared_ptr.hh.

Constructor & Destructor Documentation

◆ i_shared_ptr() [1/7]

template<typename T >
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U *, T *>>>
i_shared_ptr ( const std::shared_ptr< U > &  ptr)
inline

Definition at line 45 of file i_shared_ptr.hh.

45 : std::shared_ptr<T>(ptr) {
46 }

◆ i_shared_ptr() [2/7]

template<typename T >
template<typename U , typename std::enable_if<!std::is_same< T, U >::value, int >::type = 0>
i_shared_ptr ( const i_shared_ptr< U > &  other)
inline

Template constructor from i_shared_ptr where U can construct T.

Definition at line 52 of file i_shared_ptr.hh.

52 : std::shared_ptr<T>(other) {
53 }

◆ i_shared_ptr() [3/7]

template<typename T >
i_shared_ptr ( const std::shared_ptr< std::remove_const_t< T > > &  other)
inline

Definition at line 56 of file i_shared_ptr.hh.

57 : std::shared_ptr<T>(other) {
58 }

◆ i_shared_ptr() [4/7]

template<typename T >
template<typename U >
i_shared_ptr ( i_shared_ptr< U > &&  other,
typename enable_if_abstract< U >::type *  = nullptr 
)
inline

Definition at line 68 of file i_shared_ptr.hh.

70 : std::shared_ptr<T>(std::move(other)) {
71 }

◆ i_shared_ptr() [5/7]

template<typename T >
i_shared_ptr ( std::shared_ptr< T > &&  other)
inline

Explicit constructor from std::shared_ptr<T> (move)

Definition at line 79 of file i_shared_ptr.hh.

79 : std::shared_ptr<T>(std::move(other)) {
80 }

◆ i_shared_ptr() [6/7]

template<typename T >
template<typename First , typename... Rest, typename = std::enable_if_t< !std::is_same_v<std::decay_t<First>, i_shared_ptr<T>> && !is_exact_std_shared_ptr<std::decay_t<First>>::value >>
i_shared_ptr ( First &&  first,
Rest &&...  rest 
)
inline

Definition at line 106 of file i_shared_ptr.hh.

107 : std::shared_ptr<T>(new T(std::forward<First>(first), std::forward<Rest>(rest)...)) {
108 }

◆ i_shared_ptr() [7/7]

template<typename T >
i_shared_ptr ( T *  other)
inline

Implicit constructor from raw pointer (danger: takes ownership)

Definition at line 112 of file i_shared_ptr.hh.

112 : std::shared_ptr<T>(other) {
113 }

Member Function Documentation

◆ operator G4LogicalVolume *()

template<typename T >
template<typename X = T, typename = std::enable_if_t<std::is_base_of_v< VolumeBuilders::IVolumeBuilder, X>>>
operator G4LogicalVolume * ( )
inline

Definition at line 125 of file i_shared_ptr.hh.

125 {
126 auto other = static_cast<VolumeBuilders::IVolumeBuilder *>(this->get());
127 return other->GetLogicalVolume();
128 }

◆ operator G4Transform3D()

template<typename T >
template<typename X = T, typename = std::enable_if_t<std::is_base_of_v< VolumeBuilders::IVolumeBuilder, X>>>
operator G4Transform3D ( ) const
inline

Definition at line 141 of file i_shared_ptr.hh.

141 {
142 static_assert(std::is_base_of_v<VolumeBuilders::IVolumeBuilder, X>,
143 "T must derive from IVolumeBuilder");
144 auto other = static_cast<const VolumeBuilders::IVolumeBuilder *>(this->get());
145 return other->GetPhysTransform();
146 }

◆ operator G4VPhysicalVolume *()

template<typename T >
template<typename X = T, typename = std::enable_if_t<std::is_base_of_v< VolumeBuilders::IVolumeBuilder, X>>>
operator G4VPhysicalVolume * ( )
inline

Definition at line 133 of file i_shared_ptr.hh.

133 {
134 auto other = static_cast<VolumeBuilders::IVolumeBuilder *>(this->get());
135 return other->GetPlacement();
136 }

◆ operator G4VSolid *()

template<typename T >
template<typename X = T, typename = std::enable_if_t<std::is_base_of_v< VolumeBuilders::IVolumeBuilder, X>>>
operator G4VSolid * ( )
inline

Definition at line 117 of file i_shared_ptr.hh.

117 {
118 auto other = static_cast<VolumeBuilders::IVolumeBuilder *>(this->get());
119 return other->GetFinalSolid();
120 }

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