DynExp
Highly flexible laboratory automation for dynamically changing experiments.
DynExp::ObjectLink< ObjectT > Class Template Reference

Type to define object link parameters as ParamsBase::Param< ObjectLink< ObjectT > > or to define object link list parameters as ParamsBase::ListParam< ObjectLink< ObjectT > >. Such parameters own (one or multiple) ObjectLink instances and assign a resource to each instance. ObjectLink instances hold a std::weak_ptr to the resource and lock this weak_ptr if requested returning a respective LinkedObjectWrapper instance. A new resource can be assigned to an ObjectLink instance while LinkedObjectWrapper(s) exist since they hold an independent shared_ptr to the resource they have been created from. ObjectLink does not need to be thread-safe itself. All operations on it are performed through the respective ParamsBase::Param or ParamsBase::ListParam instance. To operate on those instances, the ParamsBase instance owning the respective parameter needs to be locked which renders ObjectLink implicitely thread-safe. More...

+ Inheritance diagram for DynExp::ObjectLink< ObjectT >:

Public Types

using ObjectType = ObjectT
 Equals ObjectT. More...
 
using ConstObjectType = std::add_const_t< ObjectT >
 Equals const ObjectT. More...
 

Public Member Functions

 ObjectLink ()
 Constructs an empty object link. More...
 
 ObjectLink (const std::shared_ptr< ObjectType > &DestinyResource)
 Constructs an object link pointing to DestinyResource. More...
 
virtual ~ObjectLink ()
 
void Reset ()
 Resets this object link rendering it empty. More...
 
auto & operator= (const std::shared_ptr< ObjectType > &NewDestinyResource)
 Assigns a new resource to this object link. More...
 
auto TryLockDestinyRaw ()
 Locks the resource this object link points to by creating a shared_ptr from it. This function can only be directly called by the main thread since only the respective ParamsBase::Param < LinkType > class has non-const access. More...
 

Private Member Functions

std::unique_ptr< LinkedObjectWrapper< ConstObjectType > > TryLockObject (const RunnableInstance &WrapperOwner, std::chrono::milliseconds Timeout=LockObjectTimeoutDefault) const
 Locks DestinyResource and wraps the locked Object in a LinkedObjectWrapper instance. Logical const-ness: the locked objects are const, so that users can only call const member functions on them. More...
 
auto LockObject (const RunnableInstance &WrapperOwner, std::chrono::milliseconds Timeout=LockObjectTimeoutDefault) const
 Locks DestinyResource and wraps the locked Object in a LinkedObjectWrapper instance. Logical const-ness: the locked objects are const, so that users can only call const member functions on them. More...
 

Private Attributes

std::weak_ptr< ObjectTypeDestinyResource
 Pointer to the (unlocked) resource this object link points to. Logical const-ness: the weak_ptr's type (type of the unlocked Object) is not const, so that the main thread (which locks the objects) can perform any operation on unlocked objects. More...
 

Friends

class RunnableInstance
 

Additional Inherited Members

- Static Public Attributes inherited from DynExp::ObjectLinkBase
static constexpr std::chrono::milliseconds LockObjectTimeoutDefault = std::chrono::milliseconds(100)
 Default timeout used by classes ObjectLinkt and RunnableInstance to be passed to LinkedObjectWrapper::LinkedObjectWrapper. More...
 
- Protected Member Functions inherited from DynExp::ObjectLinkBase
 ObjectLinkBase ()=default
 
virtual ~ObjectLinkBase ()=0
 

Detailed Description

template<typename ObjectT>
class DynExp::ObjectLink< ObjectT >

Type to define object link parameters as ParamsBase::Param< ObjectLink< ObjectT > > or to define object link list parameters as ParamsBase::ListParam< ObjectLink< ObjectT > >. Such parameters own (one or multiple) ObjectLink instances and assign a resource to each instance. ObjectLink instances hold a std::weak_ptr to the resource and lock this weak_ptr if requested returning a respective LinkedObjectWrapper instance. A new resource can be assigned to an ObjectLink instance while LinkedObjectWrapper(s) exist since they hold an independent shared_ptr to the resource they have been created from. ObjectLink does not need to be thread-safe itself. All operations on it are performed through the respective ParamsBase::Param or ParamsBase::ListParam instance. To operate on those instances, the ParamsBase instance owning the respective parameter needs to be locked which renders ObjectLink implicitely thread-safe.

Template Parameters
ObjectTType of the managed Object.

Definition at line 3382 of file Object.h.

Member Typedef Documentation

◆ ConstObjectType

