Mantid
|
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... | |
ScopedWorkspace & | operator= (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... | |
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.
Mantid::API::ScopedWorkspace::ScopedWorkspace | ( | ) |
Empty constructor.
Definition at line 21 of file ScopedWorkspace.cpp.
Mantid::API::ScopedWorkspace::ScopedWorkspace | ( | const Workspace_sptr & | ws | ) |
|
virtual |
|
delete |
Disable copy operator.
|
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().
|
inline |
Returns ADS name of the workspace.
Definition at line 52 of file ScopedWorkspace.h.
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().
|
delete |
Disable assignment operator.
|
staticprivate |
Generates a random alpha-numeric string.
Generates random alpha-numeric string.
len | :: Length of the string |
Definition at line 107 of file ScopedWorkspace.cpp.
Referenced by generateUniqueName().
void Mantid::API::ScopedWorkspace::remove | ( | ) |
Removes the workspace entry from the ADS.
Definition at line 58 of file ScopedWorkspace.cpp.
References Mantid::API::AnalysisDataServiceImpl::deepRemoveGroup(), Mantid::Kernel::DataService< T >::doesExist(), Mantid::Kernel::SingletonHolder< T >::Instance(), m_name, Mantid::API::AnalysisDataServiceImpl::remove(), and Mantid::API::AnalysisDataServiceImpl::retrieveWS().
Referenced by set(), and ~ScopedWorkspace().
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().
void Mantid::API::ScopedWorkspace::set | ( | const Workspace_sptr & | newWS | ) |
Make ADS entry to point to the given workspace.
Definition at line 76 of file ScopedWorkspace.cpp.
References Mantid::API::AnalysisDataServiceImpl::add(), Mantid::Kernel::DataService< T >::doesExist(), Mantid::Kernel::SingletonHolder< T >::Instance(), m_name, and remove().
Referenced by ScopedWorkspace().
|
private |
ADS name of the workspace.
Definition at line 68 of file ScopedWorkspace.h.
Referenced by remove(), retrieve(), and set().
|
staticprivate |
Length of workspace names generated.
Definition at line 77 of file ScopedWorkspace.h.
Referenced by generateUniqueName().