DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Util::SynchronizedPointer< T > Class Template Reference

Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads. Instances of this class are not intended to be stored somewhere since they make other threads block. Only use as temporary objects. More...

+ Inheritance diagram for Util::SynchronizedPointer< T >:

Public Member Functions

 SynchronizedPointer () noexcept
 Contructs an instance with an empty pointer. More...
 
 SynchronizedPointer (T *const LockableObject, const std::chrono::milliseconds Timeout=ILockable::DefaultTimeout)
 Constructs a pointer locking LockableObject. Blocks until LockableObject's mutex is locked or until the timeout duration is exceeded. Recursive locking is allowed. More...
 
 SynchronizedPointer (SynchronizedPointer &&Other) noexcept
 Moves the LockableObject from another SynchronizedPointer instance Other to a new instance. Other becomes empty. More...
 
SynchronizedPointeroperator= (SynchronizedPointer &&Other) noexcept
 Move-assigns the LockableObject from another SynchronizedPointer instance Other to this instance. Other becomes empty. More...
 
template<typename U >
 SynchronizedPointer (SynchronizedPointer< U > &&Other)
 Moves the LockableObject from a SynchronizedPointer<U> of another type U to a new instance of SynchronizedPointer<T> using dynamic_cast. Other becomes empty. More...
 
 ~SynchronizedPointer ()
 
auto get () const noexcept
 Returns the managed (locked) object. More...
 
bool operator== (const T *rhs) const noexcept
 
bool operator!= (const T *rhs) const noexcept
 
bool operator== (const SynchronizedPointer &rhs) const noexcept
 
bool operator!= (const SynchronizedPointer &rhs) const noexcept
 
 operator bool () const noexcept
 
auto operator-> () const noexcept
 
auto & operator* () const noexcept
 
- Public Member Functions inherited from Util::INonCopyable
 INonCopyable (const INonCopyable &)=delete
 
INonCopyableoperator= (const INonCopyable &)=delete
 

Private Attributes

T * LockableObject
 Pointer to the locakable object managed by this class. More...
 

Friends

template<typename >
class SynchronizedPointer
 

Additional Inherited Members

- Protected Member Functions inherited from Util::INonCopyable
constexpr INonCopyable ()=default
 
 ~INonCopyable ()=default
 

Detailed Description

template<typename T>
class Util::SynchronizedPointer< T >

Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads. Instances of this class are not intended to be stored somewhere since they make other threads block. Only use as temporary objects.

Template Parameters
TType derived from ISynchronizedPointerLockable to be managed by this pointer.

Definition at line 169 of file Util.h.

Constructor & Destructor Documentation

◆ SynchronizedPointer() [1/4]

template<typename T >
Util::SynchronizedPointer< T >::SynchronizedPointer ( )
inlinenoexcept

Contructs an instance with an empty pointer.

Definition at line 178 of file Util.h.

◆ SynchronizedPointer() [2/4]

template<typename T >
Util::SynchronizedPointer< T >::SynchronizedPointer ( T *const  LockableObject,
const std::chrono::milliseconds  Timeout = ILockable::DefaultTimeout 
)
inline

Constructs a pointer locking LockableObject. Blocks until LockableObject's mutex is locked or until the timeout duration is exceeded. Recursive locking is allowed.

Parameters
LockableObjectPointer to an instance of a class derived from ISynchronizedPointerLockable to be locked.
TimeoutTime to wait trying to lock the internal mutex. 0 ms means that the functions waits for the mutex without timing out ever.

Definition at line 188 of file Util.h.

◆ SynchronizedPointer() [3/4]

template<typename T >
Util::SynchronizedPointer< T >::SynchronizedPointer ( SynchronizedPointer< T > &&  Other)
inlinenoexcept

Moves the LockableObject from another SynchronizedPointer instance Other to a new instance. Other becomes empty.

Parameters
OtherSynchronizedPointer instance to move from

Definition at line 197 of file Util.h.

◆ SynchronizedPointer() [4/4]

template<typename T >
template<typename U >
Util::SynchronizedPointer< T >::SynchronizedPointer ( SynchronizedPointer< U > &&  Other)
inlineexplicit

Moves the LockableObject from a SynchronizedPointer<U> of another type U to a new instance of SynchronizedPointer<T> using dynamic_cast. Other becomes empty.

Template Parameters
UType derived from ISynchronizedPointerLockable managed by Other
Parameters
OtherSynchronizedPointer instance to move from
Exceptions
TypeErrorExceptionis thrown if dynamic_cast fails due to an incompatible type U.

Definition at line 221 of file Util.h.

◆ ~SynchronizedPointer()

template<typename T >
Util::SynchronizedPointer< T >::~SynchronizedPointer ( )
inline

Definition at line 235 of file Util.h.

Member Function Documentation

◆ get()

template<typename T >
auto Util::SynchronizedPointer< T >::get ( ) const
inlinenoexcept

Returns the managed (locked) object.

Returns
Pointer to an instance of a class derived from ISynchronizedPointerLockable

Definition at line 241 of file Util.h.

◆ operator bool()

template<typename T >
Util::SynchronizedPointer< T >::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 247 of file Util.h.

◆ operator!=() [1/2]

template<typename T >
bool Util::SynchronizedPointer< T >::operator!= ( const SynchronizedPointer< T > &  rhs) const
inlinenoexcept

Definition at line 246 of file Util.h.

◆ operator!=() [2/2]

template<typename T >
bool Util::SynchronizedPointer< T >::operator!= ( const T *  rhs) const
inlinenoexcept

Definition at line 244 of file Util.h.

◆ operator*()

template<typename T >
auto& Util::SynchronizedPointer< T >::operator* ( ) const
inlinenoexcept

Definition at line 250 of file Util.h.

◆ operator->()

template<typename T >
auto Util::SynchronizedPointer< T >::operator-> ( ) const
inlinenoexcept

Definition at line 249 of file Util.h.

◆ operator=()

template<typename T >
SynchronizedPointer& Util::SynchronizedPointer< T >::operator= ( SynchronizedPointer< T > &&  Other)
inlinenoexcept

Move-assigns the LockableObject from another SynchronizedPointer instance Other to this instance. Other becomes empty.

Parameters
OtherSynchronizedPointer instance to move from
Returns
Reference to this instance

Definition at line 205 of file Util.h.

◆ operator==() [1/2]

template<typename T >
bool Util::SynchronizedPointer< T >::operator== ( const SynchronizedPointer< T > &  rhs) const
inlinenoexcept

Definition at line 245 of file Util.h.

◆ operator==() [2/2]

template<typename T >
bool Util::SynchronizedPointer< T >::operator== ( const T *  rhs) const
inlinenoexcept

Definition at line 243 of file Util.h.

Friends And Related Function Documentation

◆ SynchronizedPointer

template<typename T >
template<typename >
friend class SynchronizedPointer
friend

Definition at line 172 of file Util.h.

Member Data Documentation

◆ LockableObject

template<typename T >
T* Util::SynchronizedPointer< T >::LockableObject
private

Pointer to the locakable object managed by this class.

Definition at line 256 of file Util.h.


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