template<typename ObjectT >
using DynExp::ObjectLink< ObjectT >::ConstObjectType = std::add_const_t<ObjectT>

Equals const ObjectT.

Definition at line 3386 of file Object.h.

◆ ObjectType

template<typename ObjectT >
using DynExp::ObjectLink< ObjectT >::ObjectType = ObjectT

Equals ObjectT.

Definition at line 3385 of file Object.h.

Constructor & Destructor Documentation

◆ ObjectLink() [1/2]

template<typename ObjectT >
DynExp::ObjectLink< ObjectT >::ObjectLink ( )
inline

Constructs an empty object link.

Definition at line 3393 of file Object.h.

◆ ObjectLink() [2/2]

template<typename ObjectT >
DynExp::ObjectLink< ObjectT >::ObjectLink ( const std::shared_ptr< ObjectType > &  DestinyResource)
inline

Constructs an object link pointing to DestinyResource.

Parameters
DestinyResourceResource this object link points to

Definition at line 3399 of file Object.h.

◆ ~ObjectLink()

template<typename ObjectT >
virtual DynExp::ObjectLink< ObjectT >::~ObjectLink ( )
inlinevirtual

Definition at line 3401 of file Object.h.

Member Function Documentation

◆ LockObject()

template<typename ObjectT >
auto DynExp::ObjectLink< ObjectT >::LockObject ( const RunnableInstance WrapperOwner,
std::chrono::milliseconds  Timeout = LockObjectTimeoutDefault 
) const
inlineprivate

Locks DestinyResource and wraps the locked Object in a LinkedObjectWrapper instance. Logical const-ness: the locked objects are const, so that users can only call const member functions on them.

Parameters
WrapperOwnerRunnableInstance instance owning the LinkedObjectWrapper instance this function attempts to create.
TimeoutTimeout to be passed to LinkedObjectWrapper::LinkedObjectWrapper
Returns
Returns a pointer to a LinkedObjectWrapper instance containing the locked Object instance.
Exceptions
Util::InvalidObjectLinkExceptionis thrown if this object link is empty.

Definition at line 3471 of file Object.h.

◆ operator=()

template<typename ObjectT >
auto& DynExp::ObjectLink< ObjectT >::operator= ( const std::shared_ptr< ObjectType > &  NewDestinyResource)
inline

Assigns a new resource to this object link.

Parameters
NewDestinyResourceResource this object link now points to
Returns
Returns the object link instance itself.

Definition at line 3413 of file Object.h.

◆ Reset()

template<typename ObjectT >
void DynExp::ObjectLink< ObjectT >::Reset ( )
inline

Resets this object link rendering it empty.

Definition at line 3406 of file Object.h.

◆ TryLockDestinyRaw()

template<typename ObjectT >
auto DynExp::ObjectLink< ObjectT >::TryLockDestinyRaw ( )
inline

Locks the resource this object link points to by creating a shared_ptr from it. This function can only be directly called by the main thread since only the respective ParamsBase::Param < LinkType > class has non-const access.

Returns
shared_ptr pointing to the resource this object link points to

Definition at line 3430 of file Object.h.

◆ TryLockObject()

template<typename ObjectT >
std::unique_ptr<LinkedObjectWrapper<ConstObjectType> > DynExp::ObjectLink< ObjectT >::TryLockObject ( const RunnableInstance WrapperOwner,
std::chrono::milliseconds  Timeout = LockObjectTimeoutDefault 
) const
inlineprivate

Locks DestinyResource and wraps the locked Object in a LinkedObjectWrapper instance. Logical const-ness: the locked objects are const, so that users can only call const member functions on them.

Parameters
WrapperOwnerRunnableInstance instance owning the LinkedObjectWrapper instance this function attempts to create.
TimeoutTimeout to be passed to LinkedObjectWrapper::LinkedObjectWrapper
Returns
Returns a pointer to a LinkedObjectWrapper instance containing the locked Object instance. Returns nullptr if this object link is empty.

Definition at line 3447 of file Object.h.

Friends And Related Function Documentation

◆ RunnableInstance

template<typename ObjectT >
friend class RunnableInstance
friend

Definition at line 3388 of file Object.h.

Member Data Documentation

◆ DestinyResource

template<typename ObjectT >
std::weak_ptr<ObjectType> DynExp::ObjectLink< ObjectT >::DestinyResource
private

Pointer to the (unlocked) resource this object link points to. Logical const-ness: the weak_ptr's type (type of the unlocked Object) is not const, so that the main thread (which locks the objects) can perform any operation on unlocked objects.

Definition at line 3486 of file Object.h.


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