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

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

Static Private Member Functions

static std::string generateUniqueName ()
 Generates a tricky name which is unique within ADS.
 

Private Attributes

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

Static Private Attributes

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

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 24 of file ScopedWorkspace.cpp.

◆ ScopedWorkspace() [2/3]

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

Workspace constructor.

Definition at line 29 of file ScopedWorkspace.cpp.

References set().

◆ ~ScopedWorkspace()

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

Destructor.

Definition at line 35 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.

Generates a unique workspace name.

The double underscore causes it to be hidden in ADS.

Definition at line 94 of file ScopedWorkspace.cpp.

References NAME_LENGTH.

◆ name()

const 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 42 of file ScopedWorkspace.cpp.

◆ operator=()

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

Disable assignment operator.

◆ 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 48 of file ScopedWorkspace.cpp.

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

◆ set()

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

Make ADS entry to point to the given workspace.

Definition at line 79 of file ScopedWorkspace.cpp.

References Mantid::API::AnalysisDataServiceImpl::add(), Mantid::Kernel::DataService< T >::doesExist(), m_name, and remove().

Referenced by ScopedWorkspace().

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 74 of file ScopedWorkspace.h.

Referenced by generateUniqueName().


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