Mantid
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Mantid::Kernel::DataService< T > Class Template Reference

DataService stores instances of a given type. More...

#include <DataService.h>

Classes

class  AddNotification
 AddNotification is sent after an new object is added to the data service. More...
 
class  AfterReplaceNotification
 AfterReplaceNotification is sent after an object is replaced in the addOrReplace() function. More...
 
class  BeforeReplaceNotification
 BeforeReplaceNotification is sent before an object is replaced in the addOrReplace() function. More...
 
class  ClearNotification
 Clear notification is sent when the service is cleared. More...
 
class  DataServiceNotification
 Base class for DataService notifications that also stores a pointer to the object. More...
 
class  NamedObjectNotification
 Class for named object notifications. More...
 
class  PostDeleteNotification
 PostDeleteNotification is sent after an object is deleted from the data service. More...
 
class  PreDeleteNotification
 PreDeleteNotification is sent before an object is deleted from the data service. More...
 
class  RenameNotification
 Rename notification is sent when the rename method is called. More...
 

Public Member Functions

virtual void add (const std::string &name, const std::shared_ptr< T > &Tobject)
 Add an object to the service.
 
virtual void addOrReplace (const std::string &name, const std::shared_ptr< T > &Tobject)
 Add or replace an object to the service.
 
void clear ()
 Empty the service.
 
 DataService (const DataService &)=delete
 Deleted copy constructor.
 
bool doAllWsExist (const std::vector< std::string > &listOfNames)
 Checks all elements within the specified vector exist in the ADS.
 
bool doesExist (const std::string &name) const
 Check to see if a data object exists in the store.
 
std::vector< std::string > getObjectNames (DataServiceSort sortState=DataServiceSort::Unsorted, DataServiceHidden hiddenState=DataServiceHidden::Auto, const std::string &contain="") const
 Returns a vector of strings containing all object names in the ADS.
 
std::vector< std::shared_ptr< T > > getObjects (DataServiceHidden includeHidden=DataServiceHidden::Auto) const
 Get a vector of the pointers to the data objects stored by the service.
 
DataServiceoperator= (const DataService &)=delete
 Deleted copy assignment operator.
 
void remove (const std::string &name)
 Remove an object from the service.
 
void rename (const std::string &oldName, const std::string &newName)
 Rename an object within the service.
 
std::shared_ptr< T > retrieve (const std::string &name) const
 Get a shared pointer to a stored data object.
 
virtual void shutdown ()
 Prepare for shutdown.
 
size_t size () const
 Return the number of objects stored by the data service.
 

Static Public Member Functions

static bool isHiddenDataServiceObject (const std::string &name)
 
static std::string prefixToHide ()
 
static bool showingHiddenObjects ()
 

Public Attributes

Poco::NotificationCenter notificationCenter
 Sends notifications to observers.
 

Protected Member Functions

 DataService (const std::string &name)
 Protected constructor (singleton)
 
virtual ~DataService ()=default
 

Private Types

using svc_constit = typename svcmap::const_iterator
 Const iterator for the data store map.
 
using svc_it = typename svcmap::iterator
 Iterator for the data store map.
 
using svcmap = std::map< std::string, std::shared_ptr< T >, CaseInsensitiveCmp >
 Typedef for the map holding the names of and pointers to the data objects.
 

Private Member Functions

void checkForEmptyName (const std::string &name)
 
void checkForNullPointer (const std::shared_ptr< T > &Tobject)
 

Private Attributes

svcmap datamap
 Map of objects in the data service.
 
Logger g_log
 Logger for this DataService.
 
std::recursive_mutex m_mutex
 Recursive mutex to avoid simultaneous access or notifications.
 
const std::string svcName
 DataService name.
 

Detailed Description

template<typename T>
class Mantid::Kernel::DataService< T >

DataService stores instances of a given type.

This is a templated class, designed to be implemented as a singleton. For simplicity and naming conventions, specialized classes must be constructed. The specialized classes must simply: 1) call the BaseClass constructor with the Name of the service 2) Support the SingletonHolder templated class. This is the primary data service that the users will interact with either through writing scripts or directly through the API. It is implemented as a singleton class.

Definition at line 57 of file DataService.h.

Member Typedef Documentation

◆ svc_constit

