Mantid
Loading...
Searching...
No Matches
Public Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Mantid::API::ScopedWorkspace Class Reference

ScopedWorkspace : scoped workspace ADS entry. More...

#include <ScopedWorkspace.h>

Public Member Functions

std::string name () const
 Returns ADS name of the workspace. More...
 
 operator bool () const
 Operator for conversion to boolean. More...
 
ScopedWorkspaceoperator= (const ScopedWorkspace &)=delete
 Disable assignment operator. More...
 
void remove ()
 Removes the workspace entry from the ADS. More...
 
Workspace_sptr retrieve () const
 Retrieve workspace from the ADS. More...
 
 ScopedWorkspace ()
 Empty constructor. More...
 
 ScopedWorkspace (const ScopedWorkspace &)=delete
 Disable copy operator. More...
 
 ScopedWorkspace (const Workspace_sptr &ws)
 Workspace constructor. More...
 
void set (const Workspace_sptr &newWS)
 Make ADS entry to point to the given workspace. More...
 
virtual ~ScopedWorkspace ()
 Destructor. More...
 

Static Private Member Functions

static std::string generateUniqueName ()
 Generates a tricky name which is unique within ADS. More...
 
static std::string randomString (size_t len)
 Generates a random alpha-numeric string. More...
 

Private Attributes

const std::string m_name
 ADS name of the workspace. More...
 

Static Private Attributes

static const size_t NAME_LENGTH = 16
 Length of workspace names generated. More...
 

Detailed Description

ScopedWorkspace : scoped workspace ADS entry.

This class is provided for situations when you need a workspace to be in the ADS to run an algorithm, but you don't really need to keep it there after the algorithm has finished. In these circumstances you can create ScopedWorkspace, set it's name as a workspace property for the algorithm and retrieve it when algorithm has finished. The workspace will be removed from the ADS when the object goes out of scope, or exception is thrown.

Primarily, it was created to overcome some limitations of WorkspaceProperties, but it can be useful in other places, e.g. tests.

Definition at line 34 of file ScopedWorkspace.h.

Constructor & Destructor Documentation

◆ ScopedWorkspace() [1/3]

Mantid::API::ScopedWorkspace::ScopedWorkspace ( )

Empty constructor.

Definition at line 21 of file ScopedWorkspace.cpp.

◆ ScopedWorkspace() [2/3]

Mantid::API::ScopedWorkspace::ScopedWorkspace ( const Workspace_sptr ws)

Workspace constructor.

Definition at line 26 of file ScopedWorkspace.cpp.

References set().

◆ ~ScopedWorkspace()

Mantid::API::ScopedWorkspace::~ScopedWorkspace ( )
virtual

Destructor.

Definition at line 32 of file ScopedWorkspace.cpp.

References remove().

◆ ScopedWorkspace() [3/3]

Mantid::API::ScopedWorkspace::ScopedWorkspace ( const ScopedWorkspace )
delete

Disable copy operator.

Member Function Documentation

◆ generateUniqueName()

std::string Mantid::API::ScopedWorkspace::generateUniqueName ( )
staticprivate

Generates a tricky name which is unique within ADS.

Definition at line 91 of file ScopedWorkspace.cpp.

References Mantid::Kernel::SingletonHolder< T >::Instance(), NAME_LENGTH, and randomString().

◆ name()

std::string Mantid::API::ScopedWorkspace::name ( ) const
inline

Returns ADS name of the workspace.

Definition at line 52 of file ScopedWorkspace.h.

◆ operator bool()

Mantid::API::ScopedWorkspace::operator bool ( ) const

Operator for conversion to boolean.

Returns true if workspace was created for the name and it is not null workspace.

Definition at line 39 of file ScopedWorkspace.cpp.

References Mantid::Kernel::SingletonHolder< T >::Instance().

◆ operator=()

ScopedWorkspace & Mantid::API::ScopedWorkspace::operator= ( const ScopedWorkspace )
delete

Disable assignment operator.

◆ randomString()

std::string Mantid::API::ScopedWorkspace::randomString ( size_t  len)
staticprivate

Generates a random alpha-numeric string.

Generates random alpha-numeric string.

Parameters
len:: Length of the string
Returns
Random string of the given length

Definition at line 107 of file ScopedWorkspace.cpp.

Referenced by generateUniqueName().

◆ remove()

void Mantid::API::ScopedWorkspace::remove ( )

◆ retrieve()

Workspace_sptr Mantid::API::ScopedWorkspace::retrieve ( ) const

Retrieve workspace from the ADS.

Null pointer returned if nothing was added under the name.

Definition at line 45 of file ScopedWorkspace.cpp.

References Mantid::Kernel::DataService< T >::doesExist(), Mantid::Kernel::SingletonHolder< T >::Instance(), m_name, and Mantid::API::AnalysisDataServiceImpl::retrieveWS().

◆ set()

void Mantid::API::ScopedWorkspace::set ( const Workspace_sptr newWS)

Member Data Documentation

◆ m_name

const std::string Mantid::API::ScopedWorkspace::m_name
private

ADS name of the workspace.

Definition at line 68 of file ScopedWorkspace.h.

Referenced by remove(), retrieve(), and set().

◆ NAME_LENGTH

const size_t Mantid::API::ScopedWorkspace::NAME_LENGTH = 16
staticprivate

Length of workspace names generated.

Definition at line 77 of file ScopedWorkspace.h.

Referenced by generateUniqueName().


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