Skip to content

Commit

Permalink
Re #12687 clone() for SplittersWorkspace.
Browse files Browse the repository at this point in the history
Previously (before 12687) there was no implementation of clone().
That is, when calling clone() though a base class (e.g., ITableWorkspace)
we would use TableWorkspace::clone() on an object of type
SplittersWorkspace. Was that doing the right thing?
  • Loading branch information
SimonHeybrock committed Jun 30, 2015
1 parent 158a00b commit 48215c9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/ISplittersWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class DLLExport ISplittersWorkspace : virtual public API::ITableWorkspace {
*/
virtual ~ISplittersWorkspace();

/// Returns a clone of the workspace
std::unique_ptr<ISplittersWorkspace> clone() const {
return std::unique_ptr<ISplittersWorkspace>(doClone());
}

/*
* Add a time splitter to table workspace
*/
Expand All @@ -69,9 +74,13 @@ class DLLExport ISplittersWorkspace : virtual public API::ITableWorkspace {

protected:
/// Protected copy constructor. May be used by childs for cloning.
ISplittersWorkspace(const ISplittersWorkspace &other);
ISplittersWorkspace(const ISplittersWorkspace &other)
: ITableWorkspace(other) {}
/// Protected copy assignment operator. Assignment not implemented.
ISplittersWorkspace &operator=(const ISplittersWorkspace &other);

private:
virtual ISplittersWorkspace *doClone() const = 0;
};

/// Typedef for a shared pointer to \c TableWorkspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class DLLExport SplittersWorkspace : virtual public DataObjects::TableWorkspace,
SplittersWorkspace();
virtual ~SplittersWorkspace();

/// Returns a clone of the workspace
std::unique_ptr<SplittersWorkspace> clone() const {
return std::unique_ptr<SplittersWorkspace>(doClone());
}

void addSplitter(Kernel::SplittingInterval splitter);

Kernel::SplittingInterval getSplitter(size_t index);
Expand All @@ -60,9 +65,15 @@ class DLLExport SplittersWorkspace : virtual public DataObjects::TableWorkspace,

protected:
/// Protected copy constructor. May be used by childs for cloning.
SplittersWorkspace(const SplittersWorkspace &other);
SplittersWorkspace(const SplittersWorkspace &other)
: ITableWorkspace(other), TableWorkspace(other), ISplittersWorkspace(other) {}
/// Protected copy assignment operator. Assignment not implemented.
SplittersWorkspace &operator=(const SplittersWorkspace &other);

private:
virtual SplittersWorkspace *doClone() const {
return new SplittersWorkspace(*this);
}
};

typedef boost::shared_ptr<SplittersWorkspace> SplittersWorkspace_sptr;
Expand Down
20 changes: 20 additions & 0 deletions Code/Mantid/Framework/DataObjects/test/SplittersWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ class SplittersWorkspaceTest : public CxxTest::TestSuite
static void destroySuite( SplittersWorkspaceTest *suite ) { delete suite; }


void testClone()
{
SplittersWorkspace splitterws;

Kernel::SplittingInterval s1(Kernel::DateAndTime(10000), Kernel::DateAndTime(15000), 1);
Kernel::SplittingInterval s2(Kernel::DateAndTime(20000), Kernel::DateAndTime(30000), 3);
Kernel::SplittingInterval s3(Kernel::DateAndTime(40000), Kernel::DateAndTime(50000), 2);

splitterws.addSplitter(s1);
splitterws.addSplitter(s2);
splitterws.addSplitter(s3);

auto cloned = splitterws.clone();

// Check clone is same as original.
TS_ASSERT_EQUALS(splitterws.columnCount(), cloned->columnCount());
TS_ASSERT_EQUALS(splitterws.rowCount(), cloned->rowCount());
TS_ASSERT_EQUALS(splitterws.getNumberSplitters(), 3);
}

void test_Add()
{
DataObjects::SplittersWorkspace splitterws;
Expand Down

0 comments on commit 48215c9

Please sign in to comment.