Skip to content

Commit

Permalink
Refs #8506. ScopedWorkspace: set() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Nov 28, 2013
1 parent c914183 commit 019b34e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/ScopedWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ namespace API

/// Retrieve workspace from the ADS
Workspace_sptr retrieve() const;

/// Make ADS entry to point to the given workspace
void set(Workspace_sptr newWS);

private:
DISABLE_COPY_AND_ASSIGN(ScopedWorkspace);
Expand Down
8 changes: 8 additions & 0 deletions Code/Mantid/Framework/API/src/ScopedWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ namespace API

return Workspace_sptr();
}

/**
* Make ADS entry to point to the given workspace.
*/
void ScopedWorkspace::set(Workspace_sptr newWS)
{
AnalysisDataService::Instance().addOrReplace(m_name, newWS);
}

/**
* Generates a tricky name which is unique within ADS.
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/API/test/ScopedWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ class ScopedWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( test.name().size(), prefix.size() + 16 );
}

void test_retrieve()
void test_setAndRetrieve()
{
ScopedWorkspace test;

TS_ASSERT( ! test.retrieve() );

MockWorkspace_sptr ws = MockWorkspace_sptr(new MockWorkspace);
m_ads.add( test.name(), ws );
test.set(ws);

TS_ASSERT_EQUALS( ws, test.retrieve() );
}
Expand Down

0 comments on commit 019b34e

Please sign in to comment.