Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::CoreServicePointer< S > Class Template Reference

RAII wrapper for core service objects. More...

#include <mitkCoreServices.h>

Inheritance diagram for mitk::CoreServicePointer< S >:

Public Member Functions

 CoreServicePointer (S *service, us::ModuleContext *context=us::GetModuleContext())
 Construct a RAII wrapper around a service pointer. More...
 
 ~CoreServicePointer ()
 Destructor. Releases the managed service via CoreServices::Unget(). More...
 
 operator bool () const
 Check if this pointer holds a valid (non-null) service. More...
 
S * operator-> () const
 Dereference the managed service pointer. More...
 
S * Get () const
 Get the raw service pointer. More...
 
 CoreServicePointer (const CoreServicePointer &)=delete
 
CoreServicePointer & operator= (const CoreServicePointer &)=delete
 

Detailed Description

template<class S>
class mitk::CoreServicePointer< S >

RAII wrapper for core service objects.

Intended for local-scope use: automatically calls CoreServices::Unget() in its destructor. Do not construct multiple CoreServicePointer instances from the same raw pointer unless each was obtained from a separate CoreServices getter call.

For optional services (e.g. IDataStorageService), check validity first:

CoreServicePointer<IDataStorageService> dsService(CoreServices::GetDataStorageService());
if (dsService)
{
auto storage = dsService->GetActiveDataStorage();
}
static IDataStorageService * GetDataStorageService(us::ModuleContext *context=us::GetModuleContext())
Get an IDataStorageService instance.
Template Parameters
SThe service interface type.
See also
CoreServices

Definition at line 196 of file mitkCoreServices.h.

Constructor & Destructor Documentation

◆ CoreServicePointer() [1/2]

template<class S >
mitk::CoreServicePointer< S >::CoreServicePointer ( S *  service,
us::ModuleContext *  context = us::GetModuleContext() 
)
inlineexplicit

Construct a RAII wrapper around a service pointer.

Parameters
[in]serviceThe service pointer to manage (may be nullptr).
[in]contextThe module context used for Unget().

Definition at line 204 of file mitkCoreServices.h.

◆ ~CoreServicePointer()

template<class S >
mitk::CoreServicePointer< S >::~CoreServicePointer ( )
inline

Destructor. Releases the managed service via CoreServices::Unget().

Definition at line 213 of file mitkCoreServices.h.

References MITK_ERROR, and mitk::CoreServices::Unget().

◆ CoreServicePointer() [2/2]

template<class S >
mitk::CoreServicePointer< S >::CoreServicePointer ( const CoreServicePointer< S > &  )
delete

Member Function Documentation

◆ Get()

template<class S >
S* mitk::CoreServicePointer< S >::Get ( ) const
inline

Get the raw service pointer.

Returns
The service pointer (may be nullptr for optional services).

Definition at line 255 of file mitkCoreServices.h.

◆ operator bool()

template<class S >
mitk::CoreServicePointer< S >::operator bool ( ) const
inlineexplicit

Check if this pointer holds a valid (non-null) service.

Returns
True if the service pointer is not nullptr.

Definition at line 236 of file mitkCoreServices.h.

◆ operator->()

template<class S >
S* mitk::CoreServicePointer< S >::operator-> ( ) const
inline

Dereference the managed service pointer.

Returns
The raw service pointer.
Precondition
The service pointer must not be nullptr.

Definition at line 246 of file mitkCoreServices.h.

◆ operator=()

template<class S >
CoreServicePointer& mitk::CoreServicePointer< S >::operator= ( const CoreServicePointer< S > &  )
delete

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