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. More...
 
virtual void addOrReplace (const std::string &name, const std::shared_ptr< T > &Tobject)
 Add or replace an object to the service. More...
 
void clear ()
 Empty the service. More...
 
 DataService (const DataService &)=delete
 Deleted copy constructor. More...
 
bool doAllWsExist (const std::vector< std::string > &listOfNames)
 Checks all elements within the specified vector exist in the ADS. More...
 
bool doesExist (const std::string &name) const
 Check to see if a data object exists in the store. More...
 
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. More...
 
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. More...
 
DataServiceoperator= (const DataService &)=delete
 Deleted copy assignment operator. More...
 
void remove (const std::string &name)
 Remove an object from the service. More...
 
void rename (const std::string &oldName, const std::string &newName)
 Rename an object within the service. More...
 
std::shared_ptr< T > retrieve (const std::string &name) const
 Get a shared pointer to a stored data object. More...
 
virtual void shutdown ()
 Prepare for shutdown. More...
 
size_t size () const
 Return the number of objects stored by the data service. More...
 

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. More...
 

Protected Member Functions

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

Private Types

using svc_constit = typename svcmap::const_iterator
 Const iterator for the data store map. More...
 
using svc_it = typename svcmap::iterator
 Iterator for the data store map. More...
 
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. More...
 

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. More...
 
Logger g_log
 Logger for this DataService. More...
 
std::recursive_mutex m_mutex
 Recursive mutex to avoid simultaneous access or notifications. More...
 
const std::string svcName
 DataService name. More...
 

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 58 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 65 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 63 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 61 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 492 of file DataService.h.

References Mantid::API::g_log.

◆ ~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 190 of file DataService.h.

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

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 222 of file DataService.h.

References Mantid::Kernel::Logger::debug(), and Mantid::API::g_log.

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

◆ checkForEmptyName()

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

Definition at line 496 of file DataService.h.

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

◆ checkForNullPointer()

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

Definition at line 504 of file DataService.h.

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

◆ clear()

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

Empty the service.

Definition at line 334 of file DataService.h.

References Mantid::Kernel::Logger::debug(), and Mantid::API::g_log.

◆ 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 364 of file DataService.h.

◆ 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 398 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 451 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 471 of file DataService.h.

◆ 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 469 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 251 of file DataService.h.

References Mantid::Kernel::Logger::debug(), and Mantid::API::g_log.

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 281 of file DataService.h.

References Mantid::Kernel::Logger::debug(), error, Mantid::Kernel::Logger::error(), Mantid::API::g_log, 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 475 of file DataService.h.

◆ shutdown()

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

Prepare for shutdown.

Reimplemented in Mantid::API::AnalysisDataServiceImpl.

Definition at line 345 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 378 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 516 of file DataService.h.

◆ g_log

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

Logger for this DataService.

Definition at line 520 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 518 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 484 of file DataService.h.

Referenced by MantidQt::MantidWidgets::WorkspaceSelector::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 514 of file DataService.h.


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