|
Mantid
|
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. | |
| ScopedWorkspace & | operator= (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. | |
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 24 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.
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.
|
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 42 of file ScopedWorkspace.cpp.
|
delete |
Disable assignment operator.
| void Mantid::API::ScopedWorkspace::remove | ( | ) |
Removes the workspace entry from the ADS.
Definition at line 61 of file ScopedWorkspace.cpp.
References Mantid::API::AnalysisDataServiceImpl::deepRemoveGroup(), Mantid::Kernel::DataService< T >::doesExist(), 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 48 of file ScopedWorkspace.cpp.
References Mantid::Kernel::DataService< T >::doesExist(), 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 79 of file ScopedWorkspace.cpp.
References Mantid::API::AnalysisDataServiceImpl::add(), Mantid::Kernel::DataService< T >::doesExist(), 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 74 of file ScopedWorkspace.h.
Referenced by generateUniqueName().