Skip to content

Commit

Permalink
Refs #9445. Added clone method to PoldiPeakCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Jun 26, 2014
1 parent ec947a6 commit 0448cd9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Expand Up @@ -38,6 +38,10 @@ namespace Poldi {
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

class PoldiPeakCollection;

typedef boost::shared_ptr<PoldiPeakCollection> PoldiPeakCollection_sptr;

class MANTID_SINQ_DLL PoldiPeakCollection
{
public:
Expand All @@ -50,6 +54,8 @@ class MANTID_SINQ_DLL PoldiPeakCollection
PoldiPeakCollection(DataObjects::TableWorkspace_sptr workspace);
virtual ~PoldiPeakCollection() {}

PoldiPeakCollection_sptr clone();

size_t peakCount() const;

void addPeak(PoldiPeak_sptr newPeak);
Expand Down Expand Up @@ -86,8 +92,6 @@ class MANTID_SINQ_DLL PoldiPeakCollection
std::string m_profileFunctionName;
};

typedef boost::shared_ptr<PoldiPeakCollection> PoldiPeakCollection_sptr;

}
}

Expand Down
Expand Up @@ -29,6 +29,18 @@ PoldiPeakCollection::PoldiPeakCollection(TableWorkspace_sptr workspace) :
}
}

PoldiPeakCollection_sptr PoldiPeakCollection::clone()
{
PoldiPeakCollection_sptr clone(new PoldiPeakCollection(m_intensityType));
clone->setProfileFunctionName(m_profileFunctionName);

for(size_t i = 0; i < m_peaks.size(); ++i) {
clone->addPeak(m_peaks[i]->clone());
}

return clone;
}

size_t PoldiPeakCollection::peakCount() const
{
return m_peaks.size();
Expand Down
26 changes: 26 additions & 0 deletions Code/Mantid/Framework/SINQ/test/PoldiPeakCollectionTest.h
Expand Up @@ -208,6 +208,32 @@ class PoldiPeakCollectionTest : public CxxTest::TestSuite
TS_ASSERT(peaks.checkColumns(newTable));
}

void testClone()
{
PoldiPeakCollection_sptr peaks(new PoldiPeakCollection);
peaks->setProfileFunctionName("Test");
peaks->addPeak(PoldiPeak::create(2.0));
peaks->addPeak(PoldiPeak::create(3.0));

PoldiPeakCollection_sptr clone = peaks->clone();

// make sure those are different instances
TS_ASSERT(clone != peaks);

// everything else should be identical
TS_ASSERT_EQUALS(clone->getProfileFunctionName(), peaks->getProfileFunctionName());
TS_ASSERT_EQUALS(clone->intensityType(), peaks->intensityType());
TS_ASSERT_EQUALS(clone->peakCount(), peaks->peakCount());

for(size_t i = 0; i < clone->peakCount(); ++i) {
PoldiPeak_sptr clonePeak = clone->peak(i);
PoldiPeak_sptr peaksPeak = peaks->peak(i);

TS_ASSERT(clonePeak != peaksPeak);
TS_ASSERT_EQUALS(clonePeak->d(), peaksPeak->d());
}
}


private:
TableWorkspace_sptr m_dummyData;
Expand Down

0 comments on commit 0448cd9

Please sign in to comment.