Skip to content

Commit

Permalink
Refs #5371 method getItem overloaded
Browse files Browse the repository at this point in the history
modified:   ../Framework/API/inc/MantidAPI/WorkspaceGroup.h
modified:   ../Framework/API/src/WorkspaceGroup.cpp
modified:   ../Framework/API/test/WorkspaceGroupTest.h
  • Loading branch information
jmborr committed May 22, 2012
1 parent 59800f6 commit 7ff0ca0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
size_t size() const { return m_wsNames.size(); }
/// Return the ith workspace
Workspace_sptr getItem(const size_t index) const;
/// Return the workspace by name
Workspace_sptr getItem(const std::string wsName) const;
/// Prints the group to the screen using the logger at debug
void print() const;
/// Remove a name from the group
Expand Down
11 changes: 11 additions & 0 deletions Code/Mantid/Framework/API/src/WorkspaceGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ Workspace_sptr WorkspaceGroup::getItem(const size_t index) const
return AnalysisDataService::Instance().retrieve(m_wsNames[index]);
}

/**
* Return the workspace by name
* @param wsName The name of the workspace
* @throws an out_of_range error if the workspace'sname not contained in the group's list of workspace names
*/
Workspace_sptr WorkspaceGroup::getItem(const std::string wsName) const
{
if ( !this->contains(wsName) )
throw std::out_of_range("Workspace "+wsName+" not contained in the group");
return AnalysisDataService::Instance().retrieve(wsName);
}

/// Empty all the entries out of the workspace group. Does not remove the workspaces from the ADS.
void WorkspaceGroup::removeAll()
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/test/WorkspaceGroupTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class WorkspaceGroupTest : public CxxTest::TestSuite
WorkspaceGroup_sptr group = makeGroup();
Workspace_sptr ws1 = group->getItem(1);
TS_ASSERT_EQUALS( ws1->name(), "ws1");
Workspace_sptr ws11 = group->getItem("ws1");
TS_ASSERT_EQUALS( ws1, ws11 );
}

void test_remove()
Expand Down

0 comments on commit 7ff0ca0

Please sign in to comment.