template<typename T >
using Mantid::Kernel::DataService< T >::svc_constit = typename svcmap::const_iterator
private

Const iterator for the data store map.

Definition at line 64 of file DataService.h.

◆ svc_it

template<typename T >
using Mantid::Kernel::DataService< T >::svc_it = typename svcmap::iterator
private

Iterator for the data store map.

Definition at line 62 of file DataService.h.

◆ svcmap

template<typename T >
using Mantid::Kernel::DataService< T >::svcmap = std::map<std::string, std::shared_ptr<T>, CaseInsensitiveCmp>
private

Typedef for the map holding the names of and pointers to the data objects.

Definition at line 60 of file DataService.h.

Constructor & Destructor Documentation

◆ DataService() [1/2]

template<typename T >
Mantid::Kernel::DataService< T >::DataService ( const DataService< T > &  )
delete

Deleted copy constructor.

◆ DataService() [2/2]

template<typename T >
Mantid::Kernel::DataService< T >::DataService ( const std::string &  name)
inlineprotected

Protected constructor (singleton)

Definition at line 489 of file DataService.h.

◆ ~DataService()

template<typename T >
virtual Mantid::Kernel::DataService< T >::~DataService ( )
protectedvirtualdefault

Member Function Documentation

◆ add()

template<typename T >
virtual void Mantid::Kernel::DataService< T >::add ( const std::string &  name,
const std::shared_ptr< T > &  Tobject 
)
inlinevirtual

Add an object to the service.

Parameters
name:: name of the object
Tobject:: shared pointer to object to add
Exceptions
std::runtime_errorif name is empty
std::runtime_errorif name exists in the map
std::runtime_errorif a null pointer is passed for the object

Reimplemented in Mantid::API::AnalysisDataServiceImpl.

Definition at line 189 of file DataService.h.

References Mantid::Kernel::Logger::debug(), error, Mantid::Kernel::Logger::error(), and name.

Referenced by Mantid::API::AnalysisDataServiceImpl::add().

◆ addOrReplace()

template<typename T >
virtual void Mantid::Kernel::DataService< T >::addOrReplace ( const std::string &  name,
const std::shared_ptr< T > &  Tobject 
)
inlinevirtual

Add or replace an object to the service.

Does NOT throw if the name was already used.

Parameters
name:: name of the object
Tobject:: shared pointer to object to add
Exceptions
std::runtime_errorif name is empty

Reimplemented in Mantid::API::AnalysisDataServiceImpl.

Definition at line 221 of file DataService.h.

References Mantid::Kernel::Logger::debug(), and name.

Referenced by Mantid::API::AnalysisDataServiceImpl::addOrReplace().

◆ checkForEmptyName()

template<typename T >
void Mantid::Kernel::DataService< T >::checkForEmptyName ( const std::string &  name)
inlineprivate

Definition at line 493 of file DataService.h.

References Mantid::Kernel::Logger::debug(), error, and name.

◆ checkForNullPointer()

template<typename T >
void Mantid::Kernel::DataService< T >::checkForNullPointer ( const std::shared_ptr< T > &  Tobject)
inlineprivate

Definition at line 501 of file DataService.h.

References Mantid::Kernel::Logger::debug(), and error.

◆ clear()

template<typename T >
void Mantid::Kernel::DataService< T >::clear ( )
inline

Empty the service.

Definition at line 333 of file DataService.h.

References Mantid::Kernel::Logger::debug(), and name.

◆ doAllWsExist()

template<typename T >
bool Mantid::Kernel::DataService< T >::doAllWsExist ( const std::vector< std::string > &  listOfNames)
inline

Checks all elements within the specified vector exist in the ADS.

Definition at line 363 of file DataService.h.

References name.

◆ doesExist()

template<typename T >
bool Mantid::Kernel::DataService< T >::doesExist ( const std::string &  name) const
inline

◆ getObjectNames()

template<typename T >
std::vector< std::string > Mantid::Kernel::DataService< T >::getObjectNames ( DataServiceSort  sortState = DataServiceSort::Unsorted,
DataServiceHidden  hiddenState = DataServiceHidden::Auto,
const std::string &  contain = "" 
) const
inline

Returns a vector of strings containing all object names in the ADS.

Parameters
sortStateWhether to sort the output before returning. Defaults to unsorted
hiddenStateWhether to include hidden objects, Defaults to Auto which checks the current configuration to determine behavior.
containInclude only object names that contain this string.
Returns
A vector of strings containing object names in the ADS

Definition at line 397 of file DataService.h.

Referenced by Mantid::Algorithms::UnGroupWorkspace::init().

◆ getObjects()

template<typename T >
std::vector< std::shared_ptr< T > > Mantid::Kernel::DataService< T >::getObjects ( DataServiceHidden  includeHidden = DataServiceHidden::Auto) const
inline

Get a vector of the pointers to the data objects stored by the service.

Definition at line 450 of file DataService.h.

Referenced by MantidQt::MantidWidgets::SelectWorkspacesDialog::SelectWorkspacesDialog().

◆ isHiddenDataServiceObject()

template<typename T >
static bool Mantid::Kernel::DataService< T >::isHiddenDataServiceObject ( const std::string &  name)
inlinestatic

Definition at line 470 of file DataService.h.

References name.

◆ operator=()

template<typename T >
DataService & Mantid::Kernel::DataService< T >::operator= ( const DataService< T > &  )
delete

Deleted copy assignment operator.

◆ prefixToHide()

template<typename T >
static std::string Mantid::Kernel::DataService< T >::prefixToHide ( )
inlinestatic

Definition at line 468 of file DataService.h.

◆ remove()

template<typename T >
void Mantid::Kernel::DataService< T >::remove ( const std::string &  name)
inline

Remove an object from the service.

Parameters
name:: name of the object

Definition at line 250 of file DataService.h.

References Mantid::Kernel::Logger::debug(), and name.

Referenced by Mantid::API::AnalysisDataServiceImpl::remove().

◆ rename()

template<typename T >
void Mantid::Kernel::DataService< T >::rename ( const std::string &  oldName,
const std::string &  newName 
)
inline

Rename an object within the service.

Parameters
oldName:: The old name of the object
newName:: The new name of the object

Definition at line 280 of file DataService.h.

References Mantid::Kernel::Logger::debug(), error, Mantid::Kernel::Logger::error(), and Mantid::Kernel::Logger::warning().

Referenced by Mantid::API::AnalysisDataServiceImpl::rename().

◆ retrieve()

template<typename T >
std::shared_ptr< T > Mantid::Kernel::DataService< T >::retrieve ( const std::string &  name) const
inline

◆ showingHiddenObjects()

template<typename T >
static bool Mantid::Kernel::DataService< T >::showingHiddenObjects ( )
inlinestatic

Definition at line 472 of file DataService.h.

◆ shutdown()

template<typename T >
virtual void Mantid::Kernel::DataService< T >::shutdown ( )
inlinevirtual

Prepare for shutdown.

Definition at line 344 of file DataService.h.

◆ size()

template<typename T >
size_t Mantid::Kernel::DataService< T >::size ( ) const
inline

Return the number of objects stored by the data service.

Definition at line 377 of file DataService.h.

Member Data Documentation

◆ datamap

template<typename T >
svcmap Mantid::Kernel::DataService< T >::datamap
private

Map of objects in the data service.

Definition at line 513 of file DataService.h.

◆ g_log

template<typename T >
Logger Mantid::Kernel::DataService< T >::g_log
private

Logger for this DataService.

Definition at line 517 of file DataService.h.

◆ m_mutex

template<typename T >
std::recursive_mutex Mantid::Kernel::DataService< T >::m_mutex
mutableprivate

Recursive mutex to avoid simultaneous access or notifications.

Definition at line 515 of file DataService.h.

◆ notificationCenter

template<typename T >
Poco::NotificationCenter Mantid::Kernel::DataService< T >::notificationCenter

Sends notifications to observers.

Observers can subscribe to notificationCenter using Poco::NotificationCenter::addObserver(...)

Returns
nothing

Definition at line 481 of file DataService.h.

Referenced by MantidQt::MantidWidgets::WorkspaceSelector::connectObservers(), MantidQt::MantidWidgets::WorkspaceMultiSelector::connectObservers(), and Mantid::Algorithms::UnGroupWorkspace::exec().

◆ svcName

template<typename T >
const std::string Mantid::Kernel::DataService< T >::svcName
private

DataService name.

This is set only at construction. DataService name should be provided when construction of derived classes

Definition at line 511 of file DataService.h.